import { jsx as e } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import O from "classnames";
import { getCurrencyCode as w } from "../../../../../core/Localization/amount/amount-util.js";
import { useMemo as l, useCallback as F } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import L from "../../../../../hooks/useTimezoneAwareDateFormatting.js";
import P from "../../../../internal/DataOverviewError/DataOverviewError.js";
import { TypographyVariant as a, TypographyElement as m } from "../../../../internal/Typography/types.js";
import u from "../../../../internal/Typography/Typography.js";
import { useResponsiveContainer as Y, containerQueries as M } from "../../../../../hooks/useResponsiveContainer.js";
import { BASE_CLASS as B, NET_PAYOUT_CLASS as N } from "./constants.js";
/* empty css                  */
import { useTableColumns as U } from "../../../../../hooks/useTableColumns.js";
import j from "../../../../../core/Context/preact/useCoreContext.js";
import y from "../../../../internal/DataGrid/DataGrid.js";
import x from "../../../../internal/Pagination/Pagination.js";
import { DATE_FORMAT_PAYOUTS_MOBILE as K, DATE_FORMAT_PAYOUTS as I } from "../../../../../constants/dateFormats.js";
import { useConfigContext as R } from "../../../../../core/ConfigContext/preact/context.js";
const T = ["fundsCapturedAmount", "adjustmentAmount", "payoutAmount"], $ = ["createdAt", ...T], C = {
  adjustmentAmount: "payouts.overview.list.fields.adjustmentAmount",
  createdAt: "payouts.overview.list.fields.createdAt",
  fundsCapturedAmount: "payouts.overview.list.fields.fundsCapturedAmount",
  payoutAmount: "payouts.overview.list.fields.payoutAmount"
}, G = (o) => T.includes(o), mt = ({
  error: o,
  loading: c,
  onContactSupport: p,
  onRowClick: g,
  showDetails: q,
  showPagination: v,
  data: i,
  customColumns: S,
  ...h
}) => {
  const { i18n: n } = j(), { dateFormat: d } = L("UTC"), { refreshing: A } = R(), E = l(() => c || A, [c, A]), r = Y(M.up.sm), s = F(
    (t) => {
      const f = n.get(C[t]);
      if (G(t))
        return {
          label: i?.[0]?.[t]?.currency ? `${f} (${w(i?.[0]?.[t]?.currency)})` : f,
          position: "right"
        };
    },
    [i, n]
  ), _ = U({
    customColumns: S,
    fields: $,
    fieldsKeys: C,
    columnConfig: l(
      () => ({
        fundsCapturedAmount: { ...s("fundsCapturedAmount"), visible: r },
        adjustmentAmount: { ...s("adjustmentAmount"), visible: r },
        payoutAmount: s("payoutAmount")
      }),
      [s, r]
    )
  }), b = {
    title: "payouts.overview.errors.listEmpty",
    message: ["common.errors.updateFilters"]
  }, D = l(
    () => () => /* @__PURE__ */ e(P, { error: o, errorMessage: "payouts.overview.errors.listUnavailable", onContactSupport: p }),
    [o, p]
  );
  return /* @__PURE__ */ e("div", { className: B, children: /* @__PURE__ */ e(
    y,
    {
      errorDisplay: D,
      error: o,
      columns: _,
      data: i,
      loading: E,
      outline: !1,
      onRowClick: { callback: g },
      emptyTableMessage: b,
      customCells: {
        createdAt: ({ value: t }) => t ? r ? t && /* @__PURE__ */ e("time", { dateTime: t, children: /* @__PURE__ */ e(u, { el: m.SPAN, variant: a.BODY, children: d(t, I) }) }) : /* @__PURE__ */ e("time", { dateTime: t, children: d(t, K) }) : null,
        fundsCapturedAmount: ({ value: t }) => t && /* @__PURE__ */ e(u, { el: m.SPAN, variant: a.BODY, children: n.amount(t.value, t.currency, { hideCurrency: !0 }) }),
        adjustmentAmount: ({ value: t }) => t && /* @__PURE__ */ e(u, { el: m.SPAN, variant: a.BODY, children: n.amount(t.value, t.currency, { hideCurrency: !0 }) }),
        payoutAmount: ({ value: t }) => t && /* @__PURE__ */ e(
          u,
          {
            el: m.SPAN,
            variant: a.BODY,
            className: O({ [`${N}--strong`]: !r }),
            children: n.amount(t.value, t.currency, { hideCurrency: r })
          }
        )
      },
      children: v && /* @__PURE__ */ e(y.Footer, { children: /* @__PURE__ */ e(
        x,
        {
          ...h,
          ariaLabelKey: "payouts.overview.pagination.label",
          limitSelectAriaLabelKey: "payouts.overview.pagination.controls.limitSelect.label"
        }
      ) })
    }
  ) });
};
export {
  $ as PAYOUT_TABLE_FIELDS,
  mt as PayoutsTable
};
