import { jsx as r } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { TX_DETAILS_RESERVED_FIELDS_SET as _, TX_DETAILS_FIELDS_REMAPS as F } from "../../constants.js";
import I from "../../../../internal/DataOverviewDetails/DataOverviewDetailsSkeleton.js";
import M from "../../../../utils/customData/normalizeCustomFields.js";
import { TransactionDataContent as R } from "./TransactionDataContent.js";
import { useModalContext as b } from "../../../../internal/Modal/Modal.js";
import { useState as l, useMemo as y, useEffect as c } from "../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { ErrorMessageDisplay as x } from "../../../../internal/ErrorMessageDisplay/ErrorMessageDisplay.js";
import { getErrorMessage as H } from "../../../../utils/getErrorMessage.js";
import L from "../../hooks/useTransaction/useTransaction.js";
import { boolOrFalse as N } from "../../../../../utils/value/bool.js";
import { Header as A } from "../../../../internal/Header/Header.js";
const W = ({ id: t, dataCustomization: a, hideTitle: m, onContactSupport: d }) => {
  const { error: i, fetchingTransaction: f, refreshTransaction: h, transaction: e, transactionNavigator: w } = L(t), { withinModal: n } = b(), [S, T] = l(), [p, g] = l(!1), [u, v] = l(), k = y(() => p || N(m), [p, m]), E = y(
    () => H(i, "transactions.details.errors.unavailable", d),
    [i, d]
  );
  return c(() => {
    e && e.id === t ? v((o) => o ?? e) : e || v(void 0);
  }, [e, t]), c(() => {
    g(n);
  }, [n]), c(() => {
    e && e.id === t ? (async () => {
      const o = await a?.details?.onDataRetrieve?.(e);
      T(
        M(
          a?.details?.fields,
          F,
          o
        )?.reduce((D, s) => !_.has(s.key) && s?.visibility !== "hidden" ? {
          ...D,
          ...o?.[s.key] && { [s.key]: o[s.key] }
        } : D, {})
      );
    })() : T(void 0);
  }, [e, t, a]), /* @__PURE__ */ r("div", { className: "adyen-pe-overview-details", children: [
    /* @__PURE__ */ r(A, { hideTitle: k, titleKey: "transactions.details.title", forwardedToRoot: !n }),
    u ? /* @__PURE__ */ r(
      R,
      {
        extraFields: S,
        dataCustomization: a,
        fetchingTransaction: f,
        refreshTransaction: h,
        transaction: e ?? u,
        transactionNavigator: w
      }
    ) : f ? /* @__PURE__ */ r(I, { skeletonRowNumber: 5 }) : i && E && /* @__PURE__ */ r("div", { className: "adyen-pe-overview-details--error-container", children: /* @__PURE__ */ r(x, { outlined: !1, absolutePosition: !1, withBackground: !1, withImage: !0, ...E }) })
  ] });
};
export {
  W as TransactionData
};
