import { jsx as u } from "../../../../../preact@10.29.0/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { useMemo as B, useEffect as z, useCallback as Y, useState as J } from "../../../../../preact@10.29.0/node_modules/preact/hooks/dist/hooks.module.js";
import { useQuery as ie } from "../../../../../@tanstack_preact-query@5.95.2_preact@10.29.0/node_modules/@tanstack/preact-query/build/modern/useQuery.js";
import { aa as t, m as Se, bd as H, u as G, J as Ee, ao as Ie, aK as U, aC as R, aG as Z, aF as te, bg as ue, b as j, bf as se, bk as xe, be as ye, h as le, bh as Te, ap as Le, aq as Me, z as Re, ac as _e, B as Pe, j as $e, aD as Oe, aE as re, bi as me, bj as ae } from "./StoreProvider-CBB99upB.js";
import { u as De } from "./useForm-BQDytQRR.js";
import { c as ge } from "./formUtils-BEcbGHkz.js";
import { F as Q } from "./Field-CPoHG0G-.js";
import { I as pe } from "./InputText-C55stM8O.js";
import { S as he } from "./Select-seF9rM5K.js";
import { u as we } from "./debouncedInputEvent-Cv2S512Y.js";
import { C as Be } from "./CountryField-C7SjQFv_.js";
import { C as de, g as oe, e as ke, c as be, d as Fe } from "./utils-BvFIL5qs.js";
import "./patternValidators-BkY5yvNa.js";
import { Fragment as Ae } from "../../../../../preact@10.29.0/node_modules/preact/dist/preact.module.js";
try {
  let e = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {}, s = new e.Error().stack;
  s && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[s] = "11176880-7281-41b7-80f3-9353ddebf0f1", e._sentryDebugIdIdentifier = "sentry-dbid-11176880-7281-41b7-80f3-9353ddebf0f1");
} catch {
}
const Ve = async (e, s, r) => le(
  {
    baseUrl: s,
    path: `legalEntities/${e}/addresses/cleanse`
  },
  r
), He = () => {
  const { rootLegalEntityId: e, baseUrl: s } = j();
  return Y(
    (r) => Ve(e.value, s.value, r),
    [s.value, e.value]
  );
}, Ue = ({
  address: e,
  city: s,
  country: r,
  postalCode: o
}) => {
  if (!(!e || !r))
    return `${e} ${s ?? ""} ${r} ${o ?? ""}`.trim();
}, Ge = async (e, s, r) => le(
  {
    baseUrl: s,
    path: `legalEntities/${e}/configurations/providers/status`
  },
  r
), Ke = (e, s) => {
  const { rootLegalEntityId: r, baseUrl: o } = j();
  return ie({
    queryKey: ["providersStatus", e],
    queryFn: () => Ge(r.value, o.value, e),
    ...s
  });
}, Ne = async (e, s, r) => $e({
  baseUrl: s,
  path: `legalEntities/${e}/addresses/${r}`
}), qe = (e, s) => {
  const { rootLegalEntityId: r, baseUrl: o } = j();
  return ie({
    queryKey: ["retrieveAddress", e],
    queryFn: () => Ne(r.value, o.value, e),
    ...s
  });
}, Xe = async (e, s, r) => le(
  {
    baseUrl: s,
    path: `legalEntities/${e}/addresses`
  },
  r
), We = (e, s) => {
  const { rootLegalEntityId: r, baseUrl: o } = j();
  return ie({
    queryKey: ["searchAddress", e],
    queryFn: () => Xe(r.value, o.value, e),
    ...s
  });
}, fe = (e, s) => {
  const r = [];
  let o = 0;
  return e[0] === "" ? [s] : (e.forEach((p) => {
    const n = p.split("-"), a = parseInt(n[0]), g = parseInt(n[1]);
    if (o < a) {
      const b = s.substring(o, a);
      r.push(`${b}`);
    }
    const S = s.substring(a, g);
    r.push(
      /* @__PURE__ */ u("span", { className: "adyen-kyc-dropdown-search-element__description--highlight", children: S })
    ), o = g;
  }), o < s.length && r.push(`${s.substring(o)}`), r);
}, Je = ({
  text: e = "",
  highlight: s = "",
  description: r = ""
}) => {
  let o = [];
  if (s === "")
    r ? o.push(`${e}, ${r}`) : o.push(e);
  else {
    const p = s.split(";");
    o = fe(p[0].split(","), e), p.length > 1 ? (o.push(", "), o.push(/* @__PURE__ */ u(Ae, { children: fe(p[1].split(","), r) }))) : r && o.push(`, ${r}`);
  }
  return o;
}, Ze = (e) => {
  const { t: s } = G("common"), { addressAmount: r } = e;
  return /* @__PURE__ */ u(Ae, { children: [
    /* @__PURE__ */ u("span", { className: "adyen-kyc-dropdown-search-element__description", children: Je(e) }),
    r && /* @__PURE__ */ u("div", { className: "adyen-kyc-dropdown-search-element__addresses", children: [
      r,
      " ",
      /* @__PURE__ */ u("span", { className: "adyen-kyc-dropdown-search-element__addresses--text", children: [
        " ",
        s((o) => o.addresses)
      ] }),
      /* @__PURE__ */ u(Pe, { name: "arrow-right", className: "adyen-kyc-dropdown-search-element__addresses--icon" })
    ] })
  ] });
}, ze = ({
  addressText: e,
  country: s,
  labelKey: r,
  errorMessage: o,
  isValid: p,
  readOnly: n,
  optional: a,
  handleBlur: g,
  onAddressTextChange: S,
  onAutofillAddress: b
}) => {
  const { t: E } = G("common"), c = Re(), [A, x] = J(), [O, _] = J(!1), [L, M] = J(), [C, h] = J(), D = we(x, 500), P = We(
    {
      text: A,
      country: s,
      container: C
    },
    { enabled: O && !!A && !!s }
  ), i = qe(L?.id ?? "", {
    enabled: !!L
  }), f = B(
    () => P.data?.results?.map(Ye) ?? [],
    [P.data?.results]
  );
  z(() => {
    i.data && (c.addPageEvent("Success", {
      actionType: "select",
      actionLevel: "field",
      returnType: "backend",
      returnValue: "retrieveAddress"
    }), b(i.data));
  }, [i.data]);
  const w = Y(
    (I) => {
      const v = f.find((K) => K.id === I.id);
      v && (v.type === "Address" ? (M(I), h(void 0)) : (h(v.id), x(`${v.text}`), setTimeout(() => _(!0))));
    },
    [f]
  ), k = B(
    () => f.map((I) => ({
      ...I,
      name: I.text
    })),
    [f]
  );
  return /* @__PURE__ */ u(
    Q,
    {
      name: "address",
      label: _e(E, r),
      errorMessage: o,
      isValid: p,
      optional: a,
      children: (I) => /* @__PURE__ */ u(
        he,
        {
          ...I,
          name: "address",
          filterable: "prefiltered",
          items: k,
          selected: L,
          loading: P.isLoading || i.isLoading,
          onSelect: w,
          getSearchItem: Ze,
          behaviour: "textIsData",
          text: e,
          setText: (v) => {
            S(v), D(v);
          },
          showList: O,
          setShowList: _,
          readonly: !!n,
          placeholder: E((v) => v.address__placeHolder),
          onBlur: g
        }
      )
    }
  );
}, Ye = (e) => {
  if (e.description.includes("Addresses")) {
    const s = e.description.split(" - ");
    return s.length === 1 ? {
      ...e,
      description: "",
      addressAmount: s[0].replace("Addresses", "")
    } : {
      ...e,
      description: s[0],
      addressAmount: s[1].replace("Addresses", "")
    };
  }
  return e;
}, Qe = (e, { country: s }) => {
  switch (s) {
    case t.Australia:
    case t.Brazil:
      return e((r) => r.selectState);
    case t.Canada:
      return e((r) => r.selectProvinceOrTerritory);
    case t.UnitedStates:
      return e((r) => r.stateOrProvince__placeHolder__US);
    default:
      return e((r) => r.stateOrProvince__placeHolder);
  }
};
function je({
  data: e,
  valid: s,
  errors: r,
  labels: o,
  readonly: p,
  handleChangeFor: n,
  selectedCountry: a,
  handleBlur: g
}) {
  const { t: S } = G("common"), { dataset: b, loaded: E } = Le(
    Me.state(a),
    !a || !de.includes(a)
  ), c = be("stateOrProvince", a);
  return !E || !b.length ? null : /* @__PURE__ */ u(
    Q,
    {
      name: "stateOrProvince",
      label: o?.stateOrProvince || S((A) => A[c]),
      errorMessage: r.stateOrProvince,
      isValid: s.stateOrProvince,
      dataTestId: "stateOrProvince",
      children: (A) => /* @__PURE__ */ u(
        he,
        {
          ...A,
          name: "stateOrProvince",
          selected: e.stateOrProvince,
          placeholder: Qe(S, { country: a }),
          items: b,
          readonly: p && !!e.stateOrProvince,
          onChange: n("stateOrProvince"),
          onBlur: g
        }
      )
    }
  );
}
function et({
  schema: e,
  data: s,
  valid: r,
  errors: o,
  fieldProblems: p,
  fieldName: n,
  trimOnBlur: a,
  hideField: g,
  maxlength: S,
  readOnly: b,
  optional: E,
  handleChangeFor: c,
  handleBlur: A
}) {
  const { t: x } = G("common"), { data: O } = Ke({ providers: ["address"] }), _ = O?.statuses?.address?.enabled ?? !1, L = ge({}, x), M = L.getErrorMessage(n, o ?? {}, p), C = s[n], h = be(n, s.country), D = Y(
    ({ houseNumberOrName: i, street: f, line1: w }) => {
      const k = !!i;
      if (!f && w) return c("address", "input")(w);
      if (k) {
        const v = (s.country ? Fe.includes(s.country) : !1) ? `${i} ${f}` : `${f} ${i}`;
        return c("address", "input")(v);
      }
      return c("address", "input")(f);
    },
    [s.country, c]
  ), P = Y(
    (i) => {
      e?.forEach((f) => {
        switch (f) {
          case "country":
            c("country", "input")(i.country ?? " ");
            break;
          case "address":
            D(i);
            break;
          case "otherAddressInformation":
            c("otherAddressInformation", "blur")(i.street2 ?? " ");
            break;
          case "city":
            c("city", "input")(i.city ?? " ");
            break;
          case "postalCode":
            c("postalCode", "input")(i.postalCode ?? " ");
            break;
          case "stateOrProvince":
            c("stateOrProvince", "input")(i.stateOrProvince ?? " ");
            break;
        }
      });
    },
    [c, e, D]
  );
  if (g) return null;
  switch (n) {
    case "address":
      return _ ? /* @__PURE__ */ u(
        ze,
        {
          addressText: s.address,
          country: s.country,
          labelKey: h,
          errorMessage: M,
          isValid: r?.address,
          readOnly: b,
          optional: E,
          handleBlur: (i) => {
            c("address", "blur")(s.address), A?.(i);
          },
          onAddressTextChange: c("address", "input"),
          onAutofillAddress: P
        }
      ) : /* @__PURE__ */ u(
        Q,
        {
          name: n,
          label: x((i) => i[h]),
          errorMessage: M,
          isValid: r?.[n],
          optional: E,
          children: (i) => /* @__PURE__ */ u(
            pe,
            {
              ...i,
              name: n,
              value: C,
              onInput: c(n, "input"),
              onBlur: (f) => {
                c(n, "blur")(f), A?.(f);
              },
              maxLength: S,
              "aria-required": !0,
              "aria-invalid": !r?.[n],
              trimOnBlur: a,
              readonly: !!b
            }
          )
        }
      );
    case "country":
      return /* @__PURE__ */ u(
        Be,
        {
          data: { country: C },
          valid: { country: r?.country },
          errors: { country: M },
          labels: { country: L.getLabel(n, h) },
          readonly: !!b,
          handleChangeFor: c,
          handleBlur: A
        }
      );
    case "stateOrProvince":
      return /* @__PURE__ */ u(
        je,
        {
          data: { stateOrProvince: C },
          valid: { stateOrProvince: r?.stateOrProvince },
          errors: { stateOrProvince: M },
          labels: { stateOrProvince: L.getLabel(n, h) },
          readonly: !!b,
          selectedCountry: s.country,
          handleChangeFor: c,
          handleBlur: A
        }
      );
    default:
      return /* @__PURE__ */ u(
        Q,
        {
          name: n,
          label: x((i) => i[h]),
          errorMessage: M,
          isValid: r?.[n],
          optional: E,
          children: (i) => /* @__PURE__ */ u(
            pe,
            {
              ...i,
              name: n,
              value: n === "postalCode" ? C?.toUpperCase() : C,
              onInput: c(n, "input"),
              onBlur: (f) => {
                c(n, "blur")(f), A?.(f);
              },
              maxLength: S,
              "aria-required": !0,
              "aria-invalid": !r?.[n],
              trimOnBlur: a,
              readonly: !!b
            }
          )
        }
      );
  }
}
const m = (e) => new RegExp(`^\\d{${e}}$`), ve = {
  [t.Australia]: m(4),
  [t.Austria]: m(4),
  [t.Belgium]: /^[1-9]\d{3}$/,
  [t.Brazil]: m(8),
  [t.Bulgaria]: m(4),
  [t.Canada]: /^[ABCEGHJKLMNPRSTVXY]\d[A-Z][ -]?(?:\d[A-Z]\d)?$/,
  [t.Croatia]: /^([1-5])\d{4}$/,
  [t.Cyprus]: m(4),
  [t.CzechRepublic]: /^\d{3} ?\d{2}$/,
  [t.Denmark]: /^(?:DK-)?\d{4}$/,
  [t.Estonia]: m(5),
  [t.Finland]: m(5),
  [t.France]: m(5),
  [t.Georgia]: m(4),
  [t.Germany]: m(5),
  [t.Gibraltar]: /^GX11[ -]?1AA$/,
  [t.Greece]: /^\d{3} ?\d{2}$/,
  [t.Hungary]: m(4),
  [t.Iceland]: m(3),
  [t.Ireland]: /^(?:[ACDEFHKNPRTVWXY]\d{2}|D6W)[ -]?[0-9ACDEFHKNPRTVWXY]{4}$/,
  [t.Italy]: m(5),
  [t.Japan]: m(7),
  [t.Latvia]: /^(?:LV-)?\d{4}$/,
  [t.Liechtenstein]: m(4),
  [t.Lithuania]: /^(?:LT-)?\d{4,5}$/,
  [t.Luxembourg]: m(4),
  [t.Malaysia]: m(5),
  [t.Malta]: /^[A-Za-z]{2,3} ?\d{2}(?:\d{2})?$/,
  [t.Monaco]: /^980\d{2}$/,
  [t.Netherlands]: /^(?:NL-)?[1-9]\d{3} ?(?:[ABCDEFGHIJKLMNOPQRTUVWXYZ][A-Z]|S[BCEFGHIJKLMNOPQRTUVWXYZ])$/,
  [t.NewZealand]: m(4),
  [t.Norway]: m(4),
  [t.Poland]: /^\d{2}-\d{3}$/,
  [t.Portugal]: /^[1-9]\d{3}([- ]?\d{3})?$/,
  [t.PuertoRico]: /^\d{5}(?:[ -]?\d{4})?$/,
  // should exactly match CountryCodes.UnitedStates
  [t.Romania]: m(6),
  [t.Slovakia]: /^(SK-)?\d{5}$/,
  [t.Slovenia]: /^(SI-)?\d{4}$/,
  [t.Singapore]: m(6),
  [t.Spain]: /(?:0[1-9]|[1-4]\d|5[0-2])\d{3}/,
  [t.Sweden]: m(5),
  [t.Switzerland]: /^[1-9]\d{3}$/,
  // https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Validation
  // follows most of the bullet points but not all the restrictions
  [t.UnitedKingdom]: /^[ABCDEFGHIJKLMNOPRSTUWYZ](?:[ABCDEFGHKLMNOPQRSTUVWXY][0-9][ABEHMNPRVWXY0-9]?|[0-9][ABCDEFGHJKPSTUW0-9]?)(?: ?[0-9][ABDEFGHJLNPQRSTUWXYZ]{1,2})?$/,
  [t.UnitedStates]: /^\d{5}(?:[ -]?\d{4})?$/
}, l = (e) => {
  const s = new Array(e).fill("9").join("");
  return {
    // Formatter - excludes non digits and limits to maxlength
    formatter: (r) => r ? r.replace(H("^\\d", "g"), "").substring(0, e) : void 0,
    format: s,
    maxlength: e
  };
}, ne = H(ye.replace(/[-(\\/)]/g, "")), tt = {
  postalCode: {
    formatter: (e, s) => {
      const r = s?.state.data.country, o = ee[r]?.postalCode?.formatter;
      return o ? o(e) : e;
    }
  },
  address: {
    formatter: (e) => e ? se(e).replace(ne, "") : void 0
  },
  otherAddressInformation: {
    formatter: (e) => e ? se(e).replace(ne, "") : void 0
  },
  city: {
    formatter: (e) => e ? se(e).replace(ne, "") : void 0
  }
}, ee = {
  [t.Australia]: { postalCode: l(4) },
  [t.Austria]: { postalCode: l(4) },
  [t.Belgium]: { postalCode: l(4) },
  [t.Brazil]: { postalCode: l(8) },
  [t.Bulgaria]: { postalCode: l(4) },
  [t.Canada]: { postalCode: { format: "A9A 9A9 or A9A9A9", maxlength: 7 } },
  [t.Croatia]: { postalCode: { format: "[1-5]9999", maxlength: 5 } },
  [t.Cyprus]: { postalCode: l(4) },
  [t.CzechRepublic]: { postalCode: { format: "999 99", maxlength: 6 } },
  [t.Denmark]: { postalCode: { format: "9999", maxlength: 7 } },
  [t.Estonia]: { postalCode: l(5) },
  [t.Finland]: { postalCode: l(5) },
  [t.France]: { postalCode: l(5) },
  [t.Germany]: { postalCode: l(5) },
  [t.Gibraltar]: { postalCode: { format: "GX11 1AA", maxlength: 8 } },
  [t.Greece]: { postalCode: { format: "999 99", maxlength: 6 } },
  [t.Hungary]: { postalCode: l(4) },
  [t.Iceland]: { postalCode: l(3) },
  [t.Ireland]: { postalCode: { format: "A99 A999", maxlength: 8 } },
  [t.Italy]: { postalCode: l(5) },
  [t.Japan]: {
    postalCode: l(7)
  },
  [t.Latvia]: { postalCode: { format: "9999 or LV-9999", maxlength: 7 } },
  [t.Liechtenstein]: { postalCode: l(4) },
  [t.Lithuania]: { postalCode: { format: "9999 or 99999 or LT-99999", maxlength: 8 } },
  [t.Luxembourg]: { postalCode: l(4) },
  [t.Malaysia]: { postalCode: l(5) },
  [t.Malta]: {
    postalCode: { format: "2 or 3 letters + 2 or 4 digits (with optional space)", maxlength: 8 }
  },
  [t.Monaco]: { postalCode: { format: "980NN", maxlength: 5 } },
  [t.Netherlands]: { postalCode: { format: "9999AA", maxlength: 7 } },
  [t.NewZealand]: { postalCode: l(4) },
  [t.Norway]: { postalCode: l(4) },
  [t.Poland]: {
    postalCode: {
      // Formatter - excludes non digits & hyphens and limits to a maxlength that varies depending on whether a hyphen is present or not
      formatter: (e) => {
        if (!e) return;
        const s = e.replace(H("^\\d-", "g"), ""), r = s.includes("-") ? 6 : 5;
        return s.substring(0, r);
      },
      format: "99-999",
      maxlength: 6
    }
  },
  [t.Portugal]: {
    postalCode: {
      formatter: (e) => e ? e.replace(H("^\\d-", "g"), "").substring(0, 8) : void 0,
      format: "9999-999",
      maxlength: 8
    }
  },
  [t.PuertoRico]: { postalCode: l(5) },
  [t.Romania]: { postalCode: l(6) },
  [t.Singapore]: { postalCode: l(6) },
  [t.Slovakia]: { postalCode: { format: "99999 or SK-99999", maxlength: 8 } },
  [t.Slovenia]: { postalCode: { format: "9999 or SI-9999", maxlength: 7 } },
  [t.Spain]: { postalCode: l(5) },
  [t.Sweden]: { postalCode: l(5) },
  [t.Switzerland]: { postalCode: l(4) },
  [t.UnitedKingdom]: {
    postalCode: {
      // Disallow special chars & set to maxlength
      formatter: (e) => e ? e.replace(H(ye), "").substring(0, 8) : void 0,
      format: "AA99 9AA or A99 9AA or A9 9AA",
      maxlength: 8
    }
  },
  [t.UnitedStates]: {
    postalCode: {
      format: "12345 or 12345-6789",
      maxlength: 10
    }
  }
}, st = Se(), rt = (e) => {
  const s = e ? ee[e]?.postalCode?.format : void 0;
  return {
    address: [
      {
        modes: ["blur"],
        validate: (r) => U(r),
        errorMessage: "fieldIsRequired"
      }
    ],
    postalCode: {
      modes: ["blur"],
      validate: (r) => {
        const o = e ? ve[e] : void 0;
        return o ? !!r && o.test(r) : !!r;
      },
      errorMessage: s ? {
        key: "invalidFormatExpects",
        values: {
          format: s
        }
      } : "invalidFormat"
    },
    city: {
      modes: ["blur"],
      validate: U,
      errorMessage: "fieldIsRequired"
    },
    stateOrProvince: {
      modes: ["blur"],
      validate: (r) => !!r,
      errorMessage: "fieldIsRequired"
    },
    country: {
      modes: ["blur"],
      validate: (r) => !!r,
      errorMessage: "fieldIsRequired"
    }
  };
}, at = (e) => {
  switch (e) {
    case t.Japan:
      return [
        {
          modes: ["blur"],
          validate: (s) => U(s),
          errorMessage: "checkForTypos"
        },
        {
          modes: ["blur"],
          validate: (s) => Te(s),
          errorMessage: "pleaseUseOnlyNumbersAndDashes"
        }
      ];
    default:
      return;
  }
}, ot = (e, s) => {
  const r = e ? ee[e]?.postalCode?.format : void 0, o = 3, p = 2, n = at(e);
  return {
    address: [
      {
        modes: ["blur"],
        validate: (a) => U(a),
        errorMessage: "fieldIsRequired"
      },
      {
        modes: ["blur"],
        validate: (a) => !R(ae, a),
        errorMessage: "nameMustContainLetters"
      },
      {
        modes: ["blur"],
        validate: (a) => !R(re, a) && !te(a) && !Z(a) && R(me, a),
        errorMessage: "checkForTypos"
      },
      {
        modes: ["blur"],
        validate: (a) => ue(a, o),
        errorMessage: {
          key: "fieldMustContainAtLeast",
          values: {
            fieldName: s((a) => a.address),
            minLength: String(o)
          }
        }
      }
    ],
    postalCode: {
      modes: ["blur"],
      validate: (a) => {
        const g = e ? ve[e] : void 0;
        return g ? !!a && g.test(a) : !!a;
      },
      errorMessage: r ? {
        key: "invalidFormatExpects",
        values: {
          format: r
        }
      } : "invalidFormat"
    },
    city: [
      {
        modes: ["blur"],
        validate: U,
        errorMessage: "fieldIsRequired"
      },
      {
        modes: ["blur"],
        validate: (a) => !R(ae, a),
        errorMessage: "nameMustContainLetters"
      },
      {
        modes: ["blur"],
        validate: (a) => !R(re, a) && !te(a) && !Z(a),
        errorMessage: "checkForTypos"
      },
      {
        modes: ["blur"],
        validate: (a) => ue(a, p),
        errorMessage: {
          key: "fieldMustContainAtLeast",
          values: {
            fieldName: s((a) => a.city),
            minLength: String(p)
          }
        }
      }
    ],
    stateOrProvince: [
      {
        modes: ["blur"],
        validate: (a) => !!a,
        errorMessage: "fieldIsRequired"
      },
      {
        modes: ["blur"],
        validate: (a) => !R(ae, a),
        errorMessage: "nameMustContainLetters"
      },
      {
        modes: ["blur"],
        validate: (a) => !te(a) && !Z(a),
        errorMessage: "checkForTypos"
      }
    ],
    country: [
      {
        modes: ["blur"],
        validate: (a) => !!a,
        errorMessage: "fieldIsRequired"
      },
      {
        modes: ["blur"],
        validate: (a) => !R(Oe, a),
        errorMessage: "nameMustContainLetters"
      },
      {
        modes: ["blur"],
        validate: (a) => !R(re, a) && !Z(a) && R(me, a),
        errorMessage: "checkForTypos"
      }
    ],
    otherAddressInformation: n
  };
}, nt = (e) => ({
  address: {
    modes: ["blur"],
    errorMessage: "addressPoBoxError",
    asyncValidate: async (s, r) => {
      const o = r?.state?.data ?? {}, { country: p } = o;
      if (!s || !p) return !0;
      const n = Ue({ ...o, address: s });
      if (!n) return !0;
      try {
        const { poBox: a } = await e({
          text: n,
          country: p
        });
        return !a;
      } catch (a) {
        return st.error("Error while checking if address is PO box", a), !0;
      }
    }
  }
});
function Ct({
  data: e,
  labels: s,
  readOnly: r,
  hideCountry: o,
  fieldValidationErrors: p,
  allFields: n,
  requiredFields: a,
  optionalFields: g = ["otherAddressInformation"],
  readOnlyFields: S,
  obscuredFields: b,
  trustedFields: E,
  shouldValidate: c,
  onChange: A,
  verifiedAddress: x,
  condensed: O,
  handleFieldChange: _,
  errors: L,
  valid: M,
  addressType: C
}) {
  const { t: h } = G("common"), { isExperimentEnabled: D } = Ee(), P = D(
    "StrictNameAndAddressValidationV4"
  ), i = C === "operationalAddress", f = B(() => a?.length ? a?.includes("stateOrProvince") || e?.country && de.includes(e?.country) ? a : a?.filter((d) => d !== "stateOrProvince") : e?.country && de.includes(e?.country) ? oe(e?.country) : oe(e?.country).filter((d) => d !== "stateOrProvince"), [e?.country, a]), w = B(() => rt(e?.country), [e?.country]), k = B(
    () => ot(e?.country, h),
    [e?.country, h]
  ), I = He(), v = B(
    () => i ? nt(I) : void 0,
    [I, i]
  ), K = De({
    schema: f,
    defaultData: e,
    formatters: tt,
    rules: P ? k : w,
    asyncRules: v,
    fieldProblems: p,
    optionalFields: g,
    obscuredFields: b,
    trustedFields: E,
    shouldValidate: c
  });
  let {
    schema: $,
    data: T,
    errors: N,
    valid: q,
    fieldProblems: X,
    handleChangeFor: F
  } = K;
  const { isValid: ce } = K;
  if (_ && a && p) {
    const d = [...a, ...g], y = oe(e?.country).filter(
      (Ce) => d.includes(Ce)
    );
    F = _, T = e ?? {}, N = L, q = M, X = p, $ = y;
  }
  z(() => {
    x && Ie(x).forEach(([d, y]) => {
      T[d] !== y && F(d, "input")(y);
    });
  }, [x]);
  const V = ge(
    {
      labels: s,
      readOnly: r,
      requiredFields: f,
      optionalFields: g,
      readOnlyFields: S,
      trustedFields: E
    },
    h
  );
  z(() => {
    o && e?.country && e.country !== T.country && f.forEach((d) => d === "country" ? F("country", "input")(e.country) : F(d, "input")(" "));
  }, [e?.country, o]), z(() => {
    A?.({
      schema: $,
      data: T,
      valid: q,
      errors: N,
      fieldProblems: X,
      isValid: ce
    });
  }, [T, N, X, $, q, ce]);
  const W = (d) => {
    if (!V.isRequiredField(d) && !V.isOptionalField(d)) return null;
    const y = d === "country" && o;
    return /* @__PURE__ */ u(
      et,
      {
        schema: $,
        data: T,
        valid: q,
        errors: N,
        fieldProblems: X,
        fieldName: d,
        maxlength: xe(
          ee,
          d,
          T.country
        ),
        hideField: y,
        readOnly: V.isReadOnly(d) || V.isTrusted(d),
        optional: V.isOptionalField(d),
        trimOnBlur: !0,
        handleChangeFor: F
      },
      d
    );
  };
  if (O && T?.country) {
    const d = ke[T.country] ?? [];
    switch (T?.country) {
      case "US":
        return /* @__PURE__ */ u("fieldset", { "aria-label": h((y) => y[C]), className: "adyen-kyc-address", children: [
          $.filter((y) => !d.includes(y)).map((y) => W(y)),
          d.length && /* @__PURE__ */ u("div", { className: "adyen-kyc-address__condensed-fields", children: d.map((y) => W(y)) })
        ] });
      default:
        return /* @__PURE__ */ u("fieldset", { "aria-label": h((y) => y[C]), className: "adyen-kyc-address", children: $.map((y) => W(y)) });
    }
  }
  return /* @__PURE__ */ u("fieldset", { "aria-label": h((d) => d[C]), className: "adyen-kyc-address", children: $.map((d) => W(d)) });
}
export {
  Ct as A,
  je as e,
  Ue as f,
  ot as h,
  rt as j,
  Ke as u
};
