import { jsx as e } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import m from "classnames";
import { useMemo as A } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import D from "../../../internal/Accordion/Accordion.js";
import N from "../../../internal/Card/Card.js";
import { TypographyVariant as i, TypographyElement as b } from "../../../internal/Typography/types.js";
import s from "../../../internal/Typography/Typography.js";
import I from "../../../internal/DataOverviewDetails/DataOverviewDetailsSkeleton.js";
import j from "../../../../hooks/useTimezoneAwareDateFormatting.js";
/* empty css                */
import { PD_BASE_CLASS as Y, PD_TITLE_CONTAINER_CLASS as R, PD_SECTION_CLASS as p, PD_TITLE_BA_CLASS as w, PD_TITLE_CLASS as U, PD_TITLE_CLASS_WITH_EXTRA_DETAILS as M, PD_EXTRA_DETAILS_CLASS as x, PD_EXTRA_DETAILS_ICON as F, PD_EXTRA_DETAILS_LABEL as X, PD_CONTENT_CLASS as $, PD_CARD_CLASS as _, PD_SECTION_AMOUNT_CLASS as C, PD_SECTION_GROSS_AMOUNT_CLASS as L, PD_CARD_TITLE_CLASS as P, PD_SECTION_NET_AMOUNT_CLASS as H, PD_UNPAID_AMOUNT as z, PD_BUTTON_ACTIONS as G } from "./constants.js";
import { Tag as J } from "../../../internal/Tag/Tag.js";
import { TagVariant as V } from "../../../internal/Tag/types.js";
import W from "../../../internal/Link/Link.js";
import q from "../../../internal/DataGrid/components/Icon.js";
import { isCustomDataObject as O } from "../../../internal/DataGrid/components/TableCells.js";
import { ButtonVariant as K } from "../../../internal/Button/types.js";
import { ButtonActionsLayoutBasic as Q } from "../../../internal/Button/ButtonActions/types.js";
import Z from "../../../internal/Button/ButtonActions/ButtonActions.js";
import { getPayoutFundsCapturedType as ee, getPayoutAdjustmentType as te } from "../../../utils/translation/getters.js";
import re from "../../../../core/Context/preact/useCoreContext.js";
import { DATE_FORMAT_PAYOUT_DETAILS as ae } from "../../../../constants/dateFormats.js";
import T from "../../../internal/StructuredList/StructuredList.js";
import { Fragment as ne } from "../../../../external/.pnpm/preact@10.28.2/node_modules/preact/dist/preact.module.js";
import { EMPTY_OBJECT as ie } from "../../../../utils/value/constants.js";
const Ee = ({
  balanceAccountId: B,
  balanceAccountDescription: f,
  payout: c,
  extraFields: y
}) => {
  const { payout: o } = c ?? ie, { dateFormat: k } = j("UTC"), { i18n: a } = re(), u = A(() => {
    const n = c?.amountBreakdowns?.adjustmentBreakdown?.reduce(
      (r, t) => {
        if (t.category && t.amount?.value) {
          const { currency: d, value: l } = t.amount;
          r[l && l < 0 ? "subtractions" : "additions"].push({
            key: t.category,
            value: a.amount(l, d, { hideCurrency: !0 })
          });
        }
        return r;
      },
      { subtractions: [], additions: [] }
    );
    return n?.subtractions.sort((r, t) => r.key.localeCompare(t.key)), n?.additions.sort((r, t) => r.key.localeCompare(t.key)), n;
  }, [a, c]), v = A(() => {
    const n = c?.amountBreakdowns?.fundsCapturedBreakdown?.reduce(
      (r, t) => (t?.amount?.value === 0 || t?.amount?.value && t.category && r.push({
        key: t.category,
        value: a.amount(t?.amount?.value, t?.amount?.currency, { hideCurrency: !0 })
      }), r),
      []
    );
    return n?.sort((r, t) => {
      const d = "capture";
      return r.key === d ? -1 : t.key === d ? 1 : r.key.localeCompare(t.key);
    }), n;
  }, [c, a]), { payoutAdjustmentTypeLabelRenderer: S, payoutFundsCapturedTypeLabelRenderer: E } = A(() => {
    const n = (r) => (t, d) => /* @__PURE__ */ e(s, { el: b.SPAN, variant: i.BODY, children: r(a, d) });
    return {
      payoutAdjustmentTypeLabelRenderer: n(te),
      payoutFundsCapturedTypeLabelRenderer: n(ee)
    };
  }, [a]), h = Object.entries(y || {}).filter(([, n]) => n.type !== "button" && n.visibility !== "hidden").map(([n, r]) => ({
    key: n,
    value: O(r) ? r.value : r,
    type: O(r) ? r.type : "text",
    config: O(r) ? r.config : void 0
  })) || [], g = A(() => [...y ? Object.values(y).filter((t) => t.type === "button").map((t) => ({
    title: t.value,
    variant: K.SECONDARY,
    event: t.config?.action,
    classNames: t?.config?.className ? [t?.config?.className] : []
  })) : []].filter(Boolean), [y]);
  return /* @__PURE__ */ e(ne, { children: o ? /* @__PURE__ */ e("div", { className: Y, children: [
    /* @__PURE__ */ e(
      "div",
      {
        className: m(U, {
          [M]: h.length
        }),
        children: [
          /* @__PURE__ */ e("div", { className: R, children: [
            /* @__PURE__ */ e(s, { variant: i.SUBTITLE, stronger: !0, children: a.get("payouts.details.tags.netPayout") }),
            o.isSumOfSameDayPayouts && /* @__PURE__ */ e(J, { variant: V.BLUE, label: a.get("payouts.details.tags.sameDaySum") })
          ] }),
          /* @__PURE__ */ e(s, { variant: i.TITLE, large: !0, children: `${a.amount(o.payoutAmount.value, o.payoutAmount.currency, {
            hideCurrency: !0
          })} ${o.payoutAmount.currency}` }),
          o?.createdAt && /* @__PURE__ */ e("time", { dateTime: o.createdAt, children: /* @__PURE__ */ e(s, { el: b.SPAN, variant: i.BODY, children: k(o.createdAt, ae) }) }),
          /* @__PURE__ */ e("div", { className: p, children: [
            f && /* @__PURE__ */ e(s, { variant: i.CAPTION, stronger: !0, wide: !0, children: `${f}` }),
            /* @__PURE__ */ e(s, { variant: i.CAPTION, className: w, children: `${B}` })
          ] })
        ]
      }
    ),
    h && h.length > 0 ? /* @__PURE__ */ e("div", { children: /* @__PURE__ */ e(
      T,
      {
        classNames: x,
        items: h,
        align: "start",
        layout: "4-8",
        renderLabel: (n) => /* @__PURE__ */ e("div", { className: X, children: n }),
        renderValue: (n, r, t, d) => {
          if (t === "link" && d)
            return /* @__PURE__ */ e(W, { classNames: [m(d?.className)], href: d.href, target: d.target || "_blank", children: n });
          if (t === "icon" && d) {
            const l = { url: d.src, alt: d.alt || n };
            return /* @__PURE__ */ e("div", { className: m(F, d?.className), children: [
              /* @__PURE__ */ e(q, { ...l }),
              /* @__PURE__ */ e(s, { variant: i.BODY, children: n })
            ] });
          }
          return /* @__PURE__ */ e(s, { className: m(d?.className), variant: i.BODY, children: n });
        }
      }
    ) }) : null,
    /* @__PURE__ */ e("div", { className: $, children: [
      /* @__PURE__ */ e("div", { className: p, children: o?.fundsCapturedAmount && (v && Object.keys(v).length > 0 ? /* @__PURE__ */ e(
        D,
        {
          header: /* @__PURE__ */ e(s, { variant: i.BODY, children: a.get("payouts.details.breakdown.fields.fundsCaptured") }),
          headerInformation: /* @__PURE__ */ e(s, { variant: i.BODY, children: a.amount(o.fundsCapturedAmount.value, o.fundsCapturedAmount.currency) }),
          children: /* @__PURE__ */ e("div", { className: p, children: /* @__PURE__ */ e("div", { className: _, children: /* @__PURE__ */ e(N, { noPadding: !0, children: /* @__PURE__ */ e("div", { "data-testid": "payout-funds-captured-breakdown", children: /* @__PURE__ */ e(
            T,
            {
              items: v,
              renderLabel: E
            }
          ) }) }) }) })
        }
      ) : /* @__PURE__ */ e("div", { className: m(C, L), children: [
        /* @__PURE__ */ e(s, { variant: i.BODY, children: a.get("payouts.details.breakdown.fields.fundsCaptured") }),
        /* @__PURE__ */ e(s, { variant: i.BODY, children: a.amount(o.fundsCapturedAmount.value, o.fundsCapturedAmount.currency) })
      ] })) }),
      /* @__PURE__ */ e("div", { className: p, children: u?.subtractions && Object.keys(u?.subtractions).length > 0 || u?.additions && Object.keys(u?.additions).length > 0 ? /* @__PURE__ */ e(
        D,
        {
          header: /* @__PURE__ */ e(s, { variant: i.BODY, children: a.get("payouts.details.breakdown.fields.adjustments") }),
          headerInformation: /* @__PURE__ */ e(s, { variant: i.BODY, children: a.amount(o.adjustmentAmount.value, o.adjustmentAmount.currency) }),
          children: [
            u?.additions && Object.keys(u?.additions).length > 0 && /* @__PURE__ */ e("div", { className: _, children: /* @__PURE__ */ e(
              N,
              {
                noPadding: !0,
                renderHeader: /* @__PURE__ */ e(s, { className: P, variant: i.CAPTION, stronger: !0, children: a.get("payouts.details.breakdown.fields.additions") }),
                children: /* @__PURE__ */ e("div", { "data-testid": "payout-adjustments-additions-breakdown", children: /* @__PURE__ */ e(T, { items: u?.additions, renderLabel: S }) })
              }
            ) }),
            u?.subtractions && Object.keys(u?.subtractions).length > 0 && /* @__PURE__ */ e("div", { className: _, children: /* @__PURE__ */ e(
              N,
              {
                noPadding: !0,
                renderHeader: /* @__PURE__ */ e(s, { className: P, variant: i.CAPTION, stronger: !0, children: a.get("payouts.details.breakdown.fields.subtractions") }),
                children: /* @__PURE__ */ e("div", { "data-testid": "payout-adjustments-subtractions-breakdown", children: /* @__PURE__ */ e(
                  T,
                  {
                    items: u?.subtractions,
                    renderLabel: S
                  }
                ) })
              }
            ) })
          ]
        }
      ) : /* @__PURE__ */ e("div", { className: m(C, L), children: [
        /* @__PURE__ */ e(s, { variant: i.BODY, children: a.get("payouts.details.breakdown.fields.adjustments") }),
        /* @__PURE__ */ e(s, { variant: i.BODY, children: a.amount(o.adjustmentAmount.value, o.adjustmentAmount.currency) })
      ] }) }),
      /* @__PURE__ */ e("div", { className: m(p), children: /* @__PURE__ */ e("div", { className: m(C, H), children: [
        /* @__PURE__ */ e(s, { variant: i.BODY, stronger: !0, children: a.get("payouts.details.breakdown.fields.netPayout") }),
        /* @__PURE__ */ e(s, { variant: i.BODY, stronger: !0, children: a.amount(o.payoutAmount.value, o.payoutAmount.currency) })
      ] }) })
    ] }),
    c?.payout?.unpaidAmount && /* @__PURE__ */ e("div", { className: z, children: [
      /* @__PURE__ */ e(s, { variant: i.BODY, children: a.get("payouts.details.breakdown.fields.remainingAmount") }),
      /* @__PURE__ */ e(s, { variant: i.BODY, children: a.amount(c.payout.unpaidAmount.value, c.payout.unpaidAmount.currency) })
    ] }),
    g.length ? /* @__PURE__ */ e("div", { className: G, children: /* @__PURE__ */ e(Z, { actions: g, layout: Q.BUTTONS_END }) }) : null
  ] }) : /* @__PURE__ */ e(I, { skeletonRowNumber: 6 }) });
};
export {
  Ee as PayoutData
};
