import { jsx as m } from "../../../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { useMemo as o, useCallback as d } from "../../../../../../../external/.pnpm/preact@10.28.2/node_modules/preact/hooks/dist/hooks.module.js";
import { useFetch as g } from "../../../../../../../hooks/useFetch.js";
import { FormSelect as p } from "../../../../../../internal/FormWrappers/FormSelect.js";
import { useWizardFormContext as f } from "../../../../../../../hooks/form/wizard/WizardFormContext.js";
import h from "../../../../../../../core/Context/preact/useCoreContext.js";
const k = () => {
  const { i18n: c, getCdnDataset: s } = h(), { fieldsConfig: n } = f(), a = o(() => n?.shopperLocale?.options, [n]), e = g({
    fetchOptions: { enabled: !0 },
    queryFn: d(async () => s ? await s({
      name: "languages",
      extension: "json",
      fallback: []
    }) ?? [] : [], [s])
  }), i = o(() => (e.data ?? []).filter(({ value: t }) => a?.length ? a?.includes(t) : !0).map(({ text: t, value: r }) => ({
    // TODO - Handle 'auto detect' option when submitting information to the BE
    id: r === null ? "auto" : r,
    name: t
  })).sort(({ name: t }, { name: r }) => t.localeCompare(r)), [e.data, a]), l = o(() => n.shopperLocale?.required, [n]);
  return o(() => {
    const u = i.length > 0;
    return !e.isFetching && !u && !l;
  }, [e.isFetching, i.length, l]) ? null : /* @__PURE__ */ m(
    p,
    {
      filterable: !0,
      fieldName: "shopperLocale",
      label: c.get("payByLink.creation.fields.language.label"),
      items: i,
      readonly: e.isFetching
    }
  );
};
export {
  k as LanguageField
};
