import { useFocusRing as $e } from "../../../../../../../@react-aria_focus@3.21.4_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@react-aria/focus/dist/useFocusRing.js";
import { useHover as Pe } from "../../../../../../../@react-aria_interactions@3.27.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@react-aria/interactions/dist/useHover.js";
import { useVirtualizer as Ne } from "../../../../../../../@tanstack_react-virtual@3.13.18_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@tanstack/react-virtual/dist/esm/index.js";
import A, { useId as pe, useState as De, useCallback as be, useMemo as j, createContext as fe, useRef as te, useContext as ve, useReducer as Ke, createRef as Ue, Fragment as we } from "react";
import { flushSync as Z } from "react-dom";
import { useActivePress as ze } from "../../hooks/use-active-press.js";
import { useByComparator as He } from "../../hooks/use-by-comparator.js";
import { useControllable as Ge } from "../../hooks/use-controllable.js";
import { useDefaultValue as je } from "../../hooks/use-default-value.js";
import { useDisposables as qe } from "../../hooks/use-disposables.js";
import { useElementSize as Ie } from "../../hooks/use-element-size.js";
import { useEvent as v } from "../../hooks/use-event.js";
import { useInertOthers as Je } from "../../hooks/use-inert-others.js";
import { useIsoMorphicEffect as Q } from "../../hooks/use-iso-morphic-effect.js";
import { useLatestValue as Qe } from "../../hooks/use-latest-value.js";
import { useOnDisappear as We } from "../../hooks/use-on-disappear.js";
import { useOutsideClick as Xe } from "../../hooks/use-outside-click.js";
import { useOwnerDocument as Fe } from "../../hooks/use-owner.js";
import { useRefocusableInput as _e } from "../../hooks/use-refocusable-input.js";
import { useResolveButtonType as Ye } from "../../hooks/use-resolve-button-type.js";
import { useScrollLock as Ze } from "../../hooks/use-scroll-lock.js";
import { useSyncRefs as ce } from "../../hooks/use-sync-refs.js";
import { useTrackedPointer as et } from "../../hooks/use-tracked-pointer.js";
import { useTransition as tt, transitionDataAttributes as ot } from "../../hooks/use-transition.js";
import { useTreeWalker as nt } from "../../hooks/use-tree-walker.js";
import { useWatch as Se } from "../../hooks/use-watch.js";
import { useDisabled as it } from "../../internal/disabled.js";
import { useResolvedAnchor as rt, useFloatingPanel as at, useFloatingPanelProps as lt, FloatingProvider as st, useFloatingReference as ut } from "../../internal/floating.js";
import { FormFields as dt } from "../../internal/form-fields.js";
import { useFrozenData as ye, Frozen as pt } from "../../internal/frozen.js";
import { useProvidedId as ct } from "../../internal/id.js";
import { useOpenClosed as mt, State as de, OpenClosedProvider as bt } from "../../internal/open-closed.js";
import { history as Ce } from "../../utils/active-element-history.js";
import { isDisabledReactIssue7711 as ft } from "../../utils/bugs.js";
import { Focus as R, calculateActiveIndex as Te } from "../../utils/calculate-active-index.js";
import { disposables as he } from "../../utils/disposables.js";
import { sortByDomNode as vt } from "../../utils/focus-management.js";
import { match as ee } from "../../utils/match.js";
import { isMobile as xt } from "../../utils/platform.js";
import { forwardRefWithAs as ae, mergeProps as xe, useRender as le, RenderFeatures as Re } from "../../utils/render.js";
import { useDescribedBy as gt } from "../description/description.js";
import { Keys as M } from "../keyboard.js";
import { Label as Ot, useLabelledBy as ge, useLabels as Et } from "../label/label.js";
import { MouseButton as Ae } from "../mouse.js";
import { Portal as It } from "../portal/portal.js";
var St = ((e) => (e[e.Open = 0] = "Open", e[e.Closed = 1] = "Closed", e))(St || {}), yt = ((e) => (e[e.Single = 0] = "Single", e[e.Multi = 1] = "Multi", e))(yt || {}), Ct = ((e) => (e[e.Pointer = 0] = "Pointer", e[e.Focus = 1] = "Focus", e[e.Other = 2] = "Other", e))(Ct || {}), Tt = ((e) => (e[e.OpenCombobox = 0] = "OpenCombobox", e[e.CloseCombobox = 1] = "CloseCombobox", e[e.GoToOption = 2] = "GoToOption", e[e.SetTyping = 3] = "SetTyping", e[e.RegisterOption = 4] = "RegisterOption", e[e.UnregisterOption = 5] = "UnregisterOption", e[e.SetActivationTrigger = 6] = "SetActivationTrigger", e[e.UpdateVirtualConfiguration = 7] = "UpdateVirtualConfiguration", e[e.SetInputElement = 8] = "SetInputElement", e[e.SetButtonElement = 9] = "SetButtonElement", e[e.SetOptionsElement = 10] = "SetOptionsElement", e))(Tt || {});
function me(e, o = (a) => a) {
  let a = e.activeOptionIndex !== null ? e.options[e.activeOptionIndex] : null, r = o(e.options.slice()), u = r.length > 0 && r[0].dataRef.current.order !== null ? r.sort((i, t) => i.dataRef.current.order - t.dataRef.current.order) : vt(r, (i) => i.dataRef.current.domRef.current), b = a ? u.indexOf(a) : null;
  return b === -1 && (b = null), { options: u, activeOptionIndex: b };
}
let ht = { 1(e) {
  var o;
  return (o = e.dataRef.current) != null && o.disabled || e.comboboxState === 1 ? e : { ...e, activeOptionIndex: null, comboboxState: 1, isTyping: !1, activationTrigger: 2, __demoMode: !1 };
}, 0(e) {
  var o, a;
  if ((o = e.dataRef.current) != null && o.disabled || e.comboboxState === 0) return e;
  if ((a = e.dataRef.current) != null && a.value) {
    let r = e.dataRef.current.calculateIndex(e.dataRef.current.value);
    if (r !== -1) return { ...e, activeOptionIndex: r, comboboxState: 0, __demoMode: !1 };
  }
  return { ...e, comboboxState: 0, __demoMode: !1 };
}, 3(e, o) {
  return e.isTyping === o.isTyping ? e : { ...e, isTyping: o.isTyping };
}, 2(e, o) {
  var a, r, u, b;
  if ((a = e.dataRef.current) != null && a.disabled || e.optionsElement && !((r = e.dataRef.current) != null && r.optionsPropsRef.current.static) && e.comboboxState === 1) return e;
  if (e.virtual) {
    let { options: d, disabled: x } = e.virtual, g = o.focus === R.Specific ? o.idx : Te(o, { resolveItems: () => d, resolveActiveIndex: () => {
      var n, y;
      return (y = (n = e.activeOptionIndex) != null ? n : d.findIndex((O) => !x(O))) != null ? y : null;
    }, resolveDisabled: x, resolveId() {
      throw new Error("Function not implemented.");
    } }), I = (u = o.trigger) != null ? u : 2;
    return e.activeOptionIndex === g && e.activationTrigger === I ? e : { ...e, activeOptionIndex: g, activationTrigger: I, isTyping: !1, __demoMode: !1 };
  }
  let i = me(e);
  if (i.activeOptionIndex === null) {
    let d = i.options.findIndex((x) => !x.dataRef.current.disabled);
    d !== -1 && (i.activeOptionIndex = d);
  }
  let t = o.focus === R.Specific ? o.idx : Te(o, { resolveItems: () => i.options, resolveActiveIndex: () => i.activeOptionIndex, resolveId: (d) => d.id, resolveDisabled: (d) => d.dataRef.current.disabled }), l = (b = o.trigger) != null ? b : 2;
  return e.activeOptionIndex === t && e.activationTrigger === l ? e : { ...e, ...i, isTyping: !1, activeOptionIndex: t, activationTrigger: l, __demoMode: !1 };
}, 4: (e, o) => {
  var a, r, u;
  if ((a = e.dataRef.current) != null && a.virtual) return { ...e, options: [...e.options, o.payload] };
  let b = o.payload, i = me(e, (l) => (l.push(b), l));
  e.activeOptionIndex === null && (r = e.dataRef.current) != null && r.isSelected(o.payload.dataRef.current.value) && (i.activeOptionIndex = i.options.indexOf(b));
  let t = { ...e, ...i, activationTrigger: 2 };
  return (u = e.dataRef.current) != null && u.__demoMode && e.dataRef.current.value === void 0 && (t.activeOptionIndex = 0), t;
}, 5: (e, o) => {
  var a;
  if ((a = e.dataRef.current) != null && a.virtual) return { ...e, options: e.options.filter((u) => u.id !== o.id) };
  let r = me(e, (u) => {
    let b = u.findIndex((i) => i.id === o.id);
    return b !== -1 && u.splice(b, 1), u;
  });
  return { ...e, ...r, activationTrigger: 2 };
}, 6: (e, o) => e.activationTrigger === o.trigger ? e : { ...e, activationTrigger: o.trigger }, 7: (e, o) => {
  var a, r;
  if (e.virtual === null) return { ...e, virtual: { options: o.options, disabled: (a = o.disabled) != null ? a : () => !1 } };
  if (e.virtual.options === o.options && e.virtual.disabled === o.disabled) return e;
  let u = e.activeOptionIndex;
  if (e.activeOptionIndex !== null) {
    let b = o.options.indexOf(e.virtual.options[e.activeOptionIndex]);
    b !== -1 ? u = b : u = null;
  }
  return { ...e, activeOptionIndex: u, virtual: { options: o.options, disabled: (r = o.disabled) != null ? r : () => !1 } };
}, 8: (e, o) => e.inputElement === o.element ? e : { ...e, inputElement: o.element }, 9: (e, o) => e.buttonElement === o.element ? e : { ...e, buttonElement: o.element }, 10: (e, o) => e.optionsElement === o.element ? e : { ...e, optionsElement: o.element } }, Oe = fe(null);
Oe.displayName = "ComboboxActionsContext";
function se(e) {
  let o = ve(Oe);
  if (o === null) {
    let a = new Error(`<${e} /> is missing a parent <Combobox /> component.`);
    throw Error.captureStackTrace && Error.captureStackTrace(a, se), a;
  }
  return o;
}
let Me = fe(null);
function Rt(e) {
  let o = oe("VirtualProvider"), { options: a } = o.virtual, [r, u] = j(() => {
    let d = o.optionsElement;
    if (!d) return [0, 0];
    let x = window.getComputedStyle(d);
    return [parseFloat(x.paddingBlockStart || x.paddingTop), parseFloat(x.paddingBlockEnd || x.paddingBottom)];
  }, [o.optionsElement]), b = Ne({ enabled: a.length !== 0, scrollPaddingStart: r, scrollPaddingEnd: u, count: a.length, estimateSize() {
    return 40;
  }, getScrollElement() {
    return o.optionsElement;
  }, overscan: 12 }), [i, t] = De(0);
  Q(() => {
    t((d) => d + 1);
  }, [a]);
  let l = b.getVirtualItems();
  return l.length === 0 ? null : A.createElement(Me.Provider, { value: b }, A.createElement("div", { style: { position: "relative", width: "100%", height: `${b.getTotalSize()}px` }, ref: (d) => {
    d && o.activationTrigger !== 0 && o.activeOptionIndex !== null && a.length > o.activeOptionIndex && b.scrollToIndex(o.activeOptionIndex);
  } }, l.map((d) => {
    var x;
    return A.createElement(we, { key: d.key }, A.cloneElement((x = e.children) == null ? void 0 : x.call(e, { ...e.slot, option: a[d.index] }), { key: `${i}-${d.key}`, "data-index": d.index, "aria-setsize": a.length, "aria-posinset": d.index + 1, style: { position: "absolute", top: 0, left: 0, transform: `translateY(${d.start}px)`, overflowAnchor: "none" } }));
  })));
}
let re = fe(null);
re.displayName = "ComboboxDataContext";
function oe(e) {
  let o = ve(re);
  if (o === null) {
    let a = new Error(`<${e} /> is missing a parent <Combobox /> component.`);
    throw Error.captureStackTrace && Error.captureStackTrace(a, oe), a;
  }
  return o;
}
function $t(e, o) {
  return ee(o.type, ht, e, o);
}
let Pt = we;
function Dt(e, o) {
  var a, r;
  let u = it(), { value: b, defaultValue: i, onChange: t, form: l, name: d, by: x, disabled: g = u || !1, onClose: I, __demoMode: n = !1, multiple: y = !1, immediate: O = !1, virtual: f = null, nullable: B, ...L } = e, P = je(i), [T = y ? [] : void 0, D] = Ge(b, t, P), [S, m] = Ke($t, { dataRef: Ue(), comboboxState: n ? 0 : 1, isTyping: !1, options: [], virtual: f ? { options: f.options, disabled: (a = f.disabled) != null ? a : () => !1 } : null, activeOptionIndex: null, activationTrigger: 2, inputElement: null, buttonElement: null, optionsElement: null, __demoMode: n }), w = te(!1), z = te({ static: !1, hold: !1 }), k = He(x), H = v((p) => f ? x === null ? f.options.indexOf(p) : f.options.findIndex((E) => k(E, p)) : S.options.findIndex((E) => k(E.dataRef.current.value, p))), q = be((p) => ee(c.mode, { 1: () => T.some((E) => k(E, p)), 0: () => k(T, p) }), [T]), G = v((p) => S.activeOptionIndex === H(p)), c = j(() => ({ ...S, immediate: O, optionsPropsRef: z, value: T, defaultValue: P, disabled: g, mode: y ? 1 : 0, virtual: f ? S.virtual : null, get activeOptionIndex() {
    if (w.current && S.activeOptionIndex === null && (f ? f.options.length > 0 : S.options.length > 0)) {
      if (f) {
        let E = f.options.findIndex((U) => {
          var ue, Ee;
          return !((Ee = (ue = f.disabled) == null ? void 0 : ue.call(f, U)) != null && Ee);
        });
        if (E !== -1) return E;
      }
      let p = S.options.findIndex((E) => !E.dataRef.current.disabled);
      if (p !== -1) return p;
    }
    return S.activeOptionIndex;
  }, calculateIndex: H, compare: k, isSelected: q, isActive: G }), [T, P, g, y, n, S, f]);
  Q(() => {
    var p;
    f && m({ type: 7, options: f.options, disabled: (p = f.disabled) != null ? p : null });
  }, [f, f == null ? void 0 : f.options, f == null ? void 0 : f.disabled]), Q(() => {
    S.dataRef.current = c;
  }, [c]);
  let C = c.comboboxState === 0;
  Xe(C, [c.buttonElement, c.inputElement, c.optionsElement], () => _.closeCombobox());
  let K = j(() => {
    var p, E, U;
    return { open: c.comboboxState === 0, disabled: g, activeIndex: c.activeOptionIndex, activeOption: c.activeOptionIndex === null ? null : c.virtual ? c.virtual.options[(p = c.activeOptionIndex) != null ? p : 0] : (U = (E = c.options[c.activeOptionIndex]) == null ? void 0 : E.dataRef.current.value) != null ? U : null, value: T };
  }, [c, g, T]), J = v(() => {
    if (c.activeOptionIndex !== null) {
      if (_.setIsTyping(!1), c.virtual) s(c.virtual.options[c.activeOptionIndex]);
      else {
        let { dataRef: p } = c.options[c.activeOptionIndex];
        s(p.current.value);
      }
      _.goToOption(R.Specific, c.activeOptionIndex);
    }
  }), W = v(() => {
    m({ type: 0 }), w.current = !0;
  }), Y = v(() => {
    m({ type: 1 }), w.current = !1, I == null || I();
  }), ne = v((p) => {
    m({ type: 3, isTyping: p });
  }), ie = v((p, E, U) => (w.current = !1, p === R.Specific ? m({ type: 2, focus: R.Specific, idx: E, trigger: U }) : m({ type: 2, focus: p, trigger: U }))), F = v((p, E) => (m({ type: 4, payload: { id: p, dataRef: E } }), () => {
    c.isActive(E.current.value) && (w.current = !0), m({ type: 5, id: p });
  })), s = v((p) => ee(c.mode, { 0() {
    return D == null ? void 0 : D(p);
  }, 1() {
    let E = c.value.slice(), U = E.findIndex((ue) => k(ue, p));
    return U === -1 ? E.push(p) : E.splice(U, 1), D == null ? void 0 : D(E);
  } })), V = v((p) => {
    m({ type: 6, trigger: p });
  }), $ = v((p) => {
    m({ type: 8, element: p });
  }), N = v((p) => {
    m({ type: 9, element: p });
  }), h = v((p) => {
    m({ type: 10, element: p });
  }), _ = j(() => ({ onChange: s, registerOption: F, goToOption: ie, setIsTyping: ne, closeCombobox: Y, openCombobox: W, setActivationTrigger: V, selectActiveOption: J, setInputElement: $, setButtonElement: N, setOptionsElement: h }), []), [X, ke] = Et(), Be = o === null ? {} : { ref: o }, Le = be(() => {
    if (P !== void 0) return D == null ? void 0 : D(P);
  }, [D, P]), Ve = le();
  return A.createElement(ke, { value: X, props: { htmlFor: (r = c.inputElement) == null ? void 0 : r.id }, slot: { open: c.comboboxState === 0, disabled: g } }, A.createElement(st, null, A.createElement(Oe.Provider, { value: _ }, A.createElement(re.Provider, { value: c }, A.createElement(bt, { value: ee(c.comboboxState, { 0: de.Open, 1: de.Closed }) }, d != null && A.createElement(dt, { disabled: g, data: T != null ? { [d]: T } : {}, form: l, onReset: Le }), Ve({ ourProps: Be, theirProps: L, slot: K, defaultTag: Pt, name: "Combobox" }))))));
}
let wt = "input";
function Ft(e, o) {
  var a, r, u, b, i;
  let t = oe("Combobox.Input"), l = se("Combobox.Input"), d = pe(), x = ct(), { id: g = x || `headlessui-combobox-input-${d}`, onChange: I, displayValue: n, disabled: y = t.disabled || !1, autoFocus: O = !1, type: f = "text", ...B } = e, L = te(null), P = ce(L, o, ut(), l.setInputElement), T = Fe(t.inputElement), D = qe(), S = v(() => {
    l.onChange(null), t.optionsElement && (t.optionsElement.scrollTop = 0), l.goToOption(R.Nothing);
  }), m = j(() => {
    var s;
    return typeof n == "function" && t.value !== void 0 ? (s = n(t.value)) != null ? s : "" : typeof t.value == "string" ? t.value : "";
  }, [t.value, n]);
  Se(([s, V], [$, N]) => {
    if (t.isTyping) return;
    let h = L.current;
    h && ((N === 0 && V === 1 || s !== $) && (h.value = s), requestAnimationFrame(() => {
      if (t.isTyping || !h || (T == null ? void 0 : T.activeElement) !== h) return;
      let { selectionStart: _, selectionEnd: X } = h;
      Math.abs((X ?? 0) - (_ ?? 0)) === 0 && _ === 0 && h.setSelectionRange(h.value.length, h.value.length);
    }));
  }, [m, t.comboboxState, T, t.isTyping]), Se(([s], [V]) => {
    if (s === 0 && V === 1) {
      if (t.isTyping) return;
      let $ = L.current;
      if (!$) return;
      let N = $.value, { selectionStart: h, selectionEnd: _, selectionDirection: X } = $;
      $.value = "", $.value = N, X !== null ? $.setSelectionRange(h, _, X) : $.setSelectionRange(h, _);
    }
  }, [t.comboboxState]);
  let w = te(!1), z = v(() => {
    w.current = !0;
  }), k = v(() => {
    D.nextFrame(() => {
      w.current = !1;
    });
  }), H = v((s) => {
    switch (l.setIsTyping(!0), s.key) {
      case M.Enter:
        if (t.comboboxState !== 0 || w.current) return;
        if (s.preventDefault(), s.stopPropagation(), t.activeOptionIndex === null) {
          l.closeCombobox();
          return;
        }
        l.selectActiveOption(), t.mode === 0 && l.closeCombobox();
        break;
      case M.ArrowDown:
        return s.preventDefault(), s.stopPropagation(), ee(t.comboboxState, { 0: () => l.goToOption(R.Next), 1: () => l.openCombobox() });
      case M.ArrowUp:
        return s.preventDefault(), s.stopPropagation(), ee(t.comboboxState, { 0: () => l.goToOption(R.Previous), 1: () => {
          Z(() => l.openCombobox()), t.value || l.goToOption(R.Last);
        } });
      case M.Home:
        if (s.shiftKey) break;
        return s.preventDefault(), s.stopPropagation(), l.goToOption(R.First);
      case M.PageUp:
        return s.preventDefault(), s.stopPropagation(), l.goToOption(R.First);
      case M.End:
        if (s.shiftKey) break;
        return s.preventDefault(), s.stopPropagation(), l.goToOption(R.Last);
      case M.PageDown:
        return s.preventDefault(), s.stopPropagation(), l.goToOption(R.Last);
      case M.Escape:
        return t.comboboxState !== 0 ? void 0 : (s.preventDefault(), t.optionsElement && !t.optionsPropsRef.current.static && s.stopPropagation(), t.mode === 0 && t.value === null && S(), l.closeCombobox());
      case M.Tab:
        if (t.comboboxState !== 0) return;
        t.mode === 0 && t.activationTrigger !== 1 && l.selectActiveOption(), l.closeCombobox();
        break;
    }
  }), q = v((s) => {
    I == null || I(s), t.mode === 0 && s.target.value === "" && S(), l.openCombobox();
  }), G = v((s) => {
    var V, $, N;
    let h = (V = s.relatedTarget) != null ? V : Ce.find((_) => _ !== s.currentTarget);
    if (!(($ = t.optionsElement) != null && $.contains(h)) && !((N = t.buttonElement) != null && N.contains(h)) && t.comboboxState === 0) return s.preventDefault(), t.mode === 0 && t.value === null && S(), l.closeCombobox();
  }), c = v((s) => {
    var V, $, N;
    let h = (V = s.relatedTarget) != null ? V : Ce.find((_) => _ !== s.currentTarget);
    ($ = t.buttonElement) != null && $.contains(h) || (N = t.optionsElement) != null && N.contains(h) || t.disabled || t.immediate && t.comboboxState !== 0 && D.microTask(() => {
      Z(() => l.openCombobox()), l.setActivationTrigger(1);
    });
  }), C = ge(), K = gt(), { isFocused: J, focusProps: W } = $e({ autoFocus: O }), { isHovered: Y, hoverProps: ne } = Pe({ isDisabled: y }), ie = j(() => ({ open: t.comboboxState === 0, disabled: y, hover: Y, focus: J, autofocus: O }), [t, Y, J, O, y]), F = xe({ ref: P, id: g, role: "combobox", type: f, "aria-controls": (a = t.optionsElement) == null ? void 0 : a.id, "aria-expanded": t.comboboxState === 0, "aria-activedescendant": t.activeOptionIndex === null ? void 0 : t.virtual ? (r = t.options.find((s) => !s.dataRef.current.disabled && t.compare(s.dataRef.current.value, t.virtual.options[t.activeOptionIndex]))) == null ? void 0 : r.id : (u = t.options[t.activeOptionIndex]) == null ? void 0 : u.id, "aria-labelledby": C, "aria-describedby": K, "aria-autocomplete": "list", defaultValue: (i = (b = e.defaultValue) != null ? b : t.defaultValue !== void 0 ? n == null ? void 0 : n(t.defaultValue) : null) != null ? i : t.defaultValue, disabled: y || void 0, autoFocus: O, onCompositionStart: z, onCompositionEnd: k, onKeyDown: H, onChange: q, onFocus: c, onBlur: G }, W, ne);
  return le()({ ourProps: F, theirProps: B, slot: ie, defaultTag: wt, name: "Combobox.Input" });
}
let _t = "button";
function At(e, o) {
  var a;
  let r = oe("Combobox.Button"), u = se("Combobox.Button"), b = ce(o, u.setButtonElement), i = pe(), { id: t = `headlessui-combobox-button-${i}`, disabled: l = r.disabled || !1, autoFocus: d = !1, ...x } = e, g = _e(r.inputElement), I = v((m) => {
    switch (m.key) {
      case M.Space:
      case M.Enter:
        m.preventDefault(), m.stopPropagation(), r.comboboxState === 1 && Z(() => u.openCombobox()), g();
        return;
      case M.ArrowDown:
        m.preventDefault(), m.stopPropagation(), r.comboboxState === 1 && (Z(() => u.openCombobox()), r.value || u.goToOption(R.First)), g();
        return;
      case M.ArrowUp:
        m.preventDefault(), m.stopPropagation(), r.comboboxState === 1 && (Z(() => u.openCombobox()), r.value || u.goToOption(R.Last)), g();
        return;
      case M.Escape:
        if (r.comboboxState !== 0) return;
        m.preventDefault(), r.optionsElement && !r.optionsPropsRef.current.static && m.stopPropagation(), Z(() => u.closeCombobox()), g();
        return;
      default:
        return;
    }
  }), n = v((m) => {
    m.preventDefault(), !ft(m.currentTarget) && (m.button === Ae.Left && (r.comboboxState === 0 ? u.closeCombobox() : u.openCombobox()), g());
  }), y = ge([t]), { isFocusVisible: O, focusProps: f } = $e({ autoFocus: d }), { isHovered: B, hoverProps: L } = Pe({ isDisabled: l }), { pressed: P, pressProps: T } = ze({ disabled: l }), D = j(() => ({ open: r.comboboxState === 0, active: P || r.comboboxState === 0, disabled: l, value: r.value, hover: B, focus: O }), [r, B, O, P, l]), S = xe({ ref: b, id: t, type: Ye(e, r.buttonElement), tabIndex: -1, "aria-haspopup": "listbox", "aria-controls": (a = r.optionsElement) == null ? void 0 : a.id, "aria-expanded": r.comboboxState === 0, "aria-labelledby": y, disabled: l || void 0, autoFocus: d, onMouseDown: n, onKeyDown: I }, f, L, T);
  return le()({ ourProps: S, theirProps: x, slot: D, defaultTag: _t, name: "Combobox.Button" });
}
let Mt = "div", kt = Re.RenderStrategy | Re.Static;
function Bt(e, o) {
  var a, r, u;
  let b = pe(), { id: i = `headlessui-combobox-options-${b}`, hold: t = !1, anchor: l, portal: d = !1, modal: x = !0, transition: g = !1, ...I } = e, n = oe("Combobox.Options"), y = se("Combobox.Options"), O = rt(l);
  O && (d = !0);
  let [f, B] = at(O), [L, P] = De(null), T = lt(), D = ce(o, O ? f : null, y.setOptionsElement, P), S = Fe(n.optionsElement), m = mt(), [w, z] = tt(g, L, m !== null ? (m & de.Open) === de.Open : n.comboboxState === 0);
  We(w, n.inputElement, y.closeCombobox);
  let k = n.__demoMode ? !1 : x && n.comboboxState === 0;
  Ze(k, S);
  let H = n.__demoMode ? !1 : x && n.comboboxState === 0;
  Je(H, { allowed: be(() => [n.inputElement, n.buttonElement, n.optionsElement], [n.inputElement, n.buttonElement, n.optionsElement]) }), Q(() => {
    var F;
    n.optionsPropsRef.current.static = (F = e.static) != null ? F : !1;
  }, [n.optionsPropsRef, e.static]), Q(() => {
    n.optionsPropsRef.current.hold = t;
  }, [n.optionsPropsRef, t]), nt(n.comboboxState === 0, { container: n.optionsElement, accept(F) {
    return F.getAttribute("role") === "option" ? NodeFilter.FILTER_REJECT : F.hasAttribute("role") ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
  }, walk(F) {
    F.setAttribute("role", "none");
  } });
  let q = ge([(a = n.buttonElement) == null ? void 0 : a.id]), G = j(() => ({ open: n.comboboxState === 0, option: void 0 }), [n.comboboxState]), c = v(() => {
    y.setActivationTrigger(0);
  }), C = v((F) => {
    F.preventDefault(), y.setActivationTrigger(0);
  }), K = xe(O ? T() : {}, { "aria-labelledby": q, role: "listbox", "aria-multiselectable": n.mode === 1 ? !0 : void 0, id: i, ref: D, style: { ...I.style, ...B, "--input-width": Ie(n.inputElement, !0).width, "--button-width": Ie(n.buttonElement, !0).width }, onWheel: n.activationTrigger === 0 ? void 0 : c, onMouseDown: C, ...ot(z) }), J = w && n.comboboxState === 1, W = ye(J, (r = n.virtual) == null ? void 0 : r.options), Y = ye(J, n.value), ne = v((F) => n.compare(Y, F));
  if (n.virtual) {
    if (W === void 0) throw new Error("Missing `options` in virtual mode");
    Object.assign(I, { children: A.createElement(re.Provider, { value: W !== n.virtual.options ? { ...n, virtual: { ...n.virtual, options: W } } : n }, A.createElement(Rt, { slot: G }, I.children)) });
  }
  let ie = le();
  return A.createElement(It, { enabled: d ? e.static || w : !1 }, A.createElement(re.Provider, { value: n.mode === 1 ? n : { ...n, isSelected: ne } }, ie({ ourProps: K, theirProps: { ...I, children: A.createElement(pt, { freeze: J }, typeof I.children == "function" ? (u = I.children) == null ? void 0 : u.call(I, G) : I.children) }, slot: G, defaultTag: Mt, features: kt, visible: w, name: "Combobox.Options" })));
}
let Lt = "div";
function Vt(e, o) {
  var a, r, u, b;
  let i = oe("Combobox.Option"), t = se("Combobox.Option"), l = pe(), { id: d = `headlessui-combobox-option-${l}`, value: x, disabled: g = (u = (r = (a = i.virtual) == null ? void 0 : a.disabled) == null ? void 0 : r.call(a, x)) != null ? u : !1, order: I = null, ...n } = e, y = _e(i.inputElement), O = i.virtual ? i.activeOptionIndex === i.calculateIndex(x) : i.activeOptionIndex === null ? !1 : ((b = i.options[i.activeOptionIndex]) == null ? void 0 : b.id) === d, f = i.isSelected(x), B = te(null), L = Qe({ disabled: g, value: x, domRef: B, order: I }), P = ve(Me), T = ce(o, B, P ? P.measureElement : null), D = v(() => {
    t.setIsTyping(!1), t.onChange(x);
  });
  Q(() => t.registerOption(d, L), [L, d]);
  let S = te(!(i.virtual || i.__demoMode));
  Q(() => {
    if (!i.virtual && !i.__demoMode) return he().requestAnimationFrame(() => {
      S.current = !0;
    });
  }, [i.virtual, i.__demoMode]), Q(() => {
    if (S.current && i.comboboxState === 0 && O && i.activationTrigger !== 0) return he().requestAnimationFrame(() => {
      var C, K;
      (K = (C = B.current) == null ? void 0 : C.scrollIntoView) == null || K.call(C, { block: "nearest" });
    });
  }, [B, O, i.comboboxState, i.activationTrigger, i.activeOptionIndex]);
  let m = v((C) => {
    C.preventDefault(), C.button === Ae.Left && (g || (D(), xt() || requestAnimationFrame(() => y()), i.mode === 0 && t.closeCombobox()));
  }), w = v(() => {
    if (g) return t.goToOption(R.Nothing);
    let C = i.calculateIndex(x);
    t.goToOption(R.Specific, C);
  }), z = et(), k = v((C) => z.update(C)), H = v((C) => {
    if (!z.wasMoved(C) || g || O) return;
    let K = i.calculateIndex(x);
    t.goToOption(R.Specific, K, 0);
  }), q = v((C) => {
    z.wasMoved(C) && (g || O && (i.optionsPropsRef.current.hold || t.goToOption(R.Nothing)));
  }), G = j(() => ({ active: O, focus: O, selected: f, disabled: g }), [O, f, g]), c = { id: d, ref: T, role: "option", tabIndex: g === !0 ? void 0 : -1, "aria-disabled": g === !0 ? !0 : void 0, "aria-selected": f, disabled: void 0, onMouseDown: m, onFocus: w, onPointerEnter: k, onMouseEnter: k, onPointerMove: H, onMouseMove: H, onPointerLeave: q, onMouseLeave: q };
  return le()({ ourProps: c, theirProps: n, slot: G, defaultTag: Lt, name: "Combobox.Option" });
}
let Nt = ae(Dt), Kt = ae(At), Ut = ae(Ft), zt = Ot, Ht = ae(Bt), Gt = ae(Vt), Lo = Object.assign(Nt, { Input: Ut, Button: Kt, Label: zt, Options: Ht, Option: Gt });
export {
  Lo as Combobox,
  Kt as ComboboxButton,
  Ut as ComboboxInput,
  zt as ComboboxLabel,
  Gt as ComboboxOption,
  Ht as ComboboxOptions
};
