;
{
  try {
    let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
    n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "c89c86b3-e52a-453f-a75f-49e8ea918274", e._sentryDebugIdIdentifier = "sentry-dbid-c89c86b3-e52a-453f-a75f-49e8ea918274");
  } catch (e) {
  }
}
;
import { jsxs, jsx } from "preact/jsx-runtime";
import { p as useAnalyticsContext, aa as useI18nContext, u as useTranslation, ai as isEmpty, t as IconButton, a2 as translateStringOrObject, bj as Svg } from "./StoreProvider-CqQrndhS.js";
import { H as Header } from "./Header-Dt-hNg1U.js";
import { L as List } from "./List-BAzyC6sw.js";
import { S as StructuredList } from "./StructuredList-BNLhk_zV.js";
import { useEffect } from "preact/hooks";
import { E as ErrorPanel } from "./ErrorPanel-D-VMcBB9.js";
import { t as trackNavigation } from "./trackNavigation-db_h46BT.js";
import { c as createFormUtils } from "./formUtils-CwOJPw6N.js";
import { g as getRoleName } from "./roleMetadata-BhGtDULY.js";
import { i as isSummaryItem } from "./summaryItem-CAQCQSkt.js";
const usePageLandedEvent = () => {
  const userEvents = useAnalyticsContext();
  useEffect(() => {
    userEvents.addPageEvent("Landed on page", {
      actionType: "navigate"
    });
  }, []);
};
const summary = "adyen-kyc-summary";
const summaryContent = "adyen-kyc-summary-content";
const summaryList = "adyen-kyc-summary-list";
const summaryListHeader = "adyen-kyc-summary-list-header";
const summaryListHeaderTitle = "adyen-kyc-summary-list-header-title";
const summaryListItem = "adyen-kyc-summary-list-item";
const summaryListItemKey = "adyen-kyc-summary-list-item-key";
const summaryListItemValue = "adyen-kyc-summary-list-item-value";
const summaryContentLegalCaption = "adyen-kyc-summary-content-legal-caption";
const summaryContentList = "adyen-kyc-summary-content-list";
const summaryContentLogo = "adyen-kyc-summary-content-logo";
const styles = {
  summary,
  summaryContent,
  summaryList,
  summaryListHeader,
  summaryListHeaderTitle,
  summaryListItem,
  summaryListItemKey,
  summaryListItemValue,
  summaryContentLegalCaption,
  summaryContentList,
  summaryContentLogo
};
const summaryStep = {
  formId: "summary",
  formName: "summary"
};
function Summary({
  data,
  forms,
  gotoForm,
  labels,
  problems,
  omitted = {},
  showFormHeader = true,
  showSectionHeader = true,
  showLegalCaption = false,
  showTaxExemptedLegalCaption = false,
  useStructuredList = false
}) {
  const { i18n } = useI18nContext();
  const { t } = useTranslation("common");
  const userEvents = useAnalyticsContext();
  usePageLandedEvent();
  const editForm = (formId) => {
    const formIndex = forms.findIndex((form) => form.formId === formId);
    if (formIndex >= 0) {
      gotoForm(formIndex);
    }
  };
  const allValidationErrors = problems?.validationErrors && Object.values(problems.validationErrors)?.reduce(
    (acc, validError) => ({ ...acc, ...validError }),
    {}
  );
  const allVerificationErrors = problems?.verificationErrors && Object.values(problems.verificationErrors)?.reduce(
    (acc, verifError) => ({ ...acc, ...verifError }),
    {}
  );
  const formUtils = createFormUtils({ labels }, t);
  const summarySectionHeader = (formName, formId) => /* @__PURE__ */ jsxs("header", { className: styles.summaryListHeader, children: [
    /* @__PURE__ */ jsx("h2", { className: styles.summaryListHeaderTitle, children: formName }),
    !omitted.summaryEditButton?.includes(formId) && /* @__PURE__ */ jsx(
      IconButton,
      {
        variant: "tertiary",
        icon: "edit",
        onClick: () => {
          trackNavigation({
            userEvents,
            actionType: "edit",
            toForm: formName,
            label: "Pencil icon"
          });
          editForm(formId);
        },
        ariaLabel: t(($) => $["editForm"], { formName })
      }
    )
  ] });
  const renderSummarySection = (fieldData, labelData = {}, formName, formId, useStructuredList2) => {
    const structuredListItems = Object.entries(fieldData).map(([key, value]) => {
      return {
        term: t(($) => $[labelData[key] || key]),
        details: value
      };
    });
    return !useStructuredList2 ? /* @__PURE__ */ jsxs(List, { variant: "grouped-secondary", children: [
      showSectionHeader && summarySectionHeader(formName, formId),
      /* @__PURE__ */ jsx("dl", { className: styles.summaryList, children: Array.isArray(fieldData) ? fieldData.map((item) => renderBulletedListField(item)) : renderSummaryItems(fieldData, labelData) })
    ] }) : /* @__PURE__ */ jsxs(List, { variant: "grouped-secondary", children: [
      showSectionHeader && summarySectionHeader(formName, formId),
      /* @__PURE__ */ jsx(StructuredList, { items: structuredListItems })
    ] });
  };
  const renderSummaryContent = (summaryData, useStructuredList2) => {
    const summaryList2 = [];
    forms.forEach(({ formId, formName }) => {
      const currentFormData = summaryData[formId];
      const isFormEmpty = !currentFormData || Object.values(currentFormData).every((value) => isEmpty(value));
      if (isFormEmpty || formId === summaryStep.formId || omitted.forms?.includes(formId)) return;
      const summaryItems = currentFormData.hasInnerForms ? renderInnerForms(labels?.[formId], formId, currentFormData) : renderSummarySection(
        currentFormData,
        labels?.[formId],
        t(
          ($) => $[typeof labels?.[formId] === "string" ? labels[formId] : formName]
        ),
        formId,
        useStructuredList2
      );
      summaryList2.push(summaryItems);
    });
    return summaryList2;
  };
  const renderInnerForms = (labelData, parentFormId, innerForms = {}) => {
    if (!innerForms) return [];
    const dataList = [];
    Object.entries(innerForms).forEach(([innerFormName, innerFormFieldData]) => {
      const formName = t(($) => $[labelData?.[innerFormName] || innerFormName]);
      if (typeof innerFormFieldData === "object" && innerFormFieldData !== null) {
        if (Object.values(innerFormFieldData).every((value) => isEmpty(value))) {
          return;
        }
        dataList.push(renderSummarySection(innerFormFieldData, labelData, formName, parentFormId));
      }
    });
    return dataList;
  };
  const renderField = (label, value) => /* @__PURE__ */ jsxs("div", { className: styles.summaryListItem, children: [
    /* @__PURE__ */ jsx("dt", { className: styles.summaryListItemKey, children: label }),
    /* @__PURE__ */ jsx("dd", { className: styles.summaryListItemValue, children: value })
  ] });
  const renderBulletedListField = (item) => /* @__PURE__ */ jsx("ul", { className: styles.summaryContentList, children: /* @__PURE__ */ jsx("li", { children: item }) });
  const renderSummaryItems = (formData = {}, labelData = {}) => {
    if (!formData) return [];
    if (formData?.idVerificationMethod === "instantVerification") {
      return [
        renderField(
          i18n.get("verificationMethod"),
          /* @__PURE__ */ jsx(Svg, { name: "onfido-logo", type: "image", className: styles.summaryContentLogo })
        )
      ];
    }
    const dataList = [];
    Object.entries(formData).forEach(([field, fieldData]) => {
      if (omitted.keys?.includes(field) || !fieldData) return;
      const fieldName = t(($) => $[labelData[field] || field]);
      if (field === "role" && Array.isArray(fieldData)) {
        const label = fieldData.length > 1 ? t(($) => $["roles"]) : fieldName;
        const roles = fieldData.map((role) => t(($) => $[getRoleName(role)])).join(", ");
        dataList.push(renderField(label, roles));
      } else if (isSummaryItem(fieldData)) {
        const { summaryLabel, summaryValue } = fieldData;
        dataList.push(renderField(translateStringOrObject(t, summaryLabel), summaryValue));
      } else if (typeof fieldData === "object") {
        dataList.push(renderSummaryItems(fieldData, labelData));
      } else if (["string", "number"].includes(typeof fieldData)) {
        dataList.push(renderField(fieldName, fieldData));
      }
    });
    return dataList;
  };
  return /* @__PURE__ */ jsxs("div", { role: "region", className: styles.summary, children: [
    showFormHeader && /* @__PURE__ */ jsx(Header, { title: t(($) => $["summary"]), description: t(($) => $["summaryDescription"]) }),
    /* @__PURE__ */ jsxs("div", { className: styles.summaryContent, children: [
      /* @__PURE__ */ jsx(
        ErrorPanel,
        {
          validationErrors: allValidationErrors,
          verificationErrors: allVerificationErrors,
          formUtils,
          id: "ariaErrorField"
        }
      ),
      renderSummaryContent(data, useStructuredList),
      showLegalCaption && /* @__PURE__ */ jsx("div", { className: styles.summaryContentLegalCaption, children: t(($) => $["summaryLegalCaption"]) }),
      showTaxExemptedLegalCaption && /* @__PURE__ */ jsxs("div", { className: styles.summaryContentLegalCaption, children: [
        /* @__PURE__ */ jsx("p", { children: t(($) => $["summaryTaxExemptionLegalCaptionTitle"]) }),
        /* @__PURE__ */ jsxs("ul", { children: [
          /* @__PURE__ */ jsx("li", { children: t(($) => $["summaryTaxExemptionLegalCaption_1"]) }),
          /* @__PURE__ */ jsx("li", { children: t(($) => $["summaryTaxExemptionLegalCaption_2"]) }),
          /* @__PURE__ */ jsx("li", { children: t(($) => $["summaryTaxExemptionLegalCaption_3"]) })
        ] })
      ] })
    ] })
  ] });
}
export {
  Summary as S,
  summaryStep as s,
  usePageLandedEvent as u
};
