import { o as xn } from "./rolldown-runtime.js";
import { i as ao, n as lo, r as uo, t as co } from "./vendor/react.js";
import { t as fo } from "./check.js";
import { t as ln } from "./chevron-down.js";
import { i as Be, n as Pt, o as bn, r as po, s as at, t as Ye, u as un } from "./useRenderElement.js";
import { n as te, t as Oe } from "./useIsoLayoutEffect.js";
import { t as Xt } from "./useButton.js";
import { t as $e } from "./utils.js";
import { a as mo, n as vn, t as go } from "./useTransitionStatus.js";
import { n as In } from "./useTimeout.js";
import { t as yn } from "./useBaseUiId.js";
import { n as cn, r as ho, t as xo } from "./detectBrowser.js";
import { n as ze, r as Tt } from "./shadowDom.js";
import { A as bo, T as vo, b as Io, d as s, f as C, i as yo, o as Co, p as Ro, r as Eo, u as Po } from "./popupStateMapping.js";
import { o as ht } from "./event.js";
import { t as Vo } from "./owner.js";
import { n as So } from "./DirectionContext.js";
import { d as Qe, f as wo, g as Ne, h as To, i as Ao, n as pt, p as Mo, s as Oo, t as Y, u as Vt } from "./createBaseUIEventDetails.js";
import { t as jo } from "./useValueAsRef.js";
import { n as Cn, t as ko } from "./visuallyHidden.js";
import { a as No, i as Rn, r as _o, t as Lo } from "./useOpenInteractionType.js";
import { a as Fo, n as Do, r as Ho, t as qo } from "./usePositioner.js";
import { n as Bo, t as zo } from "./useTypeahead.js";
import { t as Go } from "./inertValue.js";
import { t as Wt } from "./useControlled.js";
import { n as Uo, t as Ko } from "./useCompositeListItem.js";
import { t as Wo } from "./CompositeList.js";
import { t as $o } from "./FieldTooltip.js";
import { n as Qo, t as Yo } from "./field-props.js";
import { a as Jt, c as Xo, o as Jo, r as En, t as Zo } from "./useRegisterFieldControl.js";
import { t as er } from "./FormContext.js";
import { t as Pn } from "./useLabelableId.js";
import { a as tr, c as nr, i as or, l as rr, n as sr, o as ir, r as ar, s as lr, t as ur } from "./Field.js";
import { t as cr } from "./Tag.js";
import { t as St } from "./useValueChanged.js";
import { n as Vn } from "./resolveAriaLabelledBy.js";
import { a as fe, c as dr, d as fr, l as $t, n as pr, o as mt, s as At, t as mr, u as gr } from "./resolveValueLabel.js";
import { t as hr } from "./getPseudoElementBounds.js";
import { t as xr } from "./useAnchoredPopupScrollLock.js";
var o = /* @__PURE__ */ xn(ao()), Sn = /* @__PURE__ */ o.createContext(void 0), wn = /* @__PURE__ */ o.createContext(void 0), Tn = /* @__PURE__ */ o.createContext(void 0), An = /* @__PURE__ */ o.createContext("");
function Ge() {
  const e = o.useContext(Sn);
  if (!e) throw new Error(at(22));
  return e;
}
function Mt() {
  const e = o.useContext(wn);
  if (!e) throw new Error(at(23));
  return e;
}
function Xe() {
  const e = o.useContext(Tn);
  if (!e) throw new Error(at(24));
  return e;
}
function Mn() {
  return o.useContext(An);
}
var i = {
  id: C((e) => e.id),
  labelId: C((e) => e.labelId),
  items: C((e) => e.items),
  selectedValue: C((e) => e.selectedValue),
  hasSelectionChips: C((e) => {
    const n = e.selectedValue;
    return Array.isArray(n) && n.length > 0;
  }),
  hasSelectedValue: C((e) => {
    const { selectedValue: n, selectionMode: r } = e;
    return n == null ? !1 : r === "multiple" && Array.isArray(n) ? n.length > 0 : !0;
  }),
  hasNullItemLabel: C((e, n) => n ? mr(e.items) : !1),
  open: C((e) => e.open),
  mounted: C((e) => e.mounted),
  forceMounted: C((e) => e.forceMounted),
  inline: C((e) => e.inline),
  activeIndex: C((e) => e.activeIndex),
  selectedIndex: C((e) => e.selectedIndex),
  isActive: C((e, n) => e.activeIndex === n),
  isSelected: C((e, n) => {
    const r = e.isItemEqualToValue, d = e.selectedValue;
    return Array.isArray(d) ? d.some((I) => At(n, I, r)) : At(n, d, r);
  }),
  transitionStatus: C((e) => e.transitionStatus),
  popupProps: C((e) => e.popupProps),
  inputProps: C((e) => e.inputProps),
  triggerProps: C((e) => e.triggerProps),
  getItemProps: C((e) => e.getItemProps),
  positionerElement: C((e) => e.positionerElement),
  listElement: C((e) => e.listElement),
  triggerElement: C((e) => e.triggerElement),
  inputElement: C((e) => e.inputElement),
  inputGroupElement: C((e) => e.inputGroupElement),
  popupSide: C((e) => e.popupSide),
  openMethod: C((e) => e.openMethod),
  inputInsidePopup: C((e) => e.inputInsidePopup),
  selectionMode: C((e) => e.selectionMode),
  name: C((e) => e.name),
  form: C((e) => e.form),
  disabled: C((e) => e.disabled),
  readOnly: C((e) => e.readOnly),
  required: C((e) => e.required),
  grid: C((e) => e.grid),
  virtualized: C((e) => e.virtualized),
  itemToStringLabel: C((e) => e.itemToStringLabel),
  isItemEqualToValue: C((e) => e.isItemEqualToValue),
  modal: C((e) => e.modal),
  autoHighlight: C((e) => e.autoHighlight),
  submitOnItemClick: C((e) => e.submitOnItemClick)
};
function br(e, n) {
  return (r, d) => {
    if (r == null) return !1;
    const I = fe(r, n);
    return e.contains(I, d);
  };
}
function vr(e, n, r) {
  return (d, I) => {
    if (d == null) return !1;
    if (!I) return !0;
    const g = fe(d, n), x = r != null ? fe(r, n) : "";
    return x && e.contains(x, I) && x.length === I.length ? !0 : e.contains(g, I);
  };
}
var dn = /* @__PURE__ */ new Map();
function Ir(e = {}) {
  const n = {
    usage: "search",
    sensitivity: "base",
    ignorePunctuation: !0,
    ...e
  }, r = `${On(e.locale)}|${JSON.stringify(n)}`, d = dn.get(r);
  if (d) return d;
  const I = new Intl.Collator(e.locale, n), g = {
    contains(x, m, R) {
      if (!m) return !0;
      const l = fe(x, R);
      for (let f = 0; f <= l.length - m.length; f += 1) if (I.compare(l.slice(f, f + m.length), m) === 0) return !0;
      return !1;
    },
    startsWith(x, m, R) {
      if (!m) return !0;
      const l = fe(x, R);
      return I.compare(l.slice(0, m.length), m) === 0;
    },
    endsWith(x, m, R) {
      if (!m) return !0;
      const l = fe(x, R), f = m.length;
      return l.length >= f && I.compare(l.slice(l.length - f), m) === 0;
    }
  };
  return dn.set(r, g), g;
}
function On(e) {
  return Array.isArray(e) ? e.map((n) => On(n)).join(",") : e == null ? "" : String(e);
}
var jn = Ir, kn = /* @__PURE__ */ Symbol("none"), nt = {
  value: kn,
  index: -1
}, a = co();
function yr(e) {
  const { id: n, onOpenChangeComplete: r, defaultSelectedValue: d = null, selectedValue: I, onSelectedValueChange: g, defaultInputValue: x, inputValue: m, open: R, defaultOpen: l = !1, selectionMode: f = "none", onItemHighlighted: _, name: q, form: B, disabled: y = !1, readOnly: L = !1, required: F = !1, inputRef: h, grid: D = !1, items: t, filteredItems: Q, filter: G, openOnInputClick: H = !0, autoHighlight: U = !1, keepHighlight: N = !1, highlightItemOnHover: w = !0, loopFocus: E = !0, itemToStringLabel: b, itemToStringValue: P, isItemEqualToValue: k = dr, virtualized: ne = !1, inline: le = !1, fillInputOnItemPress: z = !0, modal: ie = !1, limit: V = -1, autoComplete: Re = "list", formAutoComplete: Pe, locale: ae, submitOnItemClick: ue = !1 } = e, { clearErrors: je } = er(), { setDirty: Z, validityData: j, shouldValidateOnChange: W, setFilled: Ee, name: Ve, disabled: _e, setTouched: Le, setFocused: Ue, validationMode: Je, validation: oe } = Jt(), re = Pn({ id: n }), pe = jn({ locale: ae }), [me, K] = o.useState(!1), [v, T] = o.useState(null), X = o.useRef([]), Se = o.useRef([]), Ze = o.useRef(null), u = o.useRef(null), A = o.useRef(null), ce = o.useRef(null), ge = o.useRef(null), Fe = o.useRef(!0), De = o.useRef(!1), se = o.useRef(null), de = o.useRef(null), ve = o.useRef(null), Ie = o.useRef(nt), lt = o.useRef(null), ot = o.useRef([]), en = o.useRef([]), et = _e || y, He = Ve ?? q, ye = f === "multiple", we = f === "single", rt = m !== void 0 || x !== void 0, Ke = t !== void 0, Ot = Q !== void 0;
  let he;
  U === "always" ? he = "always" : he = U ? "input-change" : !1;
  const [S, zn] = Wt({
    controlled: I,
    default: ye ? d ?? Pt : d,
    name: "Combobox",
    state: "selectedValue"
  }), xt = o.useMemo(() => G === null ? () => !0 : G !== void 0 ? G : we && !me ? vr(pe, b, S) : br(pe, b), [
    G,
    we,
    S,
    me,
    pe,
    b
  ]), tn = un(() => rt ? x ?? "" : we ? fe(S, b) : "").current, [Ce, Gn] = Wt({
    controlled: m,
    default: tn,
    name: "Combobox",
    state: "inputValue"
  }), [ee, Un] = Wt({
    controlled: R,
    default: l,
    name: "Combobox",
    state: "open"
  }), qe = pr(t), xe = v ?? (Ce === "" ? "" : String(Ce).trim()), jt = we ? fe(S, b) : "", nn = we && !me && xe !== "" && jt !== "" && jt.length === xe.length && pe.contains(jt, xe), ut = nn ? "" : xe, on = Ke && Ot && nn, st = o.useMemo(() => t ? qe ? t.flatMap((c) => c.items) : t : Pt, [t, qe]), ct = o.useMemo(() => {
    if (Q && !on) return Q;
    if (!t) return Pt;
    if (qe) {
      const p = t, O = [];
      let $ = 0;
      for (const J of p) {
        if (V > -1 && $ >= V) break;
        const be = ut === "" ? J.items : J.items.filter((Kt) => xt(Kt, ut, b));
        if (be.length === 0) continue;
        const Et = V > -1 ? V - $ : 1 / 0, tt = be.slice(0, Et);
        if (tt.length > 0) {
          const Kt = {
            ...J,
            items: tt
          };
          O.push(Kt), $ += tt.length;
        }
      }
      return O;
    }
    if (ut === "") return V > -1 ? st.slice(0, V) : st;
    const c = [];
    for (const p of st) {
      if (V > -1 && c.length >= V) break;
      xt(p, ut, b) && c.push(p);
    }
    return c;
  }, [
    Q,
    on,
    t,
    qe,
    ut,
    V,
    xt,
    b,
    st
  ]), Te = o.useMemo(() => qe ? ct.flatMap((c) => c.items) : ct, [ct, qe]), M = un(() => new Po({
    id: re,
    labelId: void 0,
    selectedValue: S,
    open: ee,
    filter: xt,
    query: xe,
    items: t,
    selectionMode: f,
    listRef: X,
    labelsRef: Se,
    popupRef: Ze,
    emptyRef: ge,
    inputRef: u,
    startDismissRef: A,
    endDismissRef: ce,
    keyboardActiveRef: Fe,
    chipsContainerRef: se,
    clearRef: de,
    valuesRef: ot,
    allValuesRef: en,
    selectionEventRef: ve,
    name: He,
    form: B,
    disabled: et,
    readOnly: L,
    required: F,
    grid: D,
    isGrouped: qe,
    virtualized: ne,
    openOnInputClick: H,
    itemToStringLabel: b,
    isItemEqualToValue: k,
    modal: ie,
    autoHighlight: he,
    submitOnItemClick: ue,
    hasInputValue: rt,
    mounted: !1,
    forceMounted: !1,
    transitionStatus: "idle",
    inline: le,
    activeIndex: null,
    selectedIndex: null,
    popupProps: {},
    inputProps: {},
    triggerProps: {},
    positionerElement: null,
    listElement: null,
    triggerElement: null,
    inputElement: null,
    inputGroupElement: null,
    popupSide: null,
    openMethod: null,
    inputInsidePopup: !0,
    onOpenChangeComplete: r || Be,
    setOpen: Be,
    setInputValue: Be,
    setSelectedValue: Be,
    setIndices: Be,
    onItemHighlighted: Be,
    handleSelection: Be,
    getItemProps: () => po,
    forceMount: Be,
    requestSubmit: Be
  })).current, it = f === "none" ? Ce : S, Kn = o.useMemo(() => f === "none" ? it : Array.isArray(S) ? S.map((c) => mt(c, P)) : mt(S, P), [
    it,
    P,
    f,
    S
  ]), kt = te(_), Nt = te(r), bt = s(M, i.activeIndex), Wn = s(M, i.selectedIndex), vt = s(M, i.positionerElement), rn = s(M, i.listElement), dt = s(M, i.triggerElement), It = s(M, i.inputElement), $n = s(M, i.inputGroupElement), Ae = s(M, i.inline), We = s(M, i.inputInsidePopup), Qn = jo(dt), { mounted: sn, setMounted: Yn, transitionStatus: _t } = go(ee), { openMethod: an, triggerProps: Lt } = Lo(ee), Xn = te(() => Kn);
  Zo(We ? Qn : u, {
    id: re,
    value: it,
    getValue: Xn
  });
  const yt = te(() => {
    t ? Se.current = Te.map((c) => fe(c, b)) : M.set("forceMounted", !0);
  }), Jn = o.useRef(S);
  Oe(() => {
    S !== Jn.current && yt();
  }, [yt, S]);
  const Me = te((c) => {
    M.update(c);
    const p = c.type || "none";
    if (c.activeIndex !== void 0)
      if (c.activeIndex === null)
        Ie.current !== nt && (Ie.current = nt, kt(void 0, pt(p, void 0, { index: -1 })));
      else {
        const O = ot.current[c.activeIndex];
        Ie.current = {
          value: O,
          index: c.activeIndex
        }, kt(O, pt(p, void 0, { index: c.activeIndex }));
      }
  }), ke = te((c, p) => {
    if (De.current = p.reason === Qe, e.onInputValueChange?.(c, p), !p.isCanceled) {
      if (p.reason === "input-change") {
        const O = p.event, $ = O.inputType;
        if (O.type === "compositionend" || $ != null && $ !== "" && $ !== "insertReplacementText") {
          const J = c.trim() !== "";
          J && K(!0), lt.current = { hasQuery: J }, J && he && M.state.activeIndex == null && M.set("activeIndex", 0);
        }
      }
      Gn(c);
    }
  }), ft = te((c, p) => {
    if (ee !== c && (p.reason === "escape-key" && Ke && Te.length === 0 && !M.state.emptyRef.current && p.allowPropagation(), e.onOpenChange?.(c, p), !p.isCanceled && (!c && me && (we ? (Ae || T(xe), xe === "" && K(!1)) : ye && (Ae || We ? Me({ activeIndex: null }) : T(xe), ke("", Y(Qe, p.event)))), Un(c), !c && We && (p.reason === "focus-out" || p.reason === "outside-press") && (Le(!0), Ue(!1), Je === "onBlur")))) {
      const O = f === "none" ? Ce : S;
      oe.commit(O);
    }
  }), Ct = te((c, p) => {
    g?.(c, p), !p.isCanceled && (zn(c), (f === "none" && Ze.current && z || we && !M.state.inputInsidePopup) && ke(fe(c, b), Y(p.reason, p.event)), we && c != null && p.reason !== "input-change" && me && !Ae && T(xe));
  }), Zn = te((c, p) => {
    let O = p;
    if (O === void 0) {
      if (bt === null) return;
      O = ot.current[bt];
    }
    const $ = Tt(c), J = ve.current ?? c;
    ve.current = null;
    const be = Y(Mo, J), Et = $?.closest("a")?.getAttribute("href");
    if (Et) {
      Et.startsWith("#") && ft(!1, be);
      return;
    }
    if (ye) {
      const tt = Array.isArray(S) ? S : [];
      if (Ct(fr(tt, O, M.state.isItemEqualToValue) ? gr(tt, O, M.state.isItemEqualToValue) : [...tt, O], be), !(u.current && u.current.value.trim() !== "")) return;
      M.state.inputInsidePopup ? ke("", Y(Qe, be.event)) : ft(!1, be);
    } else
      Ct(O, be), ft(!1, be);
  }), Ft = te(() => {
    if (!M.state.submitOnItemClick) return;
    const c = oe.inputRef.current?.form ?? M.state.inputElement?.form;
    c && typeof c.requestSubmit == "function" && c.requestSubmit();
  }), Dt = te(() => {
    if (Yn(!1), Nt?.(!1), K(!1), T(null), Me(f === "none" ? {
      activeIndex: null,
      selectedIndex: null
    } : { activeIndex: null }), ye && u.current && u.current.value !== "" && !De.current && ke("", Y(Qe)), we) if (M.state.inputInsidePopup)
      u.current && u.current.value !== "" && ke("", Y(Qe));
    else {
      const c = fe(S, b);
      u.current && u.current.value !== c && ke(c, Y(c === "" ? Qe : Ne));
    }
  }), eo = o.useMemo(() => Ae && vt ? { current: vt.closest('[role="dialog"]') } : Ze, [Ae, vt]);
  vn({
    enabled: !e.actionsRef,
    open: ee,
    ref: eo,
    onComplete() {
      ee || Dt();
    }
  }), o.useImperativeHandle(e.actionsRef, () => ({ unmount: Dt }), [Dt]), Oe(function() {
    if (ee || f === "none") return;
    const p = t ? st : en.current;
    if (ye) {
      const O = Array.isArray(S) ? S : [], $ = O[O.length - 1], J = $t(p, $, k);
      Me({ selectedIndex: J === -1 ? null : J });
    } else {
      const O = $t(p, S, k);
      Me({ selectedIndex: O === -1 ? null : O });
    }
  }, [
    ee,
    S,
    t,
    f,
    st,
    ye,
    k,
    Me
  ]), Oe(() => {
    t && (ot.current = Te, X.current.length = Te.length);
  }, [t, Te]), Oe(() => {
    const c = lt.current;
    if (c && (c.hasQuery ? he && M.set("activeIndex", 0) : he === "always" && M.set("activeIndex", 0), lt.current = null), !ee && !Ae) return;
    const p = Ke || Ot ? Te : ot.current, O = M.state.activeIndex;
    if (O == null) {
      if (he === "always" && p.length > 0) {
        M.set("activeIndex", 0);
        return;
      }
      Ie.current !== nt && (Ie.current = nt, M.state.onItemHighlighted(void 0, pt(Ne, void 0, { index: -1 })));
      return;
    }
    if (O >= p.length) {
      Ie.current !== nt && (Ie.current = nt, M.state.onItemHighlighted(void 0, pt(Ne, void 0, { index: -1 }))), M.set("activeIndex", null);
      return;
    }
    const $ = p[O], J = Ie.current.value, be = J !== kn && At($, J, M.state.isItemEqualToValue);
    (Ie.current.index !== O || !be) && (Ie.current = {
      value: $,
      index: O
    }, M.state.onItemHighlighted($, pt(Ne, void 0, { index: O })));
  }, [
    bt,
    he,
    Ot,
    Ke,
    Te,
    Ae,
    ee,
    M
  ]), Oe(() => {
    if (f === "none") {
      Ee(String(Ce) !== "");
      return;
    }
    Ee(ye ? Array.isArray(S) && S.length > 0 : S != null);
  }, [
    Ee,
    f,
    Ce,
    S,
    ye
  ]), o.useEffect(() => {
    Ke && he && Te.length === 0 && Me({ activeIndex: null });
  }, [
    Ke,
    he,
    Te.length,
    Me
  ]), St(xe, () => {
    !ee || xe === "" || xe === String(tn) || K(!0);
  }), St(S, () => {
    if (f !== "none" && (je(He), Z(S !== j.initialValue), W() ? oe.commit(S) : oe.commit(S, !0), we && !rt && !We)) {
      const c = fe(S, b);
      Ce !== c && ke(c, Y(Ne));
    }
  }), St(Ce, () => {
    f === "none" && (je(He), Z(Ce !== j.initialValue), W() ? oe.commit(Ce) : oe.commit(Ce, !0));
  }), St(t, () => {
    if (!we || rt || We || me) return;
    const c = fe(S, b);
    Ce !== c && ke(c, Y(Ne));
  });
  const Rt = Fo({
    open: Ae ? !0 : ee,
    onOpenChange: ft,
    elements: {
      reference: We ? dt : It,
      floating: vt
    }
  });
  let Ht, qt;
  Ae || (Ht = D ? "grid" : "listbox", qt = ee ? "true" : "false");
  const { getReferenceProps: Bt, getFloatingProps: zt, getItemProps: Gt } = Co([
    o.useMemo(() => {
      const c = It?.tagName === "INPUT", p = It == null || c, O = p || ee, $ = p ? {
        autoComplete: "off",
        spellCheck: "false",
        autoCorrect: "off",
        autoCapitalize: "none"
      } : {};
      return O && ($.role = "combobox", $["aria-expanded"] = qt, $["aria-haspopup"] = Ht, $["aria-controls"] = ee ? rn?.id : void 0, $["aria-autocomplete"] = Re), {
        reference: $,
        floating: { role: "presentation" }
      };
    }, [
      It,
      ee,
      qt,
      Ht,
      rn?.id,
      Re
    ]),
    Rn(Rt, {
      enabled: !L && !et && H,
      event: "mousedown-only",
      toggle: !1,
      touchOpenDelay: We ? 0 : 100,
      reason: wo
    }),
    Ro(Rt, {
      enabled: !L && !et && !Ae,
      outsidePressEvent: {
        mouse: "sloppy",
        touch: "intentional"
      },
      bubbles: Ae ? !0 : void 0,
      outsidePress(c) {
        const p = Tt(c);
        return !ze(dt, p) && !ze(de.current, p) && !ze(se.current, p) && !ze($n, p);
      }
    }),
    Bo(Rt, {
      enabled: !L && !et,
      id: re,
      listRef: X,
      activeIndex: bt,
      selectedIndex: Wn,
      virtual: !0,
      loopFocus: E,
      allowEscape: E && !he,
      focusItemOnOpen: me || f === "none" && !he ? !1 : "auto",
      focusItemOnHover: w,
      resetOnPointerLeave: !N,
      cols: D ? 2 : 1,
      orientation: D ? "horizontal" : void 0,
      disabledIndices: Pt,
      onNavigate(c, p) {
        !p && !ee || _t === "ending" || Me(p ? {
          activeIndex: c,
          type: Fe.current ? "keyboard" : "pointer"
        } : { activeIndex: c });
      }
    })
  ]);
  bo(() => {
    M.update({
      inline: le,
      popupProps: zt(),
      inputProps: Bt(),
      triggerProps: Lt,
      getItemProps: Gt,
      setOpen: ft,
      setInputValue: ke,
      setSelectedValue: Ct,
      setIndices: Me,
      onItemHighlighted: kt,
      handleSelection: Zn,
      forceMount: yt,
      requestSubmit: Ft
    });
  }), Oe(() => {
    M.update({
      id: re,
      selectedValue: S,
      open: ee,
      mounted: sn,
      transitionStatus: _t,
      items: t,
      inline: le,
      popupProps: zt(),
      inputProps: Bt(),
      triggerProps: Lt,
      openMethod: an,
      getItemProps: Gt,
      selectionMode: f,
      name: He,
      form: B,
      disabled: et,
      readOnly: L,
      required: F,
      grid: D,
      isGrouped: qe,
      virtualized: ne,
      onOpenChangeComplete: Nt,
      openOnInputClick: H,
      itemToStringLabel: b,
      modal: ie,
      autoHighlight: he,
      isItemEqualToValue: k,
      submitOnItemClick: ue,
      hasInputValue: rt,
      requestSubmit: Ft
    });
  }, [
    M,
    re,
    S,
    ee,
    sn,
    _t,
    t,
    zt,
    Bt,
    Gt,
    an,
    Lt,
    f,
    He,
    et,
    L,
    F,
    oe,
    D,
    qe,
    ne,
    Nt,
    H,
    b,
    ie,
    k,
    ue,
    rt,
    le,
    Ft,
    he,
    B
  ]);
  const to = bn(h, oe.inputRef), no = o.useMemo(() => ({
    query: xe,
    hasItems: Ke,
    filteredItems: ct,
    flatFilteredItems: Te
  }), [
    xe,
    Ke,
    ct,
    Te
  ]), oo = o.useMemo(() => Array.isArray(it) ? "" : mt(it, P), [it, P]), ro = ye && Array.isArray(S) && S.length > 0, Ut = ye || f === "none" ? void 0 : He, so = o.useMemo(() => !ye || !Array.isArray(S) || !He ? null : S.map((c) => {
    const p = mt(c, P);
    return /* @__PURE__ */ (0, a.jsx)("input", {
      type: "hidden",
      form: B,
      name: He,
      value: p
    }, p);
  }), [
    ye,
    S,
    B,
    He,
    P
  ]), io = /* @__PURE__ */ (0, a.jsxs)(o.Fragment, { children: [
    e.children,
    /* @__PURE__ */ (0, a.jsx)("input", {
      ...oe.getInputValidationProps({
        onFocus() {
          if (We) {
            dt?.focus();
            return;
          }
          (u.current || dt)?.focus();
        },
        onChange(c) {
          if (c.nativeEvent.defaultPrevented) return;
          const p = c.currentTarget.value, O = Y(Ne, c.nativeEvent);
          function $() {
            if (ye) return;
            if (f === "none") {
              Z(p !== j.initialValue), ke(p, O), W() && oe.commit(p);
              return;
            }
            const J = ot.current.find((be) => mt(be, P).toLowerCase() === p.toLowerCase() || fe(be, b).toLowerCase() === p.toLowerCase());
            J != null && (Z(J !== j.initialValue), Ct?.(J, O), W() && oe.commit(J));
          }
          t ? $() : (yt(), queueMicrotask($));
        }
      }),
      id: re && Ut == null ? `${re}-hidden-input` : void 0,
      form: B,
      name: Ut,
      autoComplete: Pe,
      disabled: et,
      required: F && !ro,
      readOnly: L,
      value: oo,
      ref: to,
      style: Ut ? Cn : ko,
      tabIndex: -1,
      "aria-hidden": !0,
      suppressHydrationWarning: !0
    }),
    so
  ] });
  return /* @__PURE__ */ (0, a.jsx)(Sn.Provider, {
    value: M,
    children: /* @__PURE__ */ (0, a.jsx)(wn.Provider, {
      value: Rt,
      children: /* @__PURE__ */ (0, a.jsx)(Tn.Provider, {
        value: no,
        children: /* @__PURE__ */ (0, a.jsx)(An.Provider, {
          value: Ce,
          children: io
        })
      })
    })
  });
}
function Cr(e) {
  const { openOnInputClick: n = !1, value: r, defaultValue: d, onValueChange: I, mode: g = "list", itemToStringValue: x, ...m } = e, R = g === "inline" || g === "both", l = g === "inline" || g === "none", f = r !== void 0, [_, q] = o.useState(d ?? ""), [B, y] = o.useState("");
  o.useEffect(() => {
    f && y("");
  }, [r, f]);
  let L;
  R && B !== "" ? L = B : f ? L = r ?? "" : L = _;
  const F = te((H, U) => {
    y(""), f || q(H), I?.(H, U);
  }), h = jn(), D = o.useMemo(() => m.filter !== void 0 ? m.filter : h.contains, [m.filter, h]), t = String(f ? r : _).trim(), Q = o.useMemo(() => g !== "both" ? l ? null : D : D === null ? null : (H, U, N) => D(H, t, N), [
    D,
    g,
    t,
    l
  ]), G = te((H, U) => {
    e.onItemHighlighted?.(H, U), U.reason !== "pointer" && (R ? H == null ? y("") : y(fe(H, x)) : y(""));
  });
  return /* @__PURE__ */ (0, a.jsx)(yr, {
    ...m,
    itemToStringLabel: x,
    openOnInputClick: n,
    selectionMode: "none",
    fillInputOnItemPress: !0,
    filter: Q,
    autoComplete: g,
    inputValue: L,
    defaultInputValue: d,
    onInputValueChange: F,
    onItemHighlighted: G
  });
}
var Nn = {
  ...yo,
  ...Xo,
  popupSide: (e) => e ? { "data-popup-side": e } : null,
  listEmpty: (e) => e ? { "data-list-empty": "" } : null
}, wt = 2, Rr = /* @__PURE__ */ o.forwardRef(function(n, r) {
  const { render: d, className: I, nativeButton: g = !0, disabled: x = !1, id: m, style: R, ...l } = n, { state: f, disabled: _, setTouched: q, setFocused: B, validationMode: y, validation: L } = Jt(), { labelId: F } = En(), h = Ge(), { filteredItems: D } = Xe(), t = s(h, i.selectionMode), Q = s(h, i.disabled), G = s(h, i.readOnly), H = s(h, i.required), U = s(h, i.mounted), N = s(h, i.popupSide), w = s(h, i.positionerElement), E = s(h, i.listElement), b = s(h, i.triggerProps), P = s(h, i.triggerElement), k = s(h, i.inputInsidePopup), ne = s(h, i.id), le = s(h, i.labelId), z = s(h, i.open), ie = s(h, i.selectedValue), V = s(h, i.activeIndex), Re = s(h, i.selectedIndex), Pe = s(h, i.hasSelectedValue), ae = Mt(), ue = Mn(), je = In(), Z = _ || Q || x, j = D.length === 0, W = U && w ? N : null;
  Pn({ id: k ? m : void 0 });
  const Ee = k ? m ?? ne : m, Ve = Vn(F, le), _e = o.useRef("");
  function Le(K) {
    _e.current = K.pointerType;
  }
  const Ue = ae.useState("domReferenceElement");
  o.useEffect(() => {
    k && P && P !== Ue && ae.set("domReferenceElement", P);
  }, [
    P,
    Ue,
    ae,
    k
  ]);
  const { reference: Je } = zo(ae, {
    enabled: !z && !G && !Q && t === "single",
    listRef: h.state.labelsRef,
    activeIndex: V,
    selectedIndex: Re,
    onMatch(K) {
      const v = h.state.valuesRef.current[K];
      v !== void 0 && h.state.setSelectedValue(v, Y("none"));
    }
  }), { reference: oe } = Rn(ae, {
    enabled: !G && !Q,
    event: "mousedown"
  }), { buttonRef: re, getButtonProps: pe } = Xt({
    native: g,
    disabled: Z
  }), me = {
    ...f,
    open: z,
    disabled: Z,
    popupSide: W,
    listEmpty: j,
    placeholder: t === "none" ? !1 : !Pe
  };
  return Ye("button", n, {
    ref: [
      r,
      re,
      te((K) => {
        h.set("triggerElement", K);
      })
    ],
    state: me,
    props: [
      b,
      oe,
      Je,
      {
        id: Ee,
        tabIndex: k ? 0 : -1,
        role: k ? "combobox" : void 0,
        "aria-expanded": z ? "true" : "false",
        "aria-haspopup": k ? "dialog" : "listbox",
        "aria-controls": z ? E?.id : void 0,
        "aria-required": k && H || void 0,
        "aria-labelledby": Ve,
        onPointerDown: Le,
        onPointerEnter: Le,
        onFocus() {
          B(!0), !(Z || G) && je.start(0, h.state.forceMount);
        },
        onBlur(K) {
          if (!ze(w, K.relatedTarget) && (q(!0), B(!1), y === "onBlur")) {
            const v = t === "none" ? ue : ie;
            L.commit(v);
          }
        },
        onMouseDown(K) {
          if (Z || G || (k || ae.set("domReferenceElement", K.currentTarget), h.state.forceMount(), _e.current !== "touch" && (h.state.inputRef.current?.focus(), k || K.preventDefault()), z)) return;
          const v = Vo(K.currentTarget);
          function T(X) {
            if (!P) return;
            const Se = Tt(X), Ze = h.state.positionerElement, u = h.state.listElement;
            if (ze(P, Se) || ze(Ze, Se) || ze(u, Se) || Se === P) return;
            const A = hr(P), ce = X.clientX >= A.left - wt && X.clientX <= A.right + wt, ge = X.clientY >= A.top - wt && X.clientY <= A.bottom + wt;
            ce && ge || h.state.setOpen(!1, Y("cancel-open", X));
          }
          k && v.addEventListener("mouseup", T, { once: !0 });
        },
        onKeyDown(K) {
          Z || G || (K.key === "ArrowDown" || K.key === "ArrowUp") && (ht(K), h.state.setOpen(!0, Y(To, K.nativeEvent)), h.state.inputRef.current?.focus());
        }
      },
      L ? L.getValidationProps(l) : l,
      pe
    ],
    stateAttributesMapping: Nn
  });
}), fn = Rr, Er = /* @__PURE__ */ o.createContext(void 0);
function Pr() {
  return o.useContext(Er);
}
var _n = /* @__PURE__ */ o.createContext(void 0);
function Zt(e) {
  const n = o.useContext(_n);
  if (n === void 0 && !e) throw new Error(at(21));
  return n;
}
var Ln = /* @__PURE__ */ o.forwardRef(function(n, r) {
  const d = Ge(), { buttonRef: I, getButtonProps: g } = Xt({ native: !1 });
  return /* @__PURE__ */ (0, a.jsx)("span", {
    ref: bn(r, I),
    ...g({ onClick: te((x) => {
      d.state.setOpen(!1, Y(Ao, x.nativeEvent, x.currentTarget));
    }) }),
    "aria-label": "Dismiss",
    tabIndex: void 0,
    style: Cn
  });
}), pn = /* @__PURE__ */ o.forwardRef(function(n, r) {
  const { render: d, className: I, disabled: g = !1, id: x, style: m, ...R } = n, { state: l, disabled: f, setTouched: _, setFocused: q, validationMode: B, validation: y } = Jt(), { labelId: L } = En(), F = Pr(), D = !!Zt(!0), t = Ge(), { filteredItems: Q } = Xe(), G = Mn(), H = So(), U = s(t, i.required), N = s(t, i.disabled), w = s(t, i.readOnly), E = s(t, i.name), b = s(t, i.form), P = s(t, i.selectionMode), k = s(t, i.autoHighlight), ne = s(t, i.inputProps), le = s(t, i.triggerProps), z = s(t, i.open), ie = s(t, i.mounted), V = s(t, i.selectedValue), Re = s(t, i.popupSide), Pe = s(t, i.positionerElement), ae = s(t, i.id), ue = s(t, i.inline), je = s(t, i.modal), Z = !!k, j = ie && Pe ? Re : null, W = f || N || g, Ee = Q.length === 0, Ve = D || ue, _e = !Ve || je, Le = yn(x ?? (Ve ? void 0 : ae)), Ue = Vn(L, void 0), Je = D ? Jo : l, [oe, re] = o.useState(null), pe = o.useRef(!1), me = o.useRef(null), K = o.useRef(!1), v = te((u) => {
    const A = D || t.state.inline;
    A && !t.state.hasInputValue && t.state.setInputValue("", Y(Ne)), t.update({
      inputElement: u,
      inputInsidePopup: A
    });
  }), T = D || !y ? R : y.getValidationProps(R), X = {
    ...Je,
    open: z,
    disabled: W,
    readOnly: w,
    popupSide: j,
    listEmpty: Ee
  };
  function Se(u) {
    if (!F) return;
    let A;
    const { highlightedChipIndex: ce } = F, ge = F.chipsRef.current.length;
    if (ce !== void 0) {
      if (u.key === "ArrowLeft")
        u.preventDefault(), ce > 0 ? A = ce - 1 : A = void 0;
      else if (u.key === "ArrowRight")
        u.preventDefault(), ce < ge - 1 ? A = ce + 1 : A = void 0;
      else if (u.key === "Backspace" || u.key === "Delete") {
        u.preventDefault();
        const Fe = ce >= V.length - 1 ? V.length - 2 : ce;
        A = Fe >= 0 ? Fe : void 0, t.state.setIndices({
          activeIndex: null,
          selectedIndex: null,
          type: "keyboard"
        });
      }
      return A;
    }
    return u.key === "ArrowLeft" && (u.currentTarget.selectionStart ?? 0) === 0 && V.length > 0 ? (u.preventDefault(), A = ge > 0 ? ge - 1 : void 0) : u.key === "Backspace" && u.currentTarget.value === "" && V.length > 0 && (t.state.setIndices({
      activeIndex: null,
      selectedIndex: null,
      type: "keyboard"
    }), u.preventDefault()), A;
  }
  const Ze = Ye("input", n, {
    state: X,
    ref: [
      r,
      t.state.inputRef,
      v
    ],
    props: [
      ne,
      le,
      {
        type: "text",
        value: n.value ?? oe ?? G,
        "aria-readonly": w || void 0,
        "aria-required": U || void 0,
        "aria-labelledby": Ue,
        disabled: W,
        readOnly: w,
        required: P === "none" ? U : void 0,
        form: b,
        ...P === "none" && E && { name: E },
        id: Le,
        onFocus() {
          if (q(!0), !ue || !K.current) return;
          K.current = !1;
          const u = me.current;
          u == null || !Object.hasOwn(t.state.valuesRef.current, u) || t.state.setIndices({ activeIndex: u });
        },
        onBlur() {
          _(!0), q(!1);
          const u = t.state.activeIndex;
          if (ue && u !== null && k !== "always" && (me.current = u, K.current = !0, t.state.setIndices({ activeIndex: null })), B === "onBlur") {
            const A = P === "none" ? G : V;
            y.commit(A);
          }
        },
        onCompositionStart(u) {
          xo || (pe.current = !0, re(u.currentTarget.value));
        },
        onCompositionEnd(u) {
          pe.current = !1;
          const A = u.currentTarget.value;
          re(null), t.state.setInputValue(A, Y(Vt, u.nativeEvent));
        },
        onChange(u) {
          const A = u.nativeEvent.inputType, ce = !A || A === "insertReplacementText", ge = pe.current || !ce;
          if (pe.current) {
            const de = u.currentTarget.value;
            re(de), de === "" && !t.state.openOnInputClick && !t.state.inputInsidePopup && t.state.setOpen(!1, Y(Qe, u.nativeEvent));
            const ve = de.trim(), Ie = Z && ve !== "";
            !w && !W && ve && ge && (t.state.setOpen(!0, Y(Vt, u.nativeEvent)), Z || t.state.setIndices({
              activeIndex: null,
              selectedIndex: null,
              type: t.state.keyboardActiveRef.current ? "keyboard" : "pointer"
            })), z && t.state.activeIndex !== null && !Ie && t.state.setIndices({
              activeIndex: null,
              selectedIndex: null,
              type: t.state.keyboardActiveRef.current ? "keyboard" : "pointer"
            });
            return;
          }
          t.state.setInputValue(u.currentTarget.value, Y(Vt, u.nativeEvent));
          const Fe = u.currentTarget.value === "", De = Y(Qe, u.nativeEvent);
          Fe && !t.state.inputInsidePopup && (P === "single" && t.state.setSelectedValue(null, De), t.state.openOnInputClick || t.state.setOpen(!1, De));
          const se = u.currentTarget.value.trim();
          !w && !W && se && ge && (t.state.setOpen(!0, Y(Vt, u.nativeEvent)), Z || t.state.setIndices({
            activeIndex: null,
            selectedIndex: null,
            type: t.state.keyboardActiveRef.current ? "keyboard" : "pointer"
          })), z && t.state.activeIndex !== null && !Z && t.state.setIndices({
            activeIndex: null,
            selectedIndex: null,
            type: t.state.keyboardActiveRef.current ? "keyboard" : "pointer"
          });
        },
        onKeyDown(u) {
          if (W || w || u.ctrlKey || u.shiftKey || u.altKey || u.metaKey) return;
          t.state.keyboardActiveRef.current = !0;
          const A = u.currentTarget, ce = A.scrollWidth - A.clientWidth, ge = H === "rtl";
          if (u.key === "Home") {
            ht(u);
            const se = cn && ge ? A.value.length : 0;
            A.setSelectionRange(se, se), A.scrollLeft = 0;
            return;
          }
          if (u.key === "End") {
            ht(u);
            const se = cn && ge ? 0 : A.value.length;
            A.setSelectionRange(se, se), A.scrollLeft = ge ? -ce : ce;
            return;
          }
          if (!ie && u.key === "Escape") {
            const se = P === "multiple" && Array.isArray(V) ? V.length === 0 : V === null, de = Y(Oo, u.nativeEvent), ve = P === "multiple" ? [] : null;
            t.state.setInputValue("", de), t.state.setSelectedValue(ve, de), !se && !t.state.inline && !de.isPropagationAllowed && u.stopPropagation();
            return;
          }
          if (F && u.key === "Backspace" && A.value === "" && F.highlightedChipIndex === void 0 && Array.isArray(V) && V.length > 0) {
            const se = F.chipsRef.current.length, de = se > 0 ? se - 1 : V.length - 1, ve = V.filter((Ie, lt) => lt !== de);
            t.state.setIndices({
              activeIndex: null,
              selectedIndex: null,
              type: t.state.keyboardActiveRef.current ? "keyboard" : "pointer"
            }), t.state.setSelectedValue(ve, Y(Ne, u.nativeEvent));
            return;
          }
          const Fe = F?.highlightedChipIndex !== void 0, De = Se(u);
          if (F?.setHighlightedChipIndex(De), De !== void 0 ? F?.chipsRef.current[De]?.focus() : Fe && t.state.inputRef.current?.focus(), u.which !== 229 && u.key === "Enter" && z) {
            const se = t.state.activeIndex, de = u.nativeEvent;
            if (se === null) {
              if (ue) return;
              t.state.setOpen(!1, Y(Ne, de));
              return;
            }
            ht(u);
            const ve = t.state.listRef.current[se];
            ve && (t.state.selectionEventRef.current = de, ve.click(), t.state.selectionEventRef.current = null);
          }
        },
        onPointerMove() {
          t.state.keyboardActiveRef.current = !1;
        },
        onPointerDown() {
          t.state.keyboardActiveRef.current = !1;
        }
      },
      T
    ],
    stateAttributesMapping: Nn
  });
  return /* @__PURE__ */ (0, a.jsxs)(o.Fragment, { children: [z && _e && /* @__PURE__ */ (0, a.jsx)(Ln, { ref: t.state.startDismissRef }), Ze] });
}), Fn = /* @__PURE__ */ o.createContext(null);
function Vr() {
  return o.useContext(Fn);
}
function Sr(e) {
  const { children: n, items: r } = e, d = o.useMemo(() => ({ items: r }), [r]);
  return /* @__PURE__ */ (0, a.jsx)(Fn.Provider, {
    value: d,
    children: n
  });
}
function Qt(e) {
  const { children: n } = e, { filteredItems: r } = Xe(), d = Vr(), I = d ? d.items : r;
  return I ? /* @__PURE__ */ (0, a.jsx)(o.Fragment, { children: I.map(n) }) : null;
}
var wr = /* @__PURE__ */ o.forwardRef(function(n, r) {
  var d;
  const { render: I, className: g, style: x, children: m, ...R } = n, l = Ge(), f = Mt(), _ = !!Zt(!0), { filteredItems: q, hasItems: B } = Xe(), y = s(l, i.selectionMode), L = s(l, i.grid), F = s(l, i.popupProps), h = s(l, i.virtualized), D = y === "multiple", t = q.length === 0, Q = te((E) => {
    l.set("positionerElement", E);
  }), G = te((E) => {
    l.set("listElement", E);
  }), H = o.useMemo(() => typeof m == "function" ? d || (d = /* @__PURE__ */ (0, a.jsx)(Qt, { children: m })) : m, [m]), U = { empty: t }, N = f.useState("floatingId"), w = Ye("div", n, {
    state: U,
    ref: [
      r,
      G,
      _ ? null : Q
    ],
    props: [
      F,
      {
        children: H,
        tabIndex: -1,
        id: N,
        role: L ? "grid" : "listbox",
        "aria-multiselectable": D ? "true" : void 0,
        onKeyDown(E) {
          if (!(l.state.disabled || l.state.readOnly) && E.key === "Enter") {
            const b = l.state.activeIndex;
            if (b == null) return;
            ht(E);
            const P = E.nativeEvent, k = l.state.listRef.current[b];
            k && (l.state.selectionEventRef.current = P, k.click(), l.state.selectionEventRef.current = null);
          }
        },
        onKeyDownCapture() {
          l.state.keyboardActiveRef.current = !0;
        },
        onPointerMoveCapture() {
          l.state.keyboardActiveRef.current = !1;
        }
      },
      R
    ]
  });
  return h ? w : /* @__PURE__ */ (0, a.jsx)(Wo, {
    elementsRef: l.state.listRef,
    labelsRef: B ? void 0 : l.state.labelsRef,
    children: w
  });
}), Tr = "⁠";
function Ar(e) {
  const n = e.ownerDocument.createTreeWalker(e, NodeFilter.SHOW_TEXT);
  let r = null;
  for (; n.nextNode(); ) {
    const d = n.currentNode;
    d.nodeValue !== "" && (r = d);
  }
  return r;
}
function Mr() {
  const e = In(), n = o.useRef(null);
  return o.useEffect(() => {
    if (ho) return;
    const r = n.current;
    if (r == null) return;
    const d = Ar(r);
    if (d == null) return;
    const I = d.nodeValue ?? "", g = `${I}${Tr}`;
    return d.nodeValue = g, e.start(200, () => {
      d.nodeValue === g && (d.nodeValue = I);
    }), () => {
      e.clear(), d.nodeValue === g && (d.nodeValue = I);
    };
  }, [n, e]), n;
}
var Dn = /* @__PURE__ */ o.createContext(void 0);
function Or() {
  const e = o.useContext(Dn);
  if (e === void 0) throw new Error(at(20));
  return e;
}
var jr = /* @__PURE__ */ o.forwardRef(function(n, r) {
  const { keepMounted: d = !1, ...I } = n, g = Ge(), x = s(g, i.mounted), m = s(g, i.forceMounted);
  return x || d || m ? /* @__PURE__ */ (0, a.jsx)(Dn.Provider, {
    value: d,
    children: /* @__PURE__ */ (0, a.jsx)(Io, {
      ref: r,
      ...I
    })
  }) : null;
}), kr = /* @__PURE__ */ o.forwardRef(function(n, r) {
  const { render: d, className: I, anchor: g, positionMethod: x = "absolute", side: m = "bottom", align: R = "center", sideOffset: l = 0, alignOffset: f = 0, collisionBoundary: _ = "clipping-ancestors", collisionPadding: q = 5, arrowPadding: B = 5, sticky: y = !1, disableAnchorTracking: L = !1, collisionAvoidance: F = vo, style: h, ...D } = n, t = Ge(), { filteredItems: Q } = Xe(), G = Mt(), H = Or(), U = s(t, i.modal), N = s(t, i.open), w = s(t, i.mounted), E = s(t, i.openMethod), b = s(t, i.positionerElement), P = s(t, i.triggerElement), k = s(t, i.inputElement), ne = s(t, i.inputGroupElement), le = s(t, i.inputInsidePopup), z = s(t, i.transitionStatus), ie = Q.length === 0, V = Ho({
    anchor: g ?? (le ? P : ne ?? k),
    floatingRootContext: G,
    positionMethod: x,
    mounted: w,
    side: m,
    sideOffset: l,
    align: R,
    alignOffset: f,
    arrowPadding: B,
    collisionBoundary: _,
    collisionPadding: q,
    sticky: y,
    disableAnchorTracking: L,
    keepMounted: H,
    collisionAvoidance: F,
    lazyFlip: !0
  });
  xr(N && U, E === "touch", b, P);
  const Re = {
    open: N,
    side: V.side,
    align: V.align,
    anchorHidden: V.anchorHidden,
    empty: ie
  };
  Oe(() => {
    t.set("popupSide", V.side);
  }, [t, V.side]);
  const Pe = te((ue) => {
    t.set("positionerElement", ue);
  }), ae = qo(n, Re, {
    styles: V.positionerStyles,
    transitionStatus: z,
    props: D,
    refs: [r, Pe],
    hidden: !w,
    inert: !N
  });
  return /* @__PURE__ */ (0, a.jsxs)(_n.Provider, {
    value: V,
    children: [w && U && /* @__PURE__ */ (0, a.jsx)(_o, {
      inert: Go(!N),
      cutout: ne ?? k ?? P
    }), ae]
  });
}), Nr = {
  ...Eo,
  ...mo
}, _r = /* @__PURE__ */ o.forwardRef(function(n, r) {
  const { render: d, className: I, style: g, initialFocus: x, finalFocus: m, ...R } = n, l = Ge(), f = Zt(), _ = Mt(), { filteredItems: q } = Xe(), B = s(l, i.mounted), y = s(l, i.open), L = s(l, i.openMethod), F = s(l, i.transitionStatus), h = s(l, i.inputInsidePopup), D = s(l, i.inputElement), t = s(l, i.modal), Q = q.length === 0;
  vn({
    open: y,
    ref: l.state.popupRef,
    onComplete() {
      y && l.state.onOpenChangeComplete(!0);
    }
  });
  const G = Ye("div", n, {
    state: {
      open: y,
      side: f.side,
      align: f.align,
      anchorHidden: f.anchorHidden,
      transitionStatus: F,
      empty: Q
    },
    ref: [r, l.state.popupRef],
    props: [
      {
        role: h ? "dialog" : "presentation",
        tabIndex: -1,
        onFocus(w) {
          const E = Tt(w.nativeEvent);
          L !== "touch" && (ze(l.state.listElement, E) || E === w.currentTarget) && l.state.inputRef.current?.focus();
        }
      },
      Do(F),
      R
    ],
    stateAttributesMapping: Nr
  }), H = x === void 0 ? h ? (w) => w === "touch" ? l.state.popupRef.current : D : !1 : x;
  let U;
  m != null ? U = m : U = h ? void 0 : !1;
  const N = !h || t;
  return /* @__PURE__ */ (0, a.jsx)(No, {
    context: _,
    disabled: !B,
    modal: N,
    openInteractionType: L,
    initialFocus: H,
    returnFocus: U,
    getInsideElements: () => [l.state.startDismissRef.current, l.state.endDismissRef.current],
    children: /* @__PURE__ */ (0, a.jsxs)(o.Fragment, { children: [G, N && /* @__PURE__ */ (0, a.jsx)(Ln, { ref: l.state.endDismissRef })] })
  });
}), Hn = /* @__PURE__ */ o.createContext(void 0);
function Lr() {
  const e = o.useContext(Hn);
  if (e === void 0) throw new Error(at(18));
  return e;
}
var Fr = /* @__PURE__ */ o.forwardRef(function(n, r) {
  const { render: d, className: I, style: g, items: x, ...m } = n, [R, l] = o.useState(), f = o.useMemo(() => ({
    labelId: R,
    setLabelId: l,
    items: x
  }), [
    R,
    l,
    x
  ]), _ = Ye("div", n, {
    ref: r,
    props: [{
      role: "group",
      "aria-labelledby": R
    }, m]
  }), q = /* @__PURE__ */ (0, a.jsx)(Hn.Provider, {
    value: f,
    children: _
  });
  return x ? /* @__PURE__ */ (0, a.jsx)(Sr, {
    items: x,
    children: q
  }) : q;
}), Dr = /* @__PURE__ */ o.forwardRef(function(n, r) {
  const { render: d, className: I, style: g, id: x, ...m } = n, { setLabelId: R } = Lr(), l = yn(x);
  return Oe(() => (R(l), () => {
    R(void 0);
  }), [l, R]), Ye("div", n, {
    ref: r,
    props: [{ id: l }, m]
  });
}), Hr = /* @__PURE__ */ o.createContext(void 0), qr = /* @__PURE__ */ o.createContext(!1);
function Br() {
  return o.useContext(qr);
}
var zr = /* @__PURE__ */ xn(uo()), Gr = /* @__PURE__ */ o.memo(/* @__PURE__ */ o.forwardRef(function(n, r) {
  const { render: d, className: I, value: g = null, index: x, disabled: m = !1, nativeButton: R = !1, style: l, ...f } = n, _ = o.useRef(!1), q = o.useRef(null), B = Uo({
    index: x,
    textRef: q,
    indexGuessBehavior: Ko.GuessFromOrder
  }), y = Ge(), L = Br(), { flatFilteredItems: F, hasItems: h } = Xe(), D = s(y, i.open), t = s(y, i.selectionMode), Q = s(y, i.readOnly), G = s(y, i.virtualized), H = s(y, i.isItemEqualToValue), U = t !== "none", N = x ?? (G ? $t(F, g, H) : B.index), w = B.index !== -1, E = s(y, i.id), b = s(y, i.isActive, N), P = s(y, i.isSelected, g), k = s(y, i.getItemProps), ne = o.useRef(null), le = E != null && w ? `${E}-${N}` : void 0, z = P && U;
  Oe(() => {
    if (!(w && (G || x != null))) return;
    const j = y.state.listRef.current;
    return j[N] = ne.current, () => {
      delete j[N];
    };
  }, [
    w,
    G,
    N,
    x,
    y
  ]), Oe(() => {
    if (!w || h) return;
    const j = y.state.valuesRef.current;
    return j[N] = g, t !== "none" && y.state.allValuesRef.current.push(g), () => {
      delete j[N];
    };
  }, [
    w,
    h,
    N,
    g,
    y,
    t
  ]), Oe(() => {
    if (!D) {
      _.current = !1;
      return;
    }
    if (!w || h) return;
    const j = y.state.selectedValue;
    At(g, Array.isArray(j) ? j[j.length - 1] : j, H) && y.set("selectedIndex", N);
  }, [
    w,
    h,
    D,
    y,
    N,
    g,
    H
  ]);
  const ie = {
    disabled: m,
    selected: z,
    highlighted: b
  }, V = k({
    active: b,
    selected: z
  });
  V.id = void 0, V.onFocus = void 0;
  const { getButtonProps: Re, buttonRef: Pe } = Xt({
    disabled: m,
    focusableWhenDisabled: !0,
    native: R,
    composite: !0
  });
  function ae(j) {
    function W() {
      y.state.handleSelection(j, g);
    }
    y.state.submitOnItemClick ? (zr.flushSync(W), y.state.requestSubmit()) : W();
  }
  const ue = {
    id: le,
    role: L ? "gridcell" : "option",
    "aria-selected": U ? z : void 0,
    tabIndex: void 0,
    onPointerDownCapture(j) {
      _.current = !0, j.preventDefault();
    },
    onMouseDown(j) {
      j.preventDefault();
    },
    onClick(j) {
      m || Q || ae(j.nativeEvent);
    },
    onMouseUp(j) {
      const W = _.current;
      _.current = !1, !(m || Q || j.button !== 0 || W || !b) && ae(j.nativeEvent);
    }
  }, je = Ye("div", n, {
    ref: [
      Pe,
      r,
      B.ref,
      ne
    ],
    state: ie,
    props: [
      V,
      ue,
      f,
      Re
    ]
  }), Z = o.useMemo(() => ({
    selected: z,
    textRef: q
  }), [z, q]);
  return /* @__PURE__ */ (0, a.jsx)(Hr.Provider, {
    value: Z,
    children: je
  });
})), Ur = Gr, Kr = /* @__PURE__ */ o.forwardRef(function(n, r) {
  const { render: d, className: I, style: g, children: x, ...m } = n, { filteredItems: R } = Xe(), l = Ge(), f = Mr(), _ = R.length === 0 ? x : null;
  return Ye("div", n, {
    ref: [
      r,
      l.state.emptyRef,
      f
    ],
    props: [{
      children: _,
      role: "status",
      "aria-live": "polite",
      "aria-atomic": !0
    }, m]
  });
}), mn = {
  sm: "h-8 px-2.5 text-sm",
  md: "h-10 px-3.5 text-base md:text-sm",
  lg: "h-11 px-4 text-base"
}, Wr = {
  sm: "sm",
  md: "sm",
  lg: "md"
};
function Yt({ placeholder: e = "Search...", items: n = [], groups: r, value: d, defaultValue: I, onValueChange: g, onSelect: x, disabled: m = !1, destructive: R = !1, startIcon: l, endIcon: f, showArrow: _ = !0, showCheck: q = !0, filterFn: B, mode: y = "list", autoHighlight: L = !1, open: F, defaultOpen: h, onOpenChange: D, className: t, inputClassName: Q, popupClassName: G, emptyText: H = "No results found", name: U, required: N, size: w = "md", multiple: E = !1, selectedItems: b = [], onSelectedItemsChange: P, renderSelectedItem: k, allowCreate: ne = !1, createItem: le, maxItems: z, preventDuplicates: ie = !0, backspaceRemovesLast: V = !0, "aria-label": Re, "aria-labelledby": Pe, "aria-describedby": ae, "aria-invalid": ue, "aria-required": je }) {
  const [Z, j] = o.useState(I ?? ""), W = d !== void 0 ? d : Z, Ee = !!l, Ve = !!f || _, _e = E && b.length > 0, Le = {
    "aria-label": Re,
    "aria-labelledby": Pe,
    "aria-describedby": ae,
    "aria-invalid": ue,
    "aria-required": je
  }, Ue = o.useMemo(() => {
    if (B)
      return { filter: (v, T) => B(v, T) };
  }, [B]), Je = o.useCallback((v, T) => {
    if (E && T?.reason === "item-press") {
      j(""), g?.("");
      return;
    }
    j(v), g?.(v);
  }, [E, g]), oe = o.useCallback((v) => {
    if (E) {
      if (z !== void 0 && b.length >= z) return;
      const T = b.some((X) => X.id === v.id);
      if (ie && T) return;
      T || P?.([...b, v]);
    }
    x?.(v);
  }, [
    E,
    z,
    b,
    ie,
    P,
    x
  ]), re = o.useCallback((v) => {
    P?.(b.filter((T) => T.id !== v.id));
  }, [b, P]), pe = o.useCallback((v) => {
    if (!E || !ne || !v.trim() || z !== void 0 && b.length >= z) return;
    const T = v.trim();
    if (ie && b.some((Se) => Se.label.toLowerCase() === T.toLowerCase()))
      return;
    const X = le ? le(T) : {
      id: T.toLowerCase().replace(/\s+/g, "-"),
      label: T
    };
    P?.([...b, X]), g?.("");
  }, [
    E,
    ne,
    z,
    ie,
    b,
    le,
    P,
    g
  ]), me = o.useCallback((v) => {
    if (v.key === "Enter" && ne && W?.trim() && (n.some((T) => T.label.toLowerCase().includes(W.toLowerCase())) || r?.some((T) => T.items.some((X) => X.label.toLowerCase().includes(W.toLowerCase()))) || (v.preventDefault(), pe(W))), v.key === "Backspace" && E && V && !W && b.length > 0) {
      const T = b[b.length - 1];
      T && re(T);
    }
  }, [
    ne,
    W,
    n,
    r,
    pe,
    E,
    V,
    b,
    re
  ]), K = r ? r.map((v) => ({ items: v.items })) : n;
  return /* @__PURE__ */ (0, a.jsxs)(Cr, {
    items: K,
    value: W,
    onValueChange: Je,
    mode: y,
    autoHighlight: L,
    highlightItemOnHover: !0,
    open: F,
    defaultOpen: h,
    onOpenChange: D,
    disabled: m,
    name: U,
    itemToStringValue: (v) => v?.label ?? "",
    ...Ue,
    children: [/* @__PURE__ */ (0, a.jsx)("div", {
      className: $e("relative w-full", E && "rounded-md border border-input bg-transparent shadow-xs transition-[color,box-shadow] focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50", E && R && "border-destructive ring-[3px] ring-destructive/20 focus-within:border-destructive focus-within:ring-destructive/20", E && m && "opacity-50 cursor-not-allowed", t),
      children: E ? /* @__PURE__ */ (0, a.jsxs)("div", {
        className: "flex flex-col w-full",
        children: [/* @__PURE__ */ (0, a.jsxs)("div", {
          className: "relative flex items-center w-full",
          children: [
            Ee && /* @__PURE__ */ (0, a.jsx)("span", {
              className: "absolute start-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none [&>svg]:size-5",
              children: l
            }),
            /* @__PURE__ */ (0, a.jsx)(pn, {
              placeholder: _e ? "" : e,
              required: N,
              onKeyDown: me,
              ...Le,
              className: $e("flex-1 bg-transparent py-1 outline-none", "placeholder:text-muted-foreground", "disabled:pointer-events-none disabled:cursor-not-allowed", Ee && "ps-10", Ve && "pe-10", mn[w], "border-none shadow-none focus:ring-0", Q)
            }),
            Ve && /* @__PURE__ */ (0, a.jsxs)("span", {
              className: "absolute end-3 top-1/2 -translate-y-1/2 flex items-center gap-1",
              children: [f && /* @__PURE__ */ (0, a.jsx)("span", {
                className: "text-muted-foreground pointer-events-none [&>svg]:size-5",
                children: f
              }), _ && /* @__PURE__ */ (0, a.jsx)(fn, {
                "aria-label": "Toggle suggestions",
                className: $e("text-muted-foreground", "hover:text-foreground transition-colors", "disabled:opacity-50 disabled:cursor-not-allowed"),
                children: /* @__PURE__ */ (0, a.jsx)(ln, { className: "size-4 transition-transform duration-200 motion-reduce:transition-none [[data-popup-open]>&]:rotate-180" })
              })]
            })
          ]
        }), _e && /* @__PURE__ */ (0, a.jsx)("div", {
          className: "flex flex-wrap gap-1.5 px-3 pb-2.5",
          children: b.map((v) => k ? /* @__PURE__ */ (0, a.jsx)(o.Fragment, { children: k(v, () => re(v)) }, v.id) : /* @__PURE__ */ (0, a.jsx)(cr, {
            size: Wr[w],
            avatar: v.avatar,
            icon: v.icon,
            removable: !m,
            onRemove: () => re(v),
            children: v.label
          }, v.id))
        })]
      }) : /* @__PURE__ */ (0, a.jsxs)(a.Fragment, { children: [
        Ee && /* @__PURE__ */ (0, a.jsx)("span", {
          className: "absolute start-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none [&>svg]:size-5",
          children: l
        }),
        /* @__PURE__ */ (0, a.jsx)(pn, {
          placeholder: e,
          required: N,
          ...Le,
          className: $e("w-full rounded-md border bg-transparent py-1 shadow-xs transition-[color,box-shadow] outline-none", "border-input focus:border-ring focus:ring-[3px] focus:ring-ring/50", "placeholder:text-muted-foreground", "disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50", R && "border-destructive ring-[3px] ring-destructive/20 focus:border-destructive focus:ring-destructive/20", Ee && "ps-10", Ve && "pe-10", mn[w], Q)
        }),
        Ve && /* @__PURE__ */ (0, a.jsxs)("span", {
          className: "absolute end-3 top-1/2 -translate-y-1/2 flex items-center gap-1",
          children: [f && /* @__PURE__ */ (0, a.jsx)("span", {
            className: "text-muted-foreground pointer-events-none [&>svg]:size-5",
            children: f
          }), _ && /* @__PURE__ */ (0, a.jsx)(fn, {
            "aria-label": "Toggle suggestions",
            className: $e("text-muted-foreground", "hover:text-foreground transition-colors", "disabled:opacity-50 disabled:cursor-not-allowed"),
            children: /* @__PURE__ */ (0, a.jsx)(ln, { className: "size-4 transition-transform duration-200 motion-reduce:transition-none [[data-popup-open]>&]:rotate-180" })
          })]
        })
      ] })
    }), /* @__PURE__ */ (0, a.jsx)(jr, { children: /* @__PURE__ */ (0, a.jsx)(kr, {
      sideOffset: 4,
      className: "z-50",
      children: /* @__PURE__ */ (0, a.jsx)(_r, {
        className: $e("w-[var(--anchor-width)] max-h-[300px] overflow-auto rounded-md border bg-popover p-1 shadow-lg", "origin-[var(--transform-origin)]", "transition-[transform,opacity] duration-150 motion-reduce:transition-none", "data-[ending-style]:scale-95 data-[ending-style]:opacity-0", "data-[starting-style]:scale-95 data-[starting-style]:opacity-0", G),
        children: /* @__PURE__ */ (0, a.jsxs)(wr, { children: [r ? r.map((v) => /* @__PURE__ */ (0, a.jsxs)(Fr, {
          items: v.items,
          children: [/* @__PURE__ */ (0, a.jsx)(Dr, {
            className: "px-2 py-1.5 text-xs font-semibold text-muted-foreground",
            children: v.label
          }), /* @__PURE__ */ (0, a.jsx)(Qt, { children: (T) => /* @__PURE__ */ (0, a.jsx)(gn, {
            item: T,
            showCheck: q,
            onSelect: oe,
            isSelected: E && b.some((X) => X.id === T.id)
          }, T.id) })]
        }, v.label)) : /* @__PURE__ */ (0, a.jsx)(Qt, { children: (v) => /* @__PURE__ */ (0, a.jsx)(gn, {
          item: v,
          showCheck: q,
          onSelect: oe,
          isSelected: E && b.some((T) => T.id === v.id)
        }, v.id) }), /* @__PURE__ */ (0, a.jsx)(Kr, {
          className: "px-2 py-6 text-center text-sm text-muted-foreground animate-in fade-in-0 duration-200 motion-reduce:animate-none",
          children: H
        })] })
      })
    }) })]
  });
}
function gn({ item: e, showCheck: n, onSelect: r, isSelected: d }) {
  return /* @__PURE__ */ (0, a.jsxs)(Ur, {
    value: e,
    disabled: e.disabled,
    onClick: () => r?.(e),
    className: $e("group relative flex items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none cursor-default select-none transition-colors duration-100 motion-reduce:transition-none", "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground", "data-[disabled]:opacity-50 data-[disabled]:pointer-events-none", n && "ps-8", d && "bg-accent/50 transition-colors duration-150 motion-reduce:transition-none"),
    children: [n && /* @__PURE__ */ (0, a.jsx)("span", {
      className: "absolute start-2 flex size-4 items-center justify-center",
      children: /* @__PURE__ */ (0, a.jsx)(fo, { className: $e("size-4 transition-opacity duration-150 motion-reduce:transition-none", d ? "opacity-100" : "opacity-0 group-data-[highlighted]:opacity-100") })
    }), /* @__PURE__ */ (0, a.jsx)("span", {
      className: "truncate",
      children: e.label
    })]
  });
}
Yt.displayName = "AutocompleteControl";
function qn(e) {
  const [n, r] = Qo(e);
  if (!Yo(n)) return /* @__PURE__ */ (0, a.jsx)(Yt, {
    ...r,
    required: n.required
  });
  const { label: d, error: I, description: g, tooltip: x, labelIcon: m, topRight: R, bottomRight: l, fieldClassName: f } = n, _ = r;
  return /* @__PURE__ */ (0, a.jsxs)(ur, {
    state: I ? "destructive" : void 0,
    className: f,
    children: [
      (d || R) && /* @__PURE__ */ (0, a.jsxs)(nr, { children: [d && /* @__PURE__ */ (0, a.jsxs)(lr, {
        required: n.required,
        labelIcon: m,
        children: [d, x && /* @__PURE__ */ (0, a.jsx)($o, { content: x })]
      }), R && /* @__PURE__ */ (0, a.jsx)(rr, { children: R })] }),
      /* @__PURE__ */ (0, a.jsx)(or, { children: (q) => /* @__PURE__ */ (0, a.jsx)(Yt, {
        ..._,
        "aria-describedby": q["aria-describedby"],
        "aria-invalid": q["aria-invalid"],
        "aria-required": q["aria-required"],
        "aria-label": typeof d == "string" ? d : void 0,
        required: n.required,
        destructive: !!I || _.destructive
      }) }),
      (I || g || l) && /* @__PURE__ */ (0, a.jsxs)(sr, { children: [
        I && /* @__PURE__ */ (0, a.jsx)(ir, { children: I }),
        !I && g && /* @__PURE__ */ (0, a.jsx)(tr, { children: g }),
        l && /* @__PURE__ */ (0, a.jsx)(ar, {
          className: "ms-auto",
          children: l
        })
      ] })
    ]
  });
}
qn.displayName = "Autocomplete";
var $r = lo(), gt = {};
function hn(e, n) {
  if (e !== null)
    switch (n) {
      case "number":
        return Number(e);
      case "boolean":
        return e !== "false" && e !== "0";
      case "json":
        try {
          return JSON.parse(e);
        } catch {
          return e;
        }
      default:
        return e;
    }
}
var Bn = class extends HTMLElement {
  _root = null;
  _childrenContainer = null;
  _props = {};
  _initialized = !1;
  connectedCallback() {
    setTimeout(() => this._initialize(), 0);
  }
  _initialize() {
    if (this._initialized) return;
    this._initialized = !0;
    const e = [];
    for (const r of Array.from(this.childNodes))
      r.nodeType === Node.TEXT_NODE && !r.textContent?.trim() || e.push(r);
    const n = document.createElement("div");
    for (n.style.display = "contents", this._childrenContainer = document.createElement("div"), this._childrenContainer.style.display = "contents", e.forEach((r) => this._childrenContainer.appendChild(r)); this.firstChild; ) this.removeChild(this.firstChild);
    this.appendChild(n), this._root = (0, $r.createRoot)(n), this._render();
  }
  disconnectedCallback() {
    this._root?.unmount(), this._root = null;
  }
  attributeChangedCallback(e, n, r) {
    this._render();
  }
  static get observedAttributes() {
    return Object.keys(gt).map((e) => e.replace(/([A-Z])/g, "-$1").toLowerCase());
  }
  _setProp(e, n) {
    const r = gt[e] || "string";
    this._props[e] = this._parseValue(n, r), this._render();
  }
  _parseValue(e, n) {
    if (n === "boolean" && typeof e == "boolean" || n === "number" && typeof e == "number" || n === "string" && typeof e == "string") return e;
    if (typeof e == "string") switch (n) {
      case "boolean":
        return e !== "false" && e !== "0" && e !== "";
      case "number":
        return Number(e);
      case "json":
        try {
          return JSON.parse(e);
        } catch {
          return e;
        }
      default:
        return e;
    }
    return e;
  }
  _getProp(e) {
    if (e in this._props) return this._props[e];
    const n = e.replace(/([A-Z])/g, "-$1").toLowerCase(), r = gt[e] || "string";
    return hn(this.getAttribute(n), r);
  }
  _render() {
    if (!this._root) return;
    const e = {};
    for (const [r, d] of Object.entries(gt)) if (r in this._props) e[r] = this._props[r];
    else {
      const I = r.replace(/([A-Z])/g, "-$1").toLowerCase();
      e[r] = hn(this.getAttribute(I), d);
    }
    const n = o.createElement(qn, {
      ...e,
      _hostElement: this
    });
    this._root.render(n);
  }
};
for (const e of Object.keys(gt)) Object.defineProperty(Bn.prototype, e, {
  get() {
    return this._getProp(e);
  },
  set(n) {
    this._setProp(e, n);
  },
  enumerable: !0,
  configurable: !0
});
typeof customElements < "u" && !customElements.get("hf-autocomplete") && customElements.define("hf-autocomplete", Bn);
export {
  Bn as AutocompleteWC,
  Bn as default
};

//# sourceMappingURL=hf-autocomplete.js.map