import { jsx as b } from "../../../../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { useMemo as y, useCallback as h } from "../../../../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { FormSelect as x } from "../../../../../../../internal/FormWrappers/FormSelect.js";
import { useWizardFormContext as k } from "../../../../../../../../hooks/form/wizard/WizardFormContext.js";
import q from "../../../../../../../../core/Context/preact/useCoreContext.js";
const N = ({
  countriesData: o,
  isAddressFieldRequired: d,
  isFetchingCountries: m,
  countryDatasetData: r,
  isFetchingCountryDataset: u,
  isSameAddress: t = !1,
  showBillingFirst: i = !1,
  isSameAddressCopyEnabled: s = !1
}) => {
  const { i18n: c } = q(), { fieldsConfig: f, setValue: a } = k(), p = y(() => {
    const l = new Set((o?.data ?? []).map(({ countryCode: e }) => e).filter(Boolean));
    return (r?.length ? r : o?.data?.map(({ countryCode: e, countryName: n }) => ({ id: e, name: n })) ?? []).filter(({ id: e }) => !l.size || l.has(e)).sort((e, n) => e.name.localeCompare(n.name));
  }, [o?.data, r]), g = h(
    (l) => {
      i && s && t && a("deliveryAddress.country", l.target.value);
    },
    [t, a, i, s]
  ), C = f["billingAddress.country"]?.required || d("billingAddress.country");
  return /* @__PURE__ */ b(
    x,
    {
      clearable: !0,
      filterable: !0,
      className: "adyen-pe-payment-link-creation-form__billing-address-field--medium",
      fieldName: "billingAddress.country",
      label: c.get("payByLink.creation.fields.billingAddress.country.label"),
      items: p,
      readonly: m || u,
      onChange: g,
      hideOptionalLabel: !0,
      isRequired: C
    }
  );
};
export {
  N as BillingCountryField
};
