import { jsx as n } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { memo as N } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/compat/dist/compat.module.js";
import { useMemo as u, useCallback as P } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { getTransactionRefundReason as K } from "../../../../utils/translation/getters.js";
import { isCustomDataObject as y } from "../../../../internal/DataGrid/components/TableCells.js";
import { TypographyVariant as k, TypographyElement as A } from "../../../../internal/Typography/types.js";
import { TX_DETAILS_FIELDS_REMAPS as V, TX_DATA_LABEL as g, TX_DATA_LIST as O, sharedTransactionDetailsEventProperties as j } from "../../constants.js";
import F from "../../../../utils/customData/normalizeCustomFields.js";
import I from "../../../../internal/Typography/Typography.js";
import X from "../../../../internal/DataGrid/components/Icon.js";
import w from "../../../../internal/CopyText/CopyText.js";
import Y from "../../../../internal/Link/Link.js";
import R from "classnames";
import q from "../../../../../core/Context/preact/useCoreContext.js";
import z from "../../../../internal/StructuredList/StructuredList.js";
import $ from "../../../../../core/Context/analytics/preact/useAnalyticsContext.js";
const G = {
  ...j,
  sectionName: "Details",
  label: "Copy button"
}, o = {
  account: "transactions.details.fields.account",
  id: "transactions.details.fields.referenceID",
  merchantReference: "transactions.details.fields.merchantReference",
  pspReference: "transactions.details.fields.pspReference",
  refundPspReference: "transactions.details.fields.refundPspReference",
  refundReason: "transactions.details.fields.refundReason"
}, T = {
  id: "transactions.details.actions.copyReferenceID",
  merchantReference: "transactions.details.actions.copyMerchantReference",
  pspReference: "transactions.details.actions.copyPspReference"
}, i = null, c = ({ dataCustomization: s, extraFields: p, transaction: a }) => {
  const { i18n: d } = q(), h = u(() => {
    const { balanceAccount: e, category: r, id: m, merchantReference: t, paymentPspReference: D, refundMetadata: l } = a, b = e?.description || e?.id, L = r === "Refund", x = F(s?.details?.fields, V, a), S = [
      // balance account
      b ? { id: "account", key: o.account, value: b } : i,
      // refund reason
      L && l?.refundReason ? {
        id: "refundReason",
        key: o.refundReason,
        value: K(d, l.refundReason)
      } : i,
      // reference id
      {
        id: "id",
        key: o.id,
        value: /* @__PURE__ */ n(
          c.CopyText,
          {
            copyButtonAriaLabelKey: T.id,
            trackingName: "Reference ID",
            textToCopy: m
          }
        )
      },
      // merchant reference
      t ? {
        id: "merchantReference",
        key: o.merchantReference,
        value: /* @__PURE__ */ n(
          c.CopyText,
          {
            copyButtonAriaLabelKey: T.merchantReference,
            trackingName: "Merchant reference",
            textToCopy: t
          }
        )
      } : i,
      // payment psp reference
      D ? {
        id: "paymentPspReference",
        key: o.pspReference,
        value: /* @__PURE__ */ n(
          c.CopyText,
          {
            copyButtonAriaLabelKey: T.pspReference,
            trackingName: "PSP reference",
            textToCopy: D
          }
        )
      } : i,
      // refund psp reference
      L && l?.refundPspReference ? {
        id: "refundPspReference",
        key: o.refundPspReference,
        value: l.refundPspReference
      } : i
    ], B = x ? (f) => x.find((M) => M.key === f)?.visibility !== "hidden" : () => !0;
    return S.filter((f) => f?.id && B(f.id));
  }, [d, s, a]), C = u(
    () => Object.entries(p || {}).filter(([, e]) => e?.type !== "button").map(([e, r]) => ({
      key: e,
      value: y(r) ? r.value : r,
      type: y(r) ? r.type : "text",
      config: y(r) ? r.config : void 0
    })),
    [p]
  ), _ = u(() => [...h, ...C], [C, h]), v = P(
    (e) => /* @__PURE__ */ n("div", { className: g, children: e }),
    []
  ), E = P((e, r, m, t) => {
    if (t)
      switch (m) {
        case "icon":
          return /* @__PURE__ */ n("div", { className: R(t.className, "adyen-pe-transaction-data__list-icon-value"), children: [
            /* @__PURE__ */ n(X, { url: t.src, alt: t.alt || e }),
            /* @__PURE__ */ n(I, { el: A.SPAN, variant: k.BODY, children: [
              " ",
              e
            ] })
          ] });
        case "link":
          return /* @__PURE__ */ n(Y, { classNames: [R(t.className)], href: t.href, target: t.target || "_blank", children: e });
      }
    return /* @__PURE__ */ n(I, { el: A.DIV, variant: k.BODY, className: R(t?.className), children: e });
  }, []);
  return /* @__PURE__ */ n(
    z,
    {
      align: "start",
      layout: "5-7",
      items: _,
      classNames: O,
      renderLabel: v,
      renderValue: E
    }
  );
};
c.CopyText = N(({ trackingName: s, ...p }) => {
  const a = $(), d = P(() => {
    s && a.addEvent?.("Clicked button", {
      ...G,
      subSectionName: s
    });
  }, [s, a]);
  return /* @__PURE__ */ n(w, { ...p, onCopyText: d, showCopyTextTooltip: !1, type: "Default" });
});
const de = N(c);
export {
  de as default
};
