;
{
  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] = "f34dc6d4-0a06-4f2d-9911-3bc1a27c58d6", e._sentryDebugIdIdentifier = "sentry-dbid-f34dc6d4-0a06-4f2d-9911-3bc1a27c58d6");
  } catch (e) {
  }
}
;
import { jsxs, jsx } from "preact/jsx-runtime";
import { s as summaryItem } from "./summaryItem-CAQCQSkt.js";
import { useQuery } from "@tanstack/preact-query";
import { b as useApiContext, k as httpGet, a0 as CountryCodes } from "./StoreProvider-CqQrndhS.js";
import { u as useSetting } from "./useSetting-cDJSB-VL.js";
import { u as useCapabilities } from "./TaxInformationField-Cd1at8Ld.js";
import { i as isEmpty } from "./isEmpty-vwqWRDI4.js";
import { m as mapSchemaFieldsToApiScriptLocalization } from "./mapAddressLocalizationToJpAddressSchema-vJWbpAyq.js";
const mapJpAddressSummary = (data, datasetUtils) => {
  if (!data) return {};
  return {
    country: datasetUtils.getCountryName("JP") ?? "JP",
    postalCode: summaryItem("postalCode", data.postalCode),
    stateOrProvince: summaryItem(
      "prefecture",
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("p", { children: data.jaHaniStateOrProvince }),
        /* @__PURE__ */ jsx("p", { children: data.jaKanaStateOrProvince }),
        /* @__PURE__ */ jsx("p", { children: data.stateOrProvince })
      ] })
    ),
    city: summaryItem(
      "districtTownAreaCityWard",
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("p", { children: data.jaHaniCity }),
        /* @__PURE__ */ jsx("p", { children: data.jaKanaCity }),
        /* @__PURE__ */ jsx("p", { children: data.city })
      ] })
    ),
    otherAddressInformation: summaryItem("chomeAndBanchi", data.otherAddressInformation),
    address: summaryItem(
      "buildingNameFloorRoomNumberEtc",
      /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("p", { children: data.jaHaniAddress }),
        /* @__PURE__ */ jsx("p", { children: data.address })
      ] })
    )
  };
};
const getSupportedCountries = async (legalEntityId, baseUrl) => {
  return httpGet({
    baseUrl,
    path: `legalEntities/${legalEntityId}/configurations/supportedCountries`
  });
};
const useSupportedCountries = (options) => {
  const { rootLegalEntityId, baseUrl } = useApiContext();
  return useQuery({
    queryKey: ["supportedCountries"],
    queryFn: () => getSupportedCountries(rootLegalEntityId.value, baseUrl.value),
    ...options
  });
};
const businessAccountCountries = [
  CountryCodes.Austria,
  CountryCodes.Belgium,
  CountryCodes.Croatia,
  CountryCodes.Cyprus,
  CountryCodes.Estonia,
  CountryCodes.Finland,
  CountryCodes.France,
  CountryCodes.Germany,
  CountryCodes.Greece,
  CountryCodes.Ireland,
  CountryCodes.Italy,
  CountryCodes.Latvia,
  CountryCodes.Lithuania,
  CountryCodes.Luxembourg,
  CountryCodes.Malta,
  CountryCodes.Netherlands,
  CountryCodes.Portugal,
  CountryCodes.Slovakia,
  CountryCodes.Slovenia,
  CountryCodes.Spain,
  CountryCodes.UnitedKingdom,
  CountryCodes.UnitedStates
];
const useAllowedCountries = () => {
  const capabilities = Object.keys(useCapabilities() ?? {});
  const isLimitCountryBusinessAccountCustomersEnabled = capabilities.includes("issueBankAccount");
  const acceptedCountriesSetting = useSetting("acceptedCountries");
  const { data } = useSupportedCountries({ enabled: !acceptedCountriesSetting });
  const allowedCountries = acceptedCountriesSetting ?? data?.countries;
  if (!allowedCountries) return;
  return isLimitCountryBusinessAccountCustomersEnabled ? businessAccountCountries.filter((country) => allowedCountries.includes(country)) : allowedCountries;
};
const toFullWidth = (value) => {
  const halfWidthKatakana = [..."｡｢｣､･ｦｧｨｩｪｫｬｭｮｯｰｱｲｳｴｵｶｷｸｹｺｻｼｽｾｿﾀﾁﾂﾃﾄﾅﾆﾇﾈﾉﾊﾋﾌﾍﾎﾏﾐﾑﾒﾓﾔﾕﾖﾗﾘﾙﾚﾛﾜﾝﾞﾟ"];
  const fullWidthKatakana = [
    ..."。「」、・ヲァィゥェォャュョッーアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン゛゜"
  ];
  const hangul1 = { name: "hangul1", halfRE: /[ﾡ-ﾾ]/, fullRE: /[ᆨ-ᇂ]/, delta: -60921 };
  const hangul2 = { name: "hangul2", halfRE: /[ￂ-ￜ]/, fullRE: /[ᅡ-ᅵ]/, delta: -61025 };
  const latin = { name: "latin", halfRE: /[!-~]/, fullRE: /[！-～]/, delta: 65248 };
  const extras = {
    half: "¢£¬¯¦¥₩ |←↑→↓■°",
    full: "￠￡￢￣￤￥￦　￨￩￪￫￬￭￮"
  };
  const converters = [latin, hangul1, hangul2];
  const convertLatinHangul = (c) => {
    for (let j = 0; j < converters.length; j += 1) {
      const converter = converters[j];
      const isHalfWidth = converter.halfRE.test(c);
      if (isHalfWidth) {
        return String.fromCharCode(c.charCodeAt(0) + converter.delta);
      }
    }
    return null;
  };
  let result = "";
  for (let i = 0; i < value.length; i += 1) {
    const c = value[i];
    const convertedChar = convertLatinHangul(c);
    if (convertedChar) {
      result += convertedChar;
      continue;
    }
    const indexOfHalfWidthKatakana = halfWidthKatakana.indexOf(c);
    if (indexOfHalfWidthKatakana >= 0) {
      const fullWidthKatakanaCharacter = fullWidthKatakana[indexOfHalfWidthKatakana];
      result += fullWidthKatakanaCharacter;
      continue;
    }
    const indexOfHalfWidthExtras = extras.half.indexOf(c);
    if (indexOfHalfWidthExtras >= 0) {
      result += extras.full[indexOfHalfWidthExtras];
      continue;
    }
    result += c;
  }
  return result;
};
const mapJpAddressSchemaToAddressLocalizations = (data) => {
  if (!data) return [];
  return [
    mapSchemaFieldsToApiScriptLocalization(data, "jaHani"),
    mapSchemaFieldsToApiScriptLocalization(data, "jaKana")
  ].filter(({ fields }) => !isEmpty(fields)).map(({ script, fields }) => ({
    script,
    fields: {
      city: fields.city,
      // mismatch between API `street` and schema `address`
      // only applicable for `ja-Hani`, not `ja-Kana`
      ..."address" in fields ? { street: fields.address } : void 0
    }
  }));
};
export {
  mapJpAddressSummary as a,
  mapJpAddressSchemaToAddressLocalizations as m,
  toFullWidth as t,
  useAllowedCountries as u
};
