import { jsx as r, jsxs as c, Fragment as ie } from "react/jsx-runtime";
import { n as E, u as ne } from "./normalize-messages-BN9BAFXe.es.js";
import { M as k } from "./money-input-BuTBQcdW.es.js";
import { F as I } from "./form-field-ClimvHF6.es.js";
import { useCallback as fe, useState as he, useMemo as be } from "react";
import { j as Fe, k as Le } from "./Dialog-7Yf08giu.es.js";
import { g as ve } from "./CollectionBuilder-CTjJUDzO.es.js";
import { WarningAmber as se, HelpOutline as xe, Payments as Ie, Language as Me, ErrorOutline as Ce } from "@commercetools/nimbus-icons";
import { P as $e } from "./popover-BLYu6bVv.es.js";
import { createSlotRecipeContext as ze } from "@chakra-ui/react";
import { I as _ } from "./icon-DIEEgcIZ.es.js";
import { R as Se } from "./rich-text-input-Bo_zGUyj.es.js";
import { M as we } from "./multiline-text-input-DZ31Npjo.es.js";
import { T as je } from "./text-input-DMqogV2V.es.js";
import { a as oe } from "./mergeProps-B-cqsBhL.es.js";
import { $ as Ee } from "./useField-BxLfE_kx.es.js";
import { a as re } from "./field-errors-DYvB-OZF.es.js";
import { S as D } from "./stack-CoNreM7B.es.js";
import { I as ke } from "./icon-button-DQaOMIAe.es.js";
import { B as te } from "./box-DuBoAZvq.es.js";
import { B as Pe } from "./button-BX2O6MQP.es.js";
const Te = {
  hideCurrencies: "Hide all currencies",
  hideLanguages: "Hide all languages",
  infoBoxTriggerAriaLabel: "more info",
  missingRequiredField: "This field is required. Provide at least one value.",
  showCurrencies: "Show all currencies",
  showLanguages: "Show all languages"
}, Ae = {
  hideCurrencies: "Alle Währungen ausblenden",
  hideLanguages: "Alle Sprachen ausblenden",
  infoBoxTriggerAriaLabel: "Weitere Informationen",
  missingRequiredField: "Dies ist ein Pflichtfeld. Bitte geben Sie mindestens einen Wert an.",
  showCurrencies: "Alle Währungen anzeigen",
  showLanguages: "Alle Sprachen anzeigen"
}, Be = {
  hideCurrencies: "Ocultar todas las monedas",
  hideLanguages: "Ocultar todas las monedas",
  infoBoxTriggerAriaLabel: "más información",
  missingRequiredField: "Este valor es necesario. Proporciona al menos un valor.",
  showCurrencies: "Mostrar todas las monedas",
  showLanguages: "Mostrar todos los idiomas"
}, Re = {
  hideCurrencies: "Masquer toutes les devises",
  hideLanguages: "Masquer toutes les langues",
  infoBoxTriggerAriaLabel: "Plus d'informations",
  missingRequiredField: "Ce champ est requis. Indiquez au moins une valeur.",
  showCurrencies: "Afficher toutes les devises",
  showLanguages: "Afficher toutes les langues"
}, qe = {
  hideCurrencies: "Ocultar todas as ocorrências",
  hideLanguages: "Ocultar todos os idiomas",
  infoBoxTriggerAriaLabel: "mais informações",
  missingRequiredField: "Este campo é obrigatório. Forneça pelo menos um valor.",
  showCurrencies: "Mostrar todas as ocorrências",
  showLanguages: "Mostrar todos os idiomas"
}, ae = {
  en: /* @__PURE__ */ E(Te),
  de: /* @__PURE__ */ E(Ae),
  es: /* @__PURE__ */ E(Be),
  "fr-FR": /* @__PURE__ */ E(Re),
  "pt-BR": /* @__PURE__ */ E(qe)
}, { withProvider: ye, withContext: p } = /* @__PURE__ */ ze({
  key: "nimbusLocalizedField"
}), He = /* @__PURE__ */ ye("fieldset", "root"), Ve = /* @__PURE__ */ p("legend", "label"), De = /* @__PURE__ */ p("div", "infoDialog"), We = /* @__PURE__ */ p("div", "fieldsContainer"), _e = /* @__PURE__ */ p("div", "description"), Ne = /* @__PURE__ */ p("div", "error"), Oe = /* @__PURE__ */ p("div", "toggleButtonContainer"), Ue = /* @__PURE__ */ p("div", "localeFieldRoot"), Je = /* @__PURE__ */ p("div", "localeFieldLabel"), Qe = /* @__PURE__ */ p("div", "localeFieldInput"), Xe = () => {
  const e = ne(ae);
  return /* @__PURE__ */ r(I.Error, { children: e.format("missingRequiredField") });
}, F = (e, o) => e && o ? `${e}.${o}` : void 0, W = (e) => e.split("-")[0], Ye = (e, o) => {
  const t = W(e), i = o.filter(
    (l) => W(l) === t
  );
  return {
    unrelated: o.filter(
      (l) => W(l) !== t
    ),
    related: i
  };
}, Ze = (e, o) => {
  const { related: t, unrelated: i } = Ye(
    e,
    o.filter((n) => n !== e)
  );
  return [e, ...t.sort(), ...i.sort()];
}, Ge = (e, o) => {
  const t = o.filter(
    (i) => i !== e
  );
  return [e, ...t.sort()];
}, Ke = (e, o) => e && Object.keys(e).length > 0 && o ? Object.keys(e).some(
  (t) => t !== o
) : !1, eo = (e, o) => Array.from(
  /* @__PURE__ */ new Set([...e, ...Object.keys(o)])
).reduce(
  (i, n) => ({
    ...i,
    [n]: o?.[n] || ""
  }),
  {}
), oo = (e) => e ? Object.values(e).every(
  (o) => !o || o?.trim().length === 0
) : !0, ro = (e) => (typeof e != "object" && console.warn(
  "Nimbus Localized Field - Warning: omitEmptyTranslations must be called with an object"
), Object.entries(e).reduce(
  (o, [t, i]) => i && i.trim().length > 0 ? {
    ...o,
    [t]: i
  } : o,
  {}
)), to = (e) => e ? Object.values(e).some(Boolean) : !1;
function io(e) {
  return e;
}
const no = (e, o) => Object.values(e).map((t) => k.convertToMoneyValue(t, o)), so = (e = [], o) => e.reduce(
  (t, i) => {
    const n = k.parseMoneyValue(i, o);
    return {
      ...t,
      [n.currencyCode]: n
    };
  },
  {}
), ao = (e, o) => Object.keys(e).filter(
  (i) => k.isHighPrecision(e[i], o)
), lo = (e) => Object.keys(e).filter(
  (t) => k.isEmpty(e[t])
), co = ({
  type: e,
  size: o,
  localeOrCurrency: t,
  id: i,
  name: n,
  inputValue: l,
  description: M,
  warning: f,
  error: h,
  onChange: L,
  onBlur: C,
  onFocus: $,
  isRequired: z,
  isReadOnly: b,
  isDisabled: v,
  isInvalid: x,
  touched: a,
  ...B
}) => {
  let s;
  switch (e) {
    case "text":
    default:
      s = je;
      break;
    case "multiLine":
      s = we;
      break;
    case "money":
      s = k;
      break;
    case "richText":
      s = Se;
      break;
  }
  const S = e === "money" ? l || { amount: "", currencyCode: t } : l || "", T = fe(
    (d) => {
      const R = {
        target: typeof d == "object" ? {
          id: d.target.id,
          name: d.target.name,
          locale: void 0,
          currency: t,
          value: d.target.value
        } : { id: i, name: n, locale: t, currency: void 0, value: d }
      };
      L(R);
    },
    [i, n, t, L]
  );
  return /* @__PURE__ */ r(Ue, { asChild: !0, children: /* @__PURE__ */ c(
    I.Root,
    {
      isDisabled: v,
      isReadOnly: b,
      isInvalid: (x || !!h) && a,
      direction: "row",
      size: o,
      id: i,
      children: [
        /* @__PURE__ */ r(
          Je,
          {
            display: e === "money" ? "none" : void 0,
            ...v && { "data-disabled": v },
            asChild: !0,
            children: /* @__PURE__ */ r(I.Label, { children: t.toLocaleUpperCase() })
          }
        ),
        /* @__PURE__ */ r(I.Input, { children: /* @__PURE__ */ r(
          Qe,
          {
            "aria-required": z,
            asChild: !0,
            children: /* @__PURE__ */ r(
              s,
              {
                ...B,
                size: o,
                value: S,
                onChange: T,
                onBlur: (d) => C?.(d, t),
                onFocus: (d) => $?.(d, t),
                isRequired: z,
                isDisabled: v,
                isReadOnly: b,
                isInvalid: (x || !!h) && a
              }
            )
          }
        ) }),
        (M || f && a) && /* @__PURE__ */ r(
          I.Description,
          {
            role: f && a ? "status" : void 0,
            color: f && a ? "warning.11" : void 0,
            display: "flex",
            gap: "100",
            alignItems: "center",
            children: f && a ? /* @__PURE__ */ c(ie, { children: [
              /* @__PURE__ */ r(_, { colorPalette: "warning", children: /* @__PURE__ */ r(se, {}) }),
              f
            ] }) : M
          }
        ),
        h && a && /* @__PURE__ */ r(I.Error, { children: h })
      ]
    }
  ) });
}, uo = ({
  type: e = "text",
  id: o,
  name: t,
  defaultLocaleOrCurrency: i,
  valuesByLocaleOrCurrency: n,
  placeholdersByLocaleOrCurrency: l,
  descriptionsByLocaleOrCurrency: M,
  warningsByLocaleOrCurrency: f,
  errorsByLocaleOrCurrency: h,
  label: L,
  hint: C,
  description: $,
  warning: z,
  warnings: b,
  renderWarning: v,
  error: x,
  errors: a,
  renderError: B,
  touched: s,
  isRequired: P,
  isDisabled: S,
  isReadOnly: T,
  onChange: d,
  onBlur: N,
  onFocus: R,
  defaultExpanded: le = !1,
  displayAllLocalesOrCurrencies: O = !1,
  size: U,
  autoFocus: J,
  ["data-track-component"]: de,
  ["data-testid"]: ce,
  ["data-test"]: ue,
  // DOM & Style props for wrapper container
  ...ge
}) => {
  const [u, Q] = he(
    O || le
  ), w = ne(ae), X = oe(), Y = oe(), q = !!(x || a && Object.values(a).some((g) => g === !0)), j = !!(z || b && Object.values(b).some(Boolean)), A = !!(q && s), { labelProps: Z, fieldProps: G, descriptionProps: y, errorMessageProps: H } = Ee({
    id: o,
    label: L,
    description: $,
    errorMessage: x,
    isInvalid: A
  }), V = Object.keys(
    n
  ), me = be(() => (e === "money" ? Ge(
    i,
    V
  ) : Ze(
    i,
    V
  )).reduce(
    (ee, m) => {
      const pe = {
        localeOrCurrency: m,
        inputValue: n[m],
        placeholder: l?.[m],
        description: M?.[m],
        warning: f?.[m],
        error: h?.[m],
        // autoFocus default/first locale field
        ...m === i && J ? { autoFocus: J } : {},
        isInvalid: A,
        isRequired: P,
        isDisabled: S,
        isReadOnly: T
      };
      return u || // Only display defaultLocaleOrInput field if fieldGroup is not expanded
      !u && m === i ? [...ee, pe] : ee;
    },
    []
  ), [
    n,
    l,
    M,
    f,
    h,
    i,
    u,
    A,
    P,
    S,
    T
  ]), K = (Ke(
    h,
    i
  ) || q) && s;
  return K && !u && Q(!0), /* @__PURE__ */ c(
    He,
    {
      ...ge,
      ...G,
      "aria-details": C ? Y : void 0,
      type: e,
      size: U,
      name: t,
      children: [
        L && /* @__PURE__ */ c(D, { direction: "row", gap: "0", children: [
          /* @__PURE__ */ c(Ve, { ...Z, children: [
            L,
            P && /* @__PURE__ */ r("sup", { "aria-hidden": "true", children: "*" })
          ] }),
          C && /* @__PURE__ */ c(Fe, { children: [
            /* @__PURE__ */ r(
              ke,
              {
                id: Y,
                "aria-label": w.format("infoBoxTriggerAriaLabel"),
                size: "2xs",
                colorPalette: "info",
                variant: "link",
                children: /* @__PURE__ */ r(xe, {})
              }
            ),
            /* @__PURE__ */ r($e, { padding: 0, children: /* @__PURE__ */ r(De, { asChild: !0, children: /* @__PURE__ */ r(Le, { children: /* @__PURE__ */ r(te, { p: "300", children: C }) }) }) })
          ] })
        ] }),
        /* @__PURE__ */ r(
          We,
          {
            id: X,
            "data-expanded": u,
            children: /* @__PURE__ */ r(ve, { items: me, children: (g) => /* @__PURE__ */ r(
              co,
              {
                ...g,
                size: U,
                type: e,
                onChange: d,
                onBlur: N,
                onFocus: R,
                touched: s,
                id: F(
                  G.id,
                  g.localeOrCurrency
                ),
                name: F(t, g.localeOrCurrency),
                "data-test": F(
                  ue,
                  g.localeOrCurrency
                ),
                "data-testid": F(
                  ce,
                  g.localeOrCurrency
                ),
                "data-track-component": F(
                  de,
                  g.localeOrCurrency
                )
              }
            ) })
          }
        ),
        !O && V.length > 1 && /* @__PURE__ */ r(Oe, { children: /* @__PURE__ */ c(
          Pe,
          {
            "aria-controls": X,
            "aria-describedby": Z.id,
            "aria-expanded": u,
            onPress: () => Q(!u),
            isDisabled: S || K && u,
            variant: "ghost",
            size: "2xs",
            colorPalette: "primary",
            children: [
              /* @__PURE__ */ r(
                te,
                {
                  as: e === "money" ? Ie : Me,
                  display: "inline-flex",
                  boxSize: "400",
                  verticalAlign: "text-bottom",
                  mr: "100"
                }
              ),
              e === "money" ? u ? w.format("hideCurrencies") : w.format("showCurrencies") : u ? w.format("hideLanguages") : w.format("showLanguages")
            ]
          }
        ) }),
        ($ || j && s) && /* @__PURE__ */ r(
          _e,
          {
            role: j && s ? "status" : void 0,
            color: j && s ? "warning.11" : void 0,
            "aria-labelledby": `${y.id}-warning`,
            ...y,
            children: j && s ? /* @__PURE__ */ c(ie, { children: [
              /* @__PURE__ */ r(_, { colorPalette: "warning", children: /* @__PURE__ */ r(se, {}) }),
              /* @__PURE__ */ c(D, { gap: "0", id: `${y.id}-warning`, children: [
                z,
                b && j && /* @__PURE__ */ r(
                  re,
                  {
                    errors: b,
                    renderError: v,
                    colorPalette: "warning",
                    role: void 0
                  }
                )
              ] })
            ] }) : $
          }
        ),
        A && /* @__PURE__ */ c(
          Ne,
          {
            "aria-labelledby": `${H.id}-error`,
            role: "alert",
            ...H,
            children: [
              /* @__PURE__ */ r(_, { children: /* @__PURE__ */ r(Ce, {}) }),
              /* @__PURE__ */ c(D, { gap: "0", id: `${H.id}-error`, children: [
                x,
                a && q && /* @__PURE__ */ r(
                  re,
                  {
                    errors: a,
                    renderError: B,
                    role: void 0
                  }
                )
              ] })
            ]
          }
        )
      ]
    }
  );
}, Ao = /* @__PURE__ */ Object.assign(uo, {
  // Add util methods here for compat with uikit - see https://github.com/commercetools/ui-kit/blob/e97e0c7e8f3e9393981bf1949573212d7c571c90/packages/components/inputs/localized-text-input/src/localized-text-input.tsx#L396
  getId: F,
  getName: F,
  isTouched: to,
  isEmpty: oo,
  createLocalizedString: eo,
  omitEmptyTranslations: ro,
  RequiredValueErrorMessage: Xe,
  toFieldErrors: io,
  convertToMoneyValues: no,
  parseMoneyValues: so,
  getHighPrecisionCurrencies: ao,
  getEmptyCurrencies: lo
});
export {
  Ao as L
};
//# sourceMappingURL=localized-field-y1Maik4X.es.js.map
