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