import { jsx as o } from "../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
/* empty css                         */
import { useMemo as l, useState as C, useCallback as g, useEffect as w } from "../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { useModalContext as S } from "../Modal/Modal.js";
import { useFetch as _ } from "../../../hooks/useFetch.js";
import { PayoutData as F } from "../../external/PayoutDetails/components/PayoutData.js";
import P from "../../../hooks/useBalanceAccounts.js";
import { getErrorMessage as k } from "../../utils/getErrorMessage.js";
import { ErrorMessageDisplay as x } from "../ErrorMessageDisplay/ErrorMessageDisplay.js";
import I from "./useDataOverviewDetailsTitle.js";
import { TX_DETAILS_RESERVED_FIELDS_SET as M } from "../../external/TransactionDetails/constants.js";
import { PAYOUT_TABLE_FIELDS as O } from "../../external/PayoutsOverview/components/PayoutsTable/PayoutsTable.js";
import { Header as p } from "../Header/Header.js";
import { useConfigContext as B } from "../../../core/ConfigContext/preact/context.js";
import { EMPTY_OBJECT as q } from "../../../utils/value/constants.js";
const z = {
  payout: "getPayout"
};
function $(t) {
  const r = B().endpoints[z[t.type]], { hideTitle: y, titleKey: f } = I(t), { withinModal: D } = S(), { data: i, error: n, isFetching: E } = _(
    l(
      () => ({
        fetchOptions: { enabled: !!t.id && !!r },
        queryFn: async () => {
          switch (t.type) {
            case "payout": {
              const e = { query: { balanceAccountId: t.id, createdAt: t.date } };
              return r(q, { ...e });
            }
          }
        }
      }),
      [r, t]
    )
  ), s = t.id, v = t?.balanceAccountDescription, { balanceAccounts: h } = P(s, !v), c = l(() => {
    if (n) {
      let e;
      switch (t.type) {
        case "payout":
          e = "payouts.details.errors.unavailable";
          break;
      }
      return k(n, e, t.onContactSupport);
    }
  }, [n, t.onContactSupport, t.type]), u = i, [T, A] = C(), d = g(async () => {
    if (i) {
      const e = await t.dataCustomization?.details?.onDataRetrieve?.(i);
      A(
        t.dataCustomization?.details?.fields?.reduce((m, a) => M.has(a.key) || O.includes(a.key) || a?.visibility === "hidden" ? m : { ...m, ...e?.[a.key] ? { [a.key]: e[a.key] } : {} }, {})
      );
    }
  }, [i, t]), b = t.dataCustomization;
  return w(() => {
    d();
  }, [d]), /* @__PURE__ */ o("div", { className: "adyen-pe-overview-details", children: [
    /* @__PURE__ */ o(p, { hideTitle: y, titleKey: f, forwardedToRoot: !D }),
    n && c && /* @__PURE__ */ o("div", { className: "adyen-pe-overview-details--error-container", children: /* @__PURE__ */ o(x, { withImage: !0, ...c }) }),
    t.type === "payout" && u && /* @__PURE__ */ o(
      F,
      {
        balanceAccountId: s,
        payout: u,
        balanceAccountDescription: t?.balanceAccountDescription || h?.[0]?.description,
        isFetching: E,
        extraFields: T,
        dataCustomization: b
      }
    )
  ] });
}
export {
  $ as default
};
