import { jsx as n, jsxs as le } from "react/jsx-runtime";
import P, { useRef as y, createContext as ce } from "react";
import { createSlotRecipeContext as ie, mergeRefs as ne } from "@chakra-ui/react";
import { useSlotRecipe as de } from "@chakra-ui/react/styled-system";
import { $ as fe, a as $e } from "./Input-CXkgRPwc.es.js";
import { $ as pe } from "./Button-C9AKe3Kt.es.js";
import { $ as g, c as be, b as ve, f as he, a as xe, e as me } from "./utils-CrjF8U_E.es.js";
import { $ as Ce } from "./FieldError-CXcEMuBf.es.js";
import { c as Pe } from "./RSPContexts-DLgb84PF.es.js";
import { $ as ge } from "./Form-CXcEMuBf.es.js";
import { a as De } from "./Group-GVlDKuLP.es.js";
import { $ as ye } from "./Label-BPLFvUwR.es.js";
import { $ as Be } from "./Text-DOcU1ycg.es.js";
import { $ as Ee } from "./Hidden-X9vuhkMZ.es.js";
import { $ as Se } from "./filterDOMProps-Cxz9cAAv.es.js";
import { $ as Ie } from "./useControlledState-3TGZUXux.es.js";
import { d as Re } from "./mergeProps-B-cqsBhL.es.js";
import { $ as ke } from "./useLocalizedStringFormatter-CYDf7GZk.es.js";
import { $ as Me } from "./useTextField-Def10i_1.es.js";
import { Search as Fe, Close as _e } from "@commercetools/nimbus-icons";
import { e as ze } from "./extract-style-props-CMyV-es-.es.js";
import { o as Ae } from "./index-N3Xxo-X9.es.js";
import { n as h, u as Oe } from "./normalize-messages-BN9BAFXe.es.js";
import { $ as Ve } from "./useObjectRef-CaJ5pgjX.es.js";
import { I as we } from "./icon-button-DQaOMIAe.es.js";
var B = {};
B = {
  "Clear search": "مسح البحث"
};
var E = {};
E = {
  "Clear search": "Изчистване на търсене"
};
var S = {};
S = {
  "Clear search": "Vymazat hledání"
};
var I = {};
I = {
  "Clear search": "Ryd søgning"
};
var R = {};
R = {
  "Clear search": "Suche zurücksetzen"
};
var k = {};
k = {
  "Clear search": "Απαλοιφή αναζήτησης"
};
var M = {};
M = {
  "Clear search": "Clear search"
};
var F = {};
F = {
  "Clear search": "Borrar búsqueda"
};
var _ = {};
_ = {
  "Clear search": "Tühjenda otsing"
};
var z = {};
z = {
  "Clear search": "Tyhjennä haku"
};
var A = {};
A = {
  "Clear search": "Effacer la recherche"
};
var O = {};
O = {
  "Clear search": "נקה חיפוש"
};
var V = {};
V = {
  "Clear search": "Obriši pretragu"
};
var w = {};
w = {
  "Clear search": "Keresés törlése"
};
var L = {};
L = {
  "Clear search": "Cancella ricerca"
};
var q = {};
q = {
  "Clear search": "検索をクリア"
};
var T = {};
T = {
  "Clear search": "검색 지우기"
};
var K = {};
K = {
  "Clear search": "Išvalyti iešką"
};
var j = {};
j = {
  "Clear search": "Notīrīt meklēšanu"
};
var N = {};
N = {
  "Clear search": "Tøm søk"
};
var U = {};
U = {
  "Clear search": "Zoekactie wissen"
};
var G = {};
G = {
  "Clear search": "Wyczyść zawartość wyszukiwania"
};
var H = {};
H = {
  "Clear search": "Limpar pesquisa"
};
var W = {};
W = {
  "Clear search": "Limpar pesquisa"
};
var Z = {};
Z = {
  "Clear search": "Ştergeţi căutarea"
};
var J = {};
J = {
  "Clear search": "Очистить поиск"
};
var Q = {};
Q = {
  "Clear search": "Vymazať vyhľadávanie"
};
var X = {};
X = {
  "Clear search": "Počisti iskanje"
};
var Y = {};
Y = {
  "Clear search": "Obriši pretragu"
};
var ee = {};
ee = {
  "Clear search": "Rensa sökning"
};
var ae = {};
ae = {
  "Clear search": "Aramayı temizle"
};
var re = {};
re = {
  "Clear search": "Очистити пошук"
};
var te = {};
te = {
  "Clear search": "清除搜索"
};
var se = {};
se = {
  "Clear search": "清除搜尋條件"
};
var oe = {};
oe = {
  "ar-AE": B,
  "bg-BG": E,
  "cs-CZ": S,
  "da-DK": I,
  "de-DE": R,
  "el-GR": k,
  "en-US": M,
  "es-ES": F,
  "et-EE": _,
  "fi-FI": z,
  "fr-FR": A,
  "he-IL": O,
  "hr-HR": V,
  "hu-HU": w,
  "it-IT": L,
  "ja-JP": q,
  "ko-KR": T,
  "lt-LT": K,
  "lv-LV": j,
  "nb-NO": N,
  "nl-NL": U,
  "pl-PL": G,
  "pt-BR": H,
  "pt-PT": W,
  "ro-RO": Z,
  "ru-RU": J,
  "sk-SK": Q,
  "sl-SI": X,
  "sr-SP": Y,
  "sv-SE": ee,
  "tr-TR": ae,
  "uk-UA": re,
  "zh-CN": te,
  "zh-TW": se
};
function Le(a) {
  return a && a.__esModule ? a.default : a;
}
function qe(a, e, r) {
  let $ = ke(Le(oe), "@react-aria/searchfield"), { isDisabled: u, isReadOnly: o, onSubmit: c, onClear: s, type: p = "search" } = a, b = (t) => {
    const f = t.key;
    f === "Enter" && (u || o) && t.preventDefault(), !(u || o) && (f === "Enter" && c && (t.preventDefault(), c(e.value)), f === "Escape" && (e.value === "" && (!r.current || r.current.value === "") ? t.continuePropagation() : (t.preventDefault(), e.setValue(""), s && s())));
  }, l = () => {
    e.setValue(""), s && s();
  }, v = () => {
    var t;
    (t = r.current) === null || t === void 0 || t.focus();
  }, { labelProps: i, inputProps: x, descriptionProps: m, errorMessageProps: C, ...d } = Me({
    ...a,
    value: e.value,
    onChange: e.setValue,
    onKeyDown: o ? a.onKeyDown : Re(b, a.onKeyDown),
    type: p
  }, r);
  return {
    labelProps: i,
    inputProps: {
      ...x,
      // already handled by useSearchFieldState
      defaultValue: void 0
    },
    clearButtonProps: {
      "aria-label": $.format("Clear search"),
      excludeFromTabOrder: !0,
      preventFocusOnPress: !0,
      isDisabled: u || o,
      onPress: l,
      onPressStart: v
    },
    descriptionProps: m,
    errorMessageProps: C,
    ...d
  };
}
function Te(a) {
  let [e, r] = Ie(D(a.value), D(a.defaultValue) || "", a.onChange);
  return {
    value: e,
    setValue: r
  };
}
function D(a) {
  if (a != null)
    return a.toString();
}
const Ke = /* @__PURE__ */ ce(null), je = /* @__PURE__ */ Ee(function(e, r) {
  [e, r] = g(e, r, Ke);
  let { validationBehavior: $ } = be(ge) || {};
  var u, o;
  let c = (o = (u = e.validationBehavior) !== null && u !== void 0 ? u : $) !== null && o !== void 0 ? o : "native", s = y(null);
  [e, s] = g(e, s, Pe);
  let [p, b] = ve(!e["aria-label"] && !e["aria-labelledby"]), l = Te({
    ...e,
    validationBehavior: c
  }), { labelProps: v, inputProps: i, clearButtonProps: x, descriptionProps: m, errorMessageProps: C, ...d } = qe({
    ...he(e),
    label: b,
    validationBehavior: c
  }, l, s), t = xe({
    ...e,
    values: {
      isEmpty: l.value === "",
      isDisabled: e.isDisabled || !1,
      isInvalid: d.isInvalid || !1,
      isReadOnly: e.isReadOnly || !1,
      isRequired: e.isRequired || !1,
      state: l
    },
    defaultClassName: "react-aria-SearchField"
  }), f = Se(e, {
    global: !0
  });
  return delete f.id, /* @__PURE__ */ P.createElement("div", {
    ...f,
    ...t,
    ref: r,
    slot: e.slot || void 0,
    "data-empty": l.value === "" || void 0,
    "data-disabled": e.isDisabled || void 0,
    "data-invalid": d.isInvalid || void 0,
    "data-readonly": e.isReadOnly || void 0,
    "data-required": e.isRequired || void 0
  }, /* @__PURE__ */ P.createElement(me, {
    values: [
      [
        ye,
        {
          ...v,
          ref: p
        }
      ],
      [
        fe,
        {
          ...i,
          ref: s
        }
      ],
      [
        pe,
        x
      ],
      [
        Be,
        {
          slots: {
            description: m,
            errorMessage: C
          }
        }
      ],
      [
        De,
        {
          isInvalid: d.isInvalid,
          isDisabled: e.isDisabled || !1
        }
      ],
      [
        Ce,
        d
      ]
    ]
  }, t.children));
}), { withProvider: Ne, withContext: ue } = /* @__PURE__ */ ie({
  key: "nimbusSearchInput"
}), Ue = /* @__PURE__ */ Ne("div", "root"), Ge = /* @__PURE__ */ ue(
  "div",
  "leadingElement"
), He = /* @__PURE__ */ ue("input", "input"), We = { clearInput: "Clear search input" }, Ze = { clearInput: "Suchfeld löschen" }, Je = { clearInput: "Borrar entrada de búsqueda" }, Qe = { clearInput: "Effacer les données de recherche" }, Xe = { clearInput: "Limpar entrada de pesquisa" }, Ye = {
  en: /* @__PURE__ */ h(We),
  de: /* @__PURE__ */ h(Ze),
  es: /* @__PURE__ */ h(Je),
  "fr-FR": /* @__PURE__ */ h(Qe),
  "pt-BR": /* @__PURE__ */ h(Xe)
}, ea = (a) => {
  const { ref: e, ...r } = a, $ = Oe(Ye), u = de({ recipe: Ae }), [o, c] = u.splitVariantProps(r), s = y(null), p = Ve(ne(s, e)), [b, l] = ze(c), v = {
    "data-disabled": a.isDisabled ? "true" : void 0,
    "data-invalid": a.isInvalid ? "true" : "false"
  };
  return /* @__PURE__ */ n(je, { ...l, children: ({ state: i }) => /* @__PURE__ */ le(Ue, { ...o, ...b, ...v, children: [
    /* @__PURE__ */ n(Ge, { children: /* @__PURE__ */ n(Fe, {}) }),
    /* @__PURE__ */ n(He, { asChild: !0, children: /* @__PURE__ */ n($e, { ref: p }) }),
    /* @__PURE__ */ n(
      we,
      {
        slot: "null",
        size: "2xs",
        variant: "ghost",
        colorPalette: "primary",
        "aria-label": $.format("clearInput"),
        onPress: () => i.setValue(""),
        opacity: i.value ? 1 : 0,
        pointerEvents: i.value ? "auto" : "none",
        isDisabled: a.isDisabled || a.isReadOnly,
        children: /* @__PURE__ */ n(_e, {})
      }
    )
  ] }) });
};
ea.displayName = "SearchInput";
export {
  ea as S
};
//# sourceMappingURL=search-input-DkAInzQF.es.js.map
