import { jsx as e } from "../../../../../preact@10.29.0/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { useState as y, useMemo as H } from "../../../../../preact@10.29.0/node_modules/preact/hooks/dist/hooks.module.js";
import { J as M, k as R, u as x, X as N, aT as T, aR as w, W as L, B as A, ao as b, bB as F, H as $, bA as B, m as j } from "./StoreProvider-CBB99upB.js";
import { M as V } from "./Modal-BMdWqd0Y.js";
import { E as q } from "./types-_ugkpUNx.js";
import { S as J } from "./types-CQ2p58-6.js";
import { I as z } from "./InputText-C55stM8O.js";
import { T as v } from "./Tag-DdkVScyr.js";
import { C as G } from "./Checkbox-DmYVTVOD.js";
import { f as _ } from "./debugStore-BvbyN1Oi.js";
import K from "../../../../../monogon@0.3.4_preact@10.29.0_react@19.2.0/node_modules/monogon/dist/frameworks/preact/MonogonCode.js";
import { Fragment as u } from "../../../../../preact@10.29.0/node_modules/preact/dist/preact.module.js";
try {
  let s = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {}, r = new s.Error().stack;
  r && (s._sentryDebugIds = s._sentryDebugIds || {}, s._sentryDebugIds[r] = "9a6cee7d-d372-4450-a2fd-84a2f55addf8", s._sentryDebugIdIdentifier = "sentry-dbid-9a6cee7d-d372-4450-a2fd-84a2f55addf8");
} catch {
}
const P = "adyen-kyc-tabs", Q = {
  tabs: P
}, U = ({ tabs: s, activeTab: r, onChange: t }) => /* @__PURE__ */ e("div", { className: Q.tabs, children: s.map(({ name: a, label: i, disabled: o }) => /* @__PURE__ */ e(
  L,
  {
    onClick: () => {
      t(a);
    },
    variant: r === a ? "secondary" : "tertiary",
    disabled: o,
    children: i
  },
  a
)) }), W = (s, r) => s.filter(({ key: t }) => t.toLowerCase().includes(r.toLowerCase())), X = (s) => [...s].sort(({ key: r }, { key: t }) => r.localeCompare(t)), f = ({
  data: s,
  heading: r,
  searchTerm: t,
  tagPosition: a = "after",
  sort: i = !1
}) => {
  const o = H(() => {
    const n = t ? W(s, t) : s;
    return i ? X(n) : n;
  }, [s, t]);
  return /* @__PURE__ */ e("div", { children: [
    r ? /* @__PURE__ */ e("h3", { children: r }) : void 0,
    o.length === 0 ? /* @__PURE__ */ e("p", { children: [
      "No results found for ",
      /* @__PURE__ */ e("strong", { children: t })
    ] }) : /* @__PURE__ */ e("table", { children: /* @__PURE__ */ e("tbody", { children: o.map(({ key: n, value: l, label: c, variant: m }) => /* @__PURE__ */ e("tr", { children: [
      a === "before" ? /* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(v, { variant: m ?? "grey", children: l }) }) : void 0,
      /* @__PURE__ */ e("td", { children: [
        /* @__PURE__ */ e("span", { className: "adyen-kyc-debug-modal__table-key", children: n }),
        c && /* @__PURE__ */ e("span", { children: c })
      ] }),
      a === "after" ? /* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(v, { variant: m ?? "grey", children: l }) }) : void 0
    ] }, n)) }) })
  ] });
}, Y = (s) => {
  switch (s) {
    case void 0:
      return "orange";
    case !0:
      return "green";
    case !1:
      return "red";
    default:
      return "blue";
  }
}, Z = ({
  experiments: s,
  settings: r
}) => {
  const [t, a] = y(""), i = b(s).map(
    ([n, l]) => ({
      key: `${n}`,
      value: l ? "Enabled" : "Disabled",
      variant: l ? "green" : "red"
    })
  ), o = b(r).map(([n, l]) => ({
    key: n,
    value: `${l}`,
    variant: Y(l)
  }));
  return /* @__PURE__ */ e(u, { children: [
    /* @__PURE__ */ e(
      z,
      {
        name: "search",
        value: t,
        onInput: (n) => a(n.currentTarget.value),
        placeholder: "Search for Experiments/Settings 🔎",
        trimOnBlur: !0,
        spellCheck: !1,
        "aria-label": "Search experiments or settings",
        "aria-invalid": !1
      }
    ),
    /* @__PURE__ */ e(
      f,
      {
        tagPosition: "before",
        data: i,
        heading: "Experiments",
        searchTerm: t,
        sort: !0
      }
    ),
    /* @__PURE__ */ e(f, { data: o, heading: "Settings", searchTerm: t, sort: !0 })
  ] });
}, ee = "adyen-kyc-searchInput", te = "adyen-kyc-toolbar", ae = "adyen-kyc-fieldHeader", se = "adyen-kyc-status", ne = "adyen-kyc-statusRequired", re = "adyen-kyc-statusOptional", oe = "adyen-kyc-statusHidden", ie = "adyen-kyc-statusInfo", le = "adyen-kyc-reasonsList", de = "adyen-kyc-reasonItem", d = {
  searchInput: ee,
  toolbar: te,
  fieldHeader: ae,
  status: se,
  statusRequired: ne,
  statusOptional: re,
  statusHidden: oe,
  statusInfo: ie,
  reasonsList: le,
  reasonItem: de
}, ce = {
  REQUIRED: d.statusRequired,
  OPTIONAL: d.statusOptional,
  INFO: d.statusInfo,
  HIDDEN: d.statusHidden
}, ue = () => {
  const s = _.value, [r, t] = y(""), [a, i] = y(!1), o = Object.keys(s).filter((n) => n.toLowerCase().includes(r.toLowerCase())).filter((n) => a || s[n].status !== "HIDDEN").sort((n, l) => n === "__FORMS__" ? -1 : l === "__FORMS__" ? 1 : n.localeCompare(l));
  return Object.keys(s).length === 0 ? /* @__PURE__ */ e("p", { children: "No form debug data available. Navigate to a form to see its debug info." }) : /* @__PURE__ */ e("div", { children: [
    /* @__PURE__ */ e("div", { className: d.toolbar, children: [
      /* @__PURE__ */ e(
        "input",
        {
          type: "text",
          placeholder: "Search field...",
          value: r,
          onInput: (n) => t(n.currentTarget.value),
          className: d.searchInput
        }
      ),
      /* @__PURE__ */ e(
        G,
        {
          id: "show-hidden-fields",
          name: "show-hidden-fields",
          label: "Show hidden fields",
          checked: a,
          onChange: () => i(!a)
        }
      )
    ] }),
    o.map((n) => {
      const l = s[n];
      return /* @__PURE__ */ e(B, { onToggle: () => {
      }, children: [
        /* @__PURE__ */ e("template", { slot: "title", children: /* @__PURE__ */ e("div", { className: d.fieldHeader, children: [
          /* @__PURE__ */ e("span", { className: d.status, children: n }),
          " ",
          /* @__PURE__ */ e("span", { className: ce[l.status], children: [
            "(",
            l.status,
            ")"
          ] })
        ] }) }),
        /* @__PURE__ */ e("template", { slot: "content", children: /* @__PURE__ */ e("ul", { className: d.reasonsList, children: l.reasons.map((c, m) => /* @__PURE__ */ e("li", { className: d.reasonItem, children: c }, m)) }) })
      ] }, n);
    })
  ] });
}, me = ({ legalEntityData: s }) => {
  if (!s) return /* @__PURE__ */ e(u, {});
  const { rootLegalEntity: r, rootLegalEntityType: t } = s, a = r.entityAssociations?.map(
    ({ name: i, type: o, jobTitle: n }) => (
      // If `name` is undefined, replace the tuple with `null` to easily filter it out later. Checking this to ensure that the 'data' for DebugTable always has a keyName.
      i ? {
        key: i,
        value: `${o}`,
        label: n,
        variant: "blue"
      } : null
    )
  ).filter(Boolean) ?? [];
  return /* @__PURE__ */ e(u, { children: [
    /* @__PURE__ */ e("span", { children: [
      "Root legal entity type: ",
      /* @__PURE__ */ e(v, { children: t })
    ] }),
    a.length ? /* @__PURE__ */ e(f, { data: a, heading: "Decision Makers" }) : void 0,
    r ? /* @__PURE__ */ e(K, { lang: "json", content: JSON.stringify(r, null, 2) }) : void 0
  ] });
}, he = ({
  metadata: { sdkVersion: s, locale: r, rootLegalEntityId: t }
}) => /* @__PURE__ */ e("div", { className: "adyen-kyc-debug-modal__meta", children: /* @__PURE__ */ e(f, { data: [
  { key: "SDK version", value: s, variant: "green" },
  { key: "Locale", value: r, variant: "blue" },
  { key: "Root legal entity ID", value: t, variant: "teal" }
] }) }), ge = "adyen-kyc-debug-modal", ye = "adyen-kyc-debug-header", fe = "adyen-kyc-footer", pe = "adyen-kyc-footer-copy-status", be = "adyen-kyc-content", g = {
  debugModal: ge,
  debugHeader: ye,
  footer: fe,
  footerCopyStatus: pe,
  content: be
}, ve = "adyen-kyc-header", ke = "adyen-kyc-task-name", De = "adyen-kyc-table", p = {
  header: ve,
  taskName: ke,
  table: De
}, Ee = ({ taskStatuses: s }) => {
  const { t: r } = x("common");
  return /* @__PURE__ */ e("table", { className: p.table, children: [
    /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ e("tr", { className: p.header, children: [
      /* @__PURE__ */ e("th", { children: r((t) => t.task) }),
      /* @__PURE__ */ e("th", { children: r((t) => t.status) }),
      /* @__PURE__ */ e("th", { children: r((t) => t.reason) })
    ] }) }),
    /* @__PURE__ */ e("tbody", { children: b(s).sort(([t], [a]) => t.localeCompare(a)).map(([t, a]) => {
      const { taskType: i, id: o } = F(t);
      return /* @__PURE__ */ e("tr", { children: [
        /* @__PURE__ */ e("td", { className: p.taskName, children: [
          i,
          o ? `: ${o}` : ""
        ] }),
        a ? /* @__PURE__ */ e(u, { children: [
          /* @__PURE__ */ e("td", { children: /* @__PURE__ */ e($, { status: a.status }) }),
          /* @__PURE__ */ e("td", { children: [
            r((n) => n[a.reason]),
            /* @__PURE__ */ e(Se, { status: a })
          ] })
        ] }) : /* @__PURE__ */ e(u, {})
      ] }, t);
    }) })
  ] });
}, Se = ({ status: s }) => {
  const { reason: r, details: t } = s;
  switch (r) {
    case "invalidInputError": {
      const a = t.verificationError, i = a.subErrors;
      return /* @__PURE__ */ e("div", { children: [
        a.code,
        ": ",
        a.message,
        i ? /* @__PURE__ */ e("ul", { children: (a.subErrors ?? []).map((o) => /* @__PURE__ */ e("li", { children: [
          o.code,
          ": ",
          o.message
        ] }, o.code)) }) : /* @__PURE__ */ e(u, {})
      ] });
    }
    case "dataMissingError": {
      const a = t.verificationError, i = a.subErrors;
      return /* @__PURE__ */ e("div", { children: [
        a.code,
        ": ",
        a.message,
        i ? /* @__PURE__ */ e("ul", { children: (a.subErrors ?? []).map((o) => /* @__PURE__ */ e("li", { children: [
          o.code,
          ": ",
          o.message
        ] }, o.code)) }) : /* @__PURE__ */ e(u, {})
      ] });
    }
    case "pendingCapabilities": {
      const a = t.pendingCapabilities;
      return /* @__PURE__ */ e("ul", { children: a.map((i) => /* @__PURE__ */ e("li", { children: i }, i)) });
    }
  }
}, Ce = j(), Fe = ({ onExit: s }) => {
  const { isExperimentEnabled: r } = M(), { getSetting: t } = R(), [a, i] = y(!1), { i18n: o } = x(), [n, l] = y("metadata"), c = N().rootLegalEntity.value, m = Object.keys(_.value).length > 0, k = {
    sdkVersion: "4.0.0-compact.9",
    locale: o.language,
    rootLegalEntityId: c.id
  }, D = T(w(q), r), E = T(w(J), t), S = N().taskStatuses.value, C = {
    rootLegalEntity: c,
    rootLegalEntityType: c.type
  }, O = async () => {
    const h = {
      metadata: k,
      experiments: D,
      settings: E,
      taskStatuses: S,
      legalEntityData: C
    };
    await window.navigator.clipboard.writeText(JSON.stringify(h, null, 2)), i(!0), setTimeout(() => {
      i(!1);
    }, 5e3);
  }, I = [
    {
      name: "metadata",
      label: "Metadata"
    },
    {
      name: "experimentsSettings",
      label: "Experiments & Settings"
    },
    {
      name: "taskStatuses",
      label: "Task Statuses"
    },
    {
      name: "legalEntityData",
      label: "Legal Entity Data"
    }
  ];
  return m && I.push({
    name: "formConfig",
    label: "Form Config"
  }), /* @__PURE__ */ e(V, { size: "fullscreen", onClose: s, ariaLabel: "Debug", children: /* @__PURE__ */ e("div", { className: g.debugModal, children: [
    /* @__PURE__ */ e("div", { className: g.debugHeader, children: [
      /* @__PURE__ */ e("h1", { children: "Debug" }),
      " ",
      /* @__PURE__ */ e(U, { activeTab: n, onChange: (h) => l(h), tabs: I })
    ] }),
    /* @__PURE__ */ e("div", { className: g.content, children: [
      n === "metadata" ? /* @__PURE__ */ e(he, { metadata: k }) : void 0,
      n === "taskStatuses" ? /* @__PURE__ */ e(Ee, { taskStatuses: S }) : void 0,
      n === "experimentsSettings" ? /* @__PURE__ */ e(Z, { experiments: D, settings: E }) : void 0,
      n === "legalEntityData" ? /* @__PURE__ */ e(me, { legalEntityData: C }) : void 0,
      n === "formConfig" ? /* @__PURE__ */ e(ue, {}) : void 0
    ] }),
    /* @__PURE__ */ e("div", { className: g.footer, children: /* @__PURE__ */ e("div", { children: [
      /* @__PURE__ */ e(
        L,
        {
          icon: "document",
          onClick: () => {
            O().catch((h) => {
              Ce.error("Error copying to clipboard:", h);
            });
          },
          children: "Copy debug info"
        }
      ),
      a ? /* @__PURE__ */ e("span", { className: g.footerCopyStatus, children: [
        /* @__PURE__ */ e(A, { name: "check" }),
        " Copied!"
      ] }) : void 0
    ] }) })
  ] }) });
};
export {
  Fe as DebugModal
};
