import { o as Ot } from "./rolldown-runtime.js";
import { i as Ft, t as Bt } from "./vendor/react.js";
import { u as gt } from "./safeReact.js";
import { l as Rt, n as ht, o as wt, r as Nt, s as $e, t as xe, u as kt } from "./useRenderElement.js";
import { n as we, t as me } from "./useIsoLayoutEffect.js";
import { t as It } from "./useButton.js";
import { n as _t } from "./useAnimationFrame.js";
import { a as Tt, n as tt, t as ct } from "./useTransitionStatus.js";
import { n as qe } from "./useTimeout.js";
import { n as Qe, r as lt, t as ut } from "./scrollEdges.js";
import { t as jt } from "./useBaseUiId.js";
import { s as Wt } from "./detectBrowser.js";
import { n as nt } from "./shadowDom.js";
import { t as qt } from "./element.js";
import { A as Yt, T as zt, a as $t, b as Gt, d as a, f as P, i as Kt, o as Xt, p as Jt, r as Zt, u as Qt } from "./popupStateMapping.js";
import { O as eo } from "./composite.js";
import { t as it } from "./owner.js";
import { t as to } from "./CSPContext.js";
import { n as oo } from "./DirectionContext.js";
import { t as Ke } from "./clamp.js";
import { t as ro } from "./addEventListener.js";
import { g as dt, p as st, r as no, t as Ee, w as so } from "./createBaseUIEventDetails.js";
import { t as ft } from "./useValueAsRef.js";
import { n as lo, t as io } from "./visuallyHidden.js";
import { a as ao, i as co, r as uo, t as fo } from "./useOpenInteractionType.js";
import { a as po, n as mo, o as go, r as ho, t as vo } from "./usePositioner.js";
import { n as So, t as xo } from "./useTypeahead.js";
import { t as yo } from "./inertValue.js";
import { t as vt } from "./useControlled.js";
import { n as bo, t as Ro } from "./useCompositeListItem.js";
import { t as wo } from "./CompositeList.js";
import { s as Io } from "./composite2.js";
import { t as To } from "./ToolbarRootContext.js";
import { a as Mt, c as Mo, r as Ao, t as Co } from "./useRegisterFieldControl.js";
import { t as Po } from "./FormContext.js";
import { t as At } from "./useLabelableId.js";
import { t as Eo } from "./useValueChanged.js";
import { n as Vo } from "./resolveAriaLabelledBy.js";
import { a as Lo, c as Ho, d as Uo, i as Do, l as ze, o as Ne, r as Oo, s as at, t as Fo, u as Bo } from "./resolveValueLabel.js";
import { t as No } from "./getPseudoElementBounds.js";
import { t as ko } from "./useAnchoredPopupScrollLock.js";
var o = /* @__PURE__ */ Ot(Ft());
function _o(e) {
  const [t, i] = o.useState({
    current: e,
    previous: null
  });
  return e !== t.current && i({
    current: e,
    previous: t.current
  }), t.previous;
}
var Ct = /* @__PURE__ */ o.createContext(null), Pt = /* @__PURE__ */ o.createContext(null);
function Ie() {
  const e = o.useContext(Ct);
  if (e === null) throw new Error($e(60));
  return e;
}
function Et() {
  const e = o.useContext(Pt);
  if (e === null) throw new Error($e(61));
  return e;
}
var l = {
  id: P((e) => e.id),
  labelId: P((e) => e.labelId),
  modal: P((e) => e.modal),
  multiple: P((e) => e.multiple),
  items: P((e) => e.items),
  itemToStringLabel: P((e) => e.itemToStringLabel),
  itemToStringValue: P((e) => e.itemToStringValue),
  isItemEqualToValue: P((e) => e.isItemEqualToValue),
  value: P((e) => e.value),
  hasSelectedValue: P((e) => {
    const { value: t, multiple: i, itemToStringValue: m } = e;
    return t == null ? !1 : i && Array.isArray(t) ? t.length > 0 : Ne(t, m) !== "";
  }),
  hasNullItemLabel: P((e, t) => t ? Fo(e.items) : !1),
  open: P((e) => e.open),
  mounted: P((e) => e.mounted),
  forceMount: P((e) => e.forceMount),
  transitionStatus: P((e) => e.transitionStatus),
  openMethod: P((e) => e.openMethod),
  activeIndex: P((e) => e.activeIndex),
  selectedIndex: P((e) => e.selectedIndex),
  isActive: P((e, t) => e.activeIndex === t),
  isSelected: P((e, t, i) => {
    const m = e.isItemEqualToValue, S = e.value;
    return e.multiple ? Array.isArray(S) && S.some((g) => at(i, g, m)) : e.selectedIndex === t && e.selectedIndex !== null ? !0 : at(i, S, m);
  }),
  isSelectedByFocus: P((e, t) => e.selectedIndex === t),
  popupProps: P((e) => e.popupProps),
  triggerProps: P((e) => e.triggerProps),
  triggerElement: P((e) => e.triggerElement),
  positionerElement: P((e) => e.positionerElement),
  listElement: P((e) => e.listElement),
  scrollUpArrowVisible: P((e) => e.scrollUpArrowVisible),
  scrollDownArrowVisible: P((e) => e.scrollDownArrowVisible),
  hasScrollArrows: P((e) => e.hasScrollArrows)
}, se = Bt();
function _r(e) {
  const { id: t, value: i, defaultValue: m = null, onValueChange: S, open: g, defaultOpen: w = !1, onOpenChange: u, name: f, form: c, autoComplete: p, disabled: v = !1, readOnly: y = !1, required: b = !1, modal: I = !0, actionsRef: Q, inputRef: R, onOpenChangeComplete: $, items: V, multiple: x = !1, itemToStringLabel: d, itemToStringValue: L, isItemEqualToValue: T = Ho, highlightItemOnHover: H = !0, children: le } = e, { clearErrors: G } = Po(), { setDirty: E, setTouched: K, setFocused: F, shouldValidateOnChange: B, validityData: N, setFilled: k, name: ee, disabled: C, validation: _, validationMode: ge } = Mt(), j = At({ id: t }), U = C || v, r = ee ?? f, [n, ue] = vt({
    controlled: i,
    default: x ? m ?? ht : m,
    name: "Select",
    state: "value"
  }), [s, D] = vt({
    controlled: g,
    default: w,
    name: "Select",
    state: "open"
  }), W = o.useRef([]), te = o.useRef([]), ie = o.useRef(null), Te = o.useRef(null), Le = o.useRef(0), M = o.useRef(null), X = o.useRef([]), q = o.useRef(!1), ae = o.useRef(!1), oe = o.useRef(null), re = o.useRef({
    allowSelectedMouseUp: !1,
    allowUnselectedMouseUp: !1
  }), Y = o.useRef(!1), { mounted: z, setMounted: ce, transitionStatus: de } = ct(s), { openMethod: J, triggerProps: Me } = fo(s), h = kt(() => new Qt({
    id: j,
    labelId: void 0,
    modal: I,
    multiple: x,
    itemToStringLabel: d,
    itemToStringValue: L,
    isItemEqualToValue: T,
    value: n,
    open: s,
    mounted: z,
    transitionStatus: de,
    items: V,
    forceMount: !1,
    openMethod: null,
    activeIndex: null,
    selectedIndex: null,
    popupProps: {},
    triggerProps: {},
    triggerElement: null,
    positionerElement: null,
    listElement: null,
    scrollUpArrowVisible: !1,
    scrollDownArrowVisible: !1,
    hasScrollArrows: !1
  })).current, he = a(h, l.activeIndex), Ae = a(h, l.selectedIndex), Ve = a(h, l.triggerElement), ye = a(h, l.positionerElement), He = _o(J), Oe = J ?? He, Ce = o.useMemo(() => x && Array.isArray(n) && n.length === 0 ? "" : Ne(n, L), [
    x,
    n,
    L
  ]), Fe = o.useMemo(() => x && Array.isArray(n) ? n.map((A) => Ne(A, L)) : Ne(n, L), [
    x,
    n,
    L
  ]);
  Co(ft(h.state.triggerElement), {
    id: j,
    value: n,
    getValue: we(() => Fe)
  });
  const pe = o.useRef(n);
  me(() => {
    n !== pe.current && h.set("forceMount", !0);
  }, [h, n]), me(() => {
    k(x ? Array.isArray(n) && n.length > 0 : n != null);
  }, [
    x,
    n,
    k
  ]), me(function() {
    if (s) return;
    const O = X.current;
    if (x) {
      const fe = Array.isArray(n) ? n : [];
      if (fe.length === 0) {
        h.set("selectedIndex", null);
        return;
      }
      const Se = fe[fe.length - 1], De = ze(O, Se, T);
      h.set("selectedIndex", De === -1 ? null : De);
      return;
    }
    const Z = ze(O, n, T);
    h.set("selectedIndex", Z === -1 ? null : Z);
  }, [
    x,
    s,
    n,
    X,
    T,
    h
  ]), Eo(n, () => {
    G(r), E(n !== N.initialValue), B() ? _.commit(n) : _.commit(n, !0);
  });
  const ne = we((A, O) => {
    if (u?.(A, O), !O.isCanceled && (D(A), !A && (O.reason === "focus-out" || O.reason === "outside-press") && (K(!0), F(!1), ge === "onBlur" && _.commit(n)), !A && h.state.activeIndex !== null)) {
      const Z = W.current[h.state.activeIndex];
      queueMicrotask(() => {
        Z?.setAttribute("tabindex", "-1");
      });
    }
  }), Pe = we(() => {
    ce(!1), h.update({
      activeIndex: null,
      openMethod: null
    }), $?.(!1);
  });
  tt({
    enabled: !Q,
    open: s,
    ref: ie,
    onComplete() {
      s || Pe();
    }
  }), o.useImperativeHandle(Q, () => ({ unmount: Pe }), [Pe]);
  const Be = we((A, O) => {
    S?.(A, O), !O.isCanceled && ue(A);
  }), ve = we(() => {
    const A = h.state.listElement || ie.current;
    if (!A) return;
    const O = ut(A.scrollHeight, A.clientHeight), Z = Qe(A.scrollTop, O), fe = Z > 0, Se = Z < O;
    h.state.scrollUpArrowVisible !== fe && h.set("scrollUpArrowVisible", fe), h.state.scrollDownArrowVisible !== Se && h.set("scrollDownArrowVisible", Se);
  }), be = po({
    open: s,
    onOpenChange: ne,
    elements: {
      reference: Ve,
      floating: ye
    }
  }), { getReferenceProps: ke, getFloatingProps: Ue, getItemProps: Re } = Xt([
    co(be, {
      enabled: !y && !U,
      event: "mousedown"
    }),
    Jt(be, { bubbles: !1 }),
    So(be, {
      enabled: !y && !U,
      listRef: W,
      activeIndex: he,
      selectedIndex: Ae,
      disabledIndices: ht,
      onNavigate(A) {
        A === null && !s || h.set("activeIndex", A);
      },
      focusItemOnHover: H
    }),
    xo(be, {
      enabled: !y && !U && (s || !x),
      listRef: te,
      activeIndex: he,
      selectedIndex: Ae,
      onMatch(A) {
        s ? h.set("activeIndex", A) : Be(X.current[A], Ee("none"));
      },
      onTypingChange(A) {
        q.current = A;
      }
    })
  ]), _e = o.useMemo(() => Rt(ke(), Me, j ? { id: j } : Nt), [
    ke,
    Me,
    j
  ]);
  Yt(() => {
    h.update({
      popupProps: Ue(),
      triggerProps: _e
    });
  }), me(() => {
    h.update({
      id: j,
      modal: I,
      multiple: x,
      value: n,
      open: s,
      mounted: z,
      transitionStatus: de,
      popupProps: Ue(),
      triggerProps: _e,
      items: V,
      itemToStringLabel: d,
      itemToStringValue: L,
      isItemEqualToValue: T,
      openMethod: Oe
    });
  }, [
    h,
    j,
    I,
    x,
    n,
    s,
    z,
    de,
    Ue,
    _e,
    V,
    d,
    L,
    T,
    Oe
  ]);
  const je = o.useMemo(() => ({
    store: h,
    name: r,
    required: b,
    disabled: U,
    readOnly: y,
    multiple: x,
    highlightItemOnHover: H,
    setValue: Be,
    setOpen: ne,
    listRef: W,
    popupRef: ie,
    scrollHandlerRef: Te,
    handleScrollArrowVisibility: ve,
    scrollArrowsMountedCountRef: Le,
    getItemProps: Re,
    events: be.context.events,
    valueRef: M,
    valuesRef: X,
    labelsRef: te,
    typingRef: q,
    selectionRef: re,
    selectedItemTextRef: oe,
    validation: _,
    onOpenChangeComplete: $,
    keyboardActiveRef: ae,
    alignItemWithTriggerActiveRef: Y,
    initialValueRef: pe
  }), [
    h,
    r,
    b,
    U,
    y,
    x,
    H,
    Be,
    ne,
    Re,
    be.context.events,
    _,
    $,
    ve
  ]), ot = wt(R, _.inputRef), Ge = x && Array.isArray(n) && n.length > 0, We = x ? void 0 : r, rt = o.useMemo(() => !x || !Array.isArray(n) || !r ? null : n.map((A) => {
    const O = Ne(A, L);
    return /* @__PURE__ */ (0, se.jsx)("input", {
      type: "hidden",
      form: c,
      name: r,
      value: O
    }, O);
  }), [
    x,
    n,
    c,
    r,
    L
  ]);
  return /* @__PURE__ */ (0, se.jsx)(Ct.Provider, {
    value: je,
    children: /* @__PURE__ */ (0, se.jsxs)(Pt.Provider, {
      value: be,
      children: [
        le,
        /* @__PURE__ */ (0, se.jsx)("input", {
          ..._.getInputValidationProps({
            onFocus() {
              h.state.triggerElement?.focus({ focusVisible: !0 });
            },
            onChange(A) {
              if (A.nativeEvent.defaultPrevented) return;
              const O = A.currentTarget.value, Z = Ee(dt, A.nativeEvent);
              function fe() {
                if (x) return;
                const Se = X.current.find((De) => Ne(De, L).toLowerCase() === O.toLowerCase() || Lo(De, d).toLowerCase() === O.toLowerCase());
                Se != null && (E(Se !== N.initialValue), Be(Se, Z), B() && _.commit(Se));
              }
              h.set("forceMount", !0), queueMicrotask(fe);
            }
          }),
          id: j && We == null ? `${j}-hidden-input` : void 0,
          form: c,
          name: We,
          autoComplete: p,
          value: Ce,
          disabled: U,
          required: b && !Ge,
          readOnly: y,
          ref: ot,
          style: r ? lo : io,
          tabIndex: -1,
          "aria-hidden": !0,
          suppressHydrationWarning: !0
        }),
        rt
      ]
    })
  });
}
var Xe = 2, jo = 400, St = 200, Wo = {
  ...Kt,
  ...Mo,
  value: () => null
}, jr = /* @__PURE__ */ o.forwardRef(function(t, i) {
  const { render: m, className: S, id: g, disabled: w = !1, nativeButton: u = !0, style: f, ...c } = t, { setTouched: p, setFocused: v, validationMode: y, state: b, disabled: I } = Mt(), { labelId: Q } = Ao(), { store: R, setOpen: $, selectionRef: V, validation: x, readOnly: d, required: L, alignItemWithTriggerActiveRef: T, disabled: H, keyboardActiveRef: le } = Ie(), G = I || H || w, E = a(R, l.open), K = a(R, l.value), F = a(R, l.triggerProps), B = a(R, l.positionerElement), N = a(R, l.listElement), k = a(R, l.id), ee = a(R, l.labelId), C = a(R, l.hasSelectedValue), _ = !C && E, ge = a(R, l.hasNullItemLabel, _), j = g ?? k, U = Vo(Q, ee);
  At({ id: j });
  const r = ft(B), n = o.useRef(null), { getButtonProps: ue, buttonRef: s } = It({
    disabled: G,
    native: u
  }), D = wt(i, n, s, we((q) => {
    R.set("triggerElement", q);
  })), W = qe(), te = qe(), ie = qe(), Te = qe();
  o.useEffect(() => {
    if (E)
      return C || ge ? Te.start(St, () => {
        V.current.allowUnselectedMouseUp = !0, ie.start(St, () => {
          V.current.allowSelectedMouseUp = !0;
        });
      }) : ie.start(jo, () => {
        V.current.allowUnselectedMouseUp = !0, V.current.allowSelectedMouseUp = !0;
      }), () => {
        ie.clear(), Te.clear();
      };
    V.current = {
      allowSelectedMouseUp: !1,
      allowUnselectedMouseUp: !1
    }, te.clear();
  }, [
    E,
    C,
    ge,
    V,
    te,
    ie,
    Te
  ]);
  const Le = o.useMemo(() => N?.id ?? qt(B)?.id, [N, B]), M = Rt(F, {
    id: j,
    role: "combobox",
    "aria-expanded": E ? "true" : "false",
    "aria-haspopup": "listbox",
    "aria-controls": E ? Le : void 0,
    "aria-labelledby": U,
    "aria-readonly": d || void 0,
    "aria-required": L || void 0,
    tabIndex: G ? -1 : 0,
    ref: D,
    onFocus(q) {
      v(!0), E && T.current && $(!1, Ee(dt, q.nativeEvent)), W.start(0, () => {
        R.set("forceMount", !0);
      });
    },
    onBlur(q) {
      nt(B, q.relatedTarget) || (p(!0), v(!1), y === "onBlur" && x.commit(K));
    },
    onPointerMove() {
      le.current = !1;
    },
    onKeyDown() {
      le.current = !0;
    },
    onMouseDown(q) {
      if (E) return;
      const ae = it(q.currentTarget);
      function oe(re) {
        if (!n.current) return;
        const Y = re.target;
        if (nt(n.current, Y) || nt(r.current, Y) || Y === n.current) return;
        const z = No(n.current);
        re.clientX >= z.left - Xe && re.clientX <= z.right + Xe && re.clientY >= z.top - Xe && re.clientY <= z.bottom + Xe || $(!1, Ee(no, re));
      }
      te.start(0, () => {
        ae.addEventListener("mouseup", oe, { once: !0 });
      });
    }
  }, x.getValidationProps, c, ue);
  M.role = "combobox";
  const X = {
    ...b,
    open: E,
    disabled: G,
    value: K,
    readOnly: d,
    placeholder: !C
  };
  return xe("button", t, {
    ref: [i, n],
    state: X,
    stateAttributesMapping: Wo,
    props: M
  });
}), qo = { value: () => null }, Wr = /* @__PURE__ */ o.forwardRef(function(t, i) {
  const { className: m, render: S, children: g, placeholder: w, style: u, ...f } = t, { store: c, valueRef: p } = Ie(), v = a(c, l.value), y = a(c, l.items), b = a(c, l.itemToStringLabel), I = a(c, l.hasSelectedValue), Q = !I && w != null && g == null, R = a(c, l.hasNullItemLabel, Q), $ = {
    value: v,
    placeholder: !I
  };
  let V = null;
  return typeof g == "function" ? V = g(v) : g != null ? V = g : !I && w != null && !R ? V = w : Array.isArray(v) ? V = Oo(v, y, b) : V = Do(v, y, b), xe("span", t, {
    state: $,
    ref: [i, p],
    props: [{ children: V }, f],
    stateAttributesMapping: qo
  });
}), qr = /* @__PURE__ */ o.forwardRef(function(t, i) {
  const { className: m, render: S, style: g, ...w } = t, { store: u } = Ie();
  return xe("span", t, {
    state: { open: a(u, l.open) },
    ref: i,
    props: [{
      "aria-hidden": !0,
      children: "▼"
    }, w],
    stateAttributesMapping: $t
  });
}), Yo = /* @__PURE__ */ o.createContext(void 0), Yr = /* @__PURE__ */ o.forwardRef(function(t, i) {
  const { store: m } = Ie(), S = a(m, l.mounted), g = a(m, l.forceMount);
  return S || g ? /* @__PURE__ */ (0, se.jsx)(Yo.Provider, {
    value: !0,
    children: /* @__PURE__ */ (0, se.jsx)(Gt, {
      ref: i,
      ...t
    })
  }) : null;
}), Vt = /* @__PURE__ */ o.createContext(void 0);
function pt() {
  const e = o.useContext(Vt);
  if (!e) throw new Error($e(59));
  return e;
}
function et(e, t) {
  e && Object.assign(e.style, t);
}
var Lt = {
  position: "relative",
  maxHeight: "100%",
  overflowX: "hidden",
  overflowY: "auto"
}, zo = { position: "fixed" }, zr = /* @__PURE__ */ o.forwardRef(function(t, i) {
  const { anchor: m, positionMethod: S = "absolute", className: g, render: w, side: u = "bottom", align: f = "center", sideOffset: c = 0, alignOffset: p = 0, collisionBoundary: v = "clipping-ancestors", collisionPadding: y, arrowPadding: b = 5, sticky: I = !1, disableAnchorTracking: Q, alignItemWithTrigger: R = !0, collisionAvoidance: $ = zt, style: V, ...x } = t, { store: d, listRef: L, labelsRef: T, alignItemWithTriggerActiveRef: H, selectedItemTextRef: le, valuesRef: G, initialValueRef: E, popupRef: K, setValue: F } = Ie(), B = Et(), N = a(d, l.open), k = a(d, l.mounted), ee = a(d, l.modal), C = a(d, l.value), _ = a(d, l.openMethod), ge = a(d, l.positionerElement), j = a(d, l.triggerElement), U = a(d, l.isItemEqualToValue), r = a(d, l.transitionStatus), n = o.useRef(null), ue = o.useRef(null), [s, D] = o.useState(R), W = k && s && _ !== "touch";
  !k && s !== R && D(R), me(() => {
    k || (l.scrollUpArrowVisible(d.state) && d.set("scrollUpArrowVisible", !1), l.scrollDownArrowVisible(d.state) && d.set("scrollDownArrowVisible", !1));
  }, [d, k]), o.useImperativeHandle(H, () => W), ko((W || ee) && N, _ === "touch", ge, j);
  const te = ho({
    anchor: m,
    floatingRootContext: B,
    positionMethod: S,
    mounted: k,
    side: u,
    sideOffset: c,
    align: f,
    alignOffset: p,
    arrowPadding: b,
    collisionBoundary: v,
    collisionPadding: y,
    sticky: I,
    disableAnchorTracking: Q ?? W,
    collisionAvoidance: $,
    keepMounted: !0
  }), ie = W ? "none" : te.side, Te = W ? zo : te.positionerStyles, Le = vo(t, {
    open: N,
    side: ie,
    align: te.align,
    anchorHidden: te.anchorHidden
  }, {
    styles: Te,
    transitionStatus: r,
    props: x,
    refs: [i, we((ae) => {
      d.set("positionerElement", ae);
    })],
    hidden: !k,
    inert: !N
  }), M = o.useRef(0), X = we((ae) => {
    if (ae.size === 0 && M.current === 0 || G.current.length === 0) return;
    const oe = M.current;
    if (M.current = ae.size, ae.size === oe) return;
    const re = Ee(dt);
    if (oe !== 0 && !d.state.multiple && C !== null && ze(G.current, C, U) === -1) {
      const Y = E.current, z = Y != null && ze(G.current, Y, U) !== -1 ? Y : null;
      F(z, re), z === null && (d.set("selectedIndex", null), le.current = null);
    }
    if (oe !== 0 && d.state.multiple && Array.isArray(C)) {
      const Y = (ce) => ze(G.current, ce, U) !== -1, z = C.filter((ce) => Y(ce));
      (z.length !== C.length || z.some((ce) => !Uo(C, ce, U))) && (F(z, re), z.length === 0 && (d.set("selectedIndex", null), le.current = null));
    }
    if (N && W) {
      d.update({
        scrollUpArrowVisible: !1,
        scrollDownArrowVisible: !1
      });
      const Y = { height: "" };
      et(ge, Y), et(K.current, Y);
    }
  }), q = o.useMemo(() => ({
    ...te,
    side: ie,
    alignItemWithTriggerActive: W,
    setControlledAlignItemWithTrigger: D,
    scrollUpArrowRef: n,
    scrollDownArrowRef: ue
  }), [
    te,
    ie,
    W,
    D
  ]);
  return /* @__PURE__ */ (0, se.jsx)(wo, {
    elementsRef: L,
    labelsRef: T,
    onMapChange: X,
    children: /* @__PURE__ */ (0, se.jsxs)(Vt.Provider, {
      value: q,
      children: [k && ee && /* @__PURE__ */ (0, se.jsx)(uo, {
        inert: yo(!N),
        cutout: j
      }), Le]
    })
  });
}), $o = {
  ...Zt,
  ...Tt
}, $r = /* @__PURE__ */ o.forwardRef(function(t, i) {
  const { render: m, className: S, style: g, finalFocus: w, ...u } = t, { store: f, popupRef: c, onOpenChangeComplete: p, setOpen: v, valueRef: y, selectedItemTextRef: b, keyboardActiveRef: I, multiple: Q, handleScrollArrowVisibility: R, scrollHandlerRef: $, listRef: V, highlightItemOnHover: x } = Ie(), { side: d, align: L, alignItemWithTriggerActive: T, isPositioned: H, setControlledAlignItemWithTrigger: le, scrollDownArrowRef: G, scrollUpArrowRef: E } = pt(), K = To(!0) != null, F = Et(), B = oo(), { nonce: N, disableStyleElements: k } = to(), ee = a(f, l.id), C = a(f, l.open), _ = a(f, l.mounted), ge = a(f, l.popupProps), j = a(f, l.transitionStatus), U = a(f, l.triggerElement), r = a(f, l.positionerElement), n = a(f, l.listElement), ue = o.useRef(!1), s = o.useRef(!1), D = o.useRef({}), W = _t(), te = we((M) => {
    if (!r || !c.current || !s.current) return;
    if (ue.current || !T) {
      R();
      return;
    }
    const X = r.style.top === "0px", q = r.style.bottom === "0px";
    if (!X && !q) {
      R();
      return;
    }
    const ae = yt(r), oe = Ye(r.getBoundingClientRect().height, "y", ae), re = it(r), Y = getComputedStyle(r), z = parseFloat(Y.marginTop), ce = parseFloat(Y.marginBottom), de = xt(getComputedStyle(c.current)), J = Math.min(re.documentElement.clientHeight - z - ce, de), Me = M.scrollTop, h = Je(M);
    let he = 0, Ae = null, Ve = !1, ye = !1;
    const He = (pe) => {
      r.style.height = `${pe}px`;
    }, Oe = (pe, ne) => {
      const Pe = Ke(pe, 0, J - oe);
      Pe > 0 && He(oe + Pe), M.scrollTop = ne, J - (oe + Pe) <= 1 && (ue.current = !0), R();
    }, Ce = X ? h - Me : Me, Fe = Math.min(oe + Ce, J);
    if (he = Fe, Ce <= 1) {
      Oe(Ce, X ? h : 0);
      return;
    }
    if (J - Fe > 1 ? X ? ye = !0 : Ae = 0 : (Ve = !0, q && Me < h && (Ae = Me - (Ce - (oe + Ce - J)))), he = Math.ceil(he), he !== 0 && He(he), ye || Ae != null) {
      const pe = Je(M), ne = ye ? pe : Ke(Ae, 0, pe);
      Math.abs(M.scrollTop - ne) > 1 && (M.scrollTop = ne);
    }
    (Ve || he >= J - 1) && (ue.current = !0), R();
  });
  o.useImperativeHandle($, () => te, [te]), tt({
    open: C,
    ref: c,
    onComplete() {
      C && p?.(!0);
    }
  });
  const ie = {
    open: C,
    transitionStatus: j,
    side: d,
    align: L
  };
  me(() => {
    !r || !c.current || Object.keys(D.current).length || (D.current = {
      top: r.style.top || "0",
      left: r.style.left || "0",
      right: r.style.right,
      height: r.style.height,
      bottom: r.style.bottom,
      minHeight: r.style.minHeight,
      maxHeight: r.style.maxHeight,
      marginTop: r.style.marginTop,
      marginBottom: r.style.marginBottom
    });
  }, [c, r]), me(() => {
    C || T || (s.current = !1, ue.current = !1, et(r, D.current));
  }, [
    C,
    T,
    r,
    c
  ]), me(() => {
    const M = c.current;
    if (!C || !U || !r || !M || T && !H || f.state.transitionStatus === "ending") return;
    if (!T) {
      s.current = !0, W.request(R), M.style.removeProperty("--transform-origin");
      return;
    }
    const X = Go(M);
    M.style.removeProperty("--transform-origin");
    try {
      const q = b.current, ae = y.current, oe = getComputedStyle(r), re = getComputedStyle(M), Y = it(U), z = gt(r), ce = yt(U), de = Ze(U.getBoundingClientRect(), ce), J = Ze(r.getBoundingClientRect(), ce), Me = de.height, h = n || M, he = h.scrollHeight, Ae = parseFloat(re.borderBottomWidth), Ve = parseFloat(oe.marginTop) || 10, ye = parseFloat(oe.marginBottom) || 10, He = parseFloat(oe.minHeight) || 100, Oe = xt(re), Ce = 5, Fe = 5, pe = 20, ne = Y.documentElement.clientHeight - Ve - ye, Pe = Y.documentElement.clientWidth, Be = ne - de.bottom + Me;
      let ve, be = B === "rtl" ? de.right - J.width : de.left, ke = 0;
      if (q && ae) {
        const Z = Ze(ae.getBoundingClientRect(), ce);
        ve = Ze(q.getBoundingClientRect(), ce), be = J.left + (B === "rtl" ? Z.right - ve.right : Z.left - ve.left);
        const fe = Z.top - de.top + Z.height / 2;
        ke = ve.top - J.top + ve.height / 2 - fe;
      }
      const Ue = Be + ke + ye + Ae;
      let Re = Math.min(ne, Ue);
      const _e = ne - Ve - ye, je = Ue - Re, ot = Pe - Fe;
      r.style.left = `${Ke(be, Ce, ot - J.width)}px`, r.style.height = `${Re}px`, r.style.maxHeight = "auto", r.style.marginTop = `${Ve}px`, r.style.marginBottom = `${ye}px`, M.style.height = "100%";
      const Ge = Je(h), We = je >= Ge - 1;
      We && (Re = Math.min(ne, J.height) - (je - Ge));
      const rt = de.top < pe || de.bottom > ne - pe || Math.ceil(Re) + 1 < Math.min(he, He), A = (z.visualViewport?.scale ?? 1) !== 1 && Wt;
      if (rt || A) {
        s.current = !0, et(r, D.current), le(!1);
        return;
      }
      const O = Math.max(He, Re);
      if (We) {
        const Z = Math.max(0, ne - Ue);
        r.style.top = J.height >= _e ? "0" : `${Z}px`, r.style.height = `${Re}px`, h.scrollTop = Je(h);
      } else
        r.style.bottom = "0", h.scrollTop = je;
      if (ve) {
        const Z = J.top, fe = J.height, Se = ve.top + ve.height / 2, De = Ke(fe > 0 ? (Se - Z) / fe * 100 : 50, 0, 100);
        M.style.setProperty("--transform-origin", `50% ${De}%`);
      }
      (O === ne || Re >= Oe) && (ue.current = !0), R(), x && f.state.selectedIndex === null && f.state.activeIndex === null && V.current[0] != null && f.set("activeIndex", 0), s.current = !0;
    } finally {
      X();
    }
  }, [
    f,
    C,
    r,
    U,
    y,
    b,
    c,
    R,
    T,
    le,
    W,
    G,
    E,
    n,
    V,
    x,
    B,
    H
  ]), o.useEffect(() => {
    if (!T || !r || !C) return;
    const M = gt(r);
    function X(q) {
      v(!1, Ee(so, q));
    }
    return ro(M, "resize", X);
  }, [
    v,
    T,
    r,
    C
  ]);
  const Te = {
    ...n ? {
      role: "presentation",
      "aria-orientation": void 0
    } : {
      role: "listbox",
      "aria-multiselectable": Q || void 0,
      id: `${ee}-list`
    },
    onKeyDown(M) {
      I.current = !0, K && Io.has(M.key) && M.stopPropagation();
    },
    onMouseMove() {
      I.current = !1;
    },
    onScroll(M) {
      n || te(M.currentTarget);
    },
    ...T && { style: n ? { height: "100%" } : Lt }
  }, Le = xe("div", t, {
    ref: [i, c],
    state: ie,
    stateAttributesMapping: $o,
    props: [
      ge,
      Te,
      mo(j),
      { className: !n && T ? lt.className : void 0 },
      u
    ]
  });
  return /* @__PURE__ */ (0, se.jsxs)(o.Fragment, { children: [!k && lt.getElement(N), /* @__PURE__ */ (0, se.jsx)(ao, {
    context: F,
    modal: !1,
    disabled: !_,
    returnFocus: w,
    restoreFocus: !0,
    children: Le
  })] });
});
function xt(e) {
  const t = e.maxHeight || "";
  return t.endsWith("px") && parseFloat(t) || 1 / 0;
}
function Je(e) {
  return ut(e.scrollHeight, e.clientHeight);
}
function yt(e) {
  return go.getScale(e);
}
function Ye(e, t, i) {
  return e / i[t];
}
function Ze(e, t) {
  return eo({
    x: Ye(e.x, "x", t),
    y: Ye(e.y, "y", t),
    width: Ye(e.width, "x", t),
    height: Ye(e.height, "y", t)
  });
}
var bt = [
  ["transform", "none"],
  ["scale", "1"],
  ["translate", "0 0"]
];
function Go(e) {
  const { style: t } = e, i = {};
  for (const [m, S] of bt)
    i[m] = t.getPropertyValue(m), t.setProperty(m, S, "important");
  return () => {
    for (const [m] of bt) {
      const S = i[m];
      S ? t.setProperty(m, S) : t.removeProperty(m);
    }
  };
}
var Gr = /* @__PURE__ */ o.forwardRef(function(t, i) {
  const { className: m, render: S, style: g, ...w } = t, { store: u, scrollHandlerRef: f } = Ie(), { alignItemWithTriggerActive: c } = pt(), p = a(u, l.hasScrollArrows), v = a(u, l.openMethod), y = a(u, l.multiple), b = {
    id: `${a(u, l.id)}-list`,
    role: "listbox",
    "aria-multiselectable": y || void 0,
    onScroll(I) {
      f.current?.(I.currentTarget);
    },
    ...c && { style: Lt },
    className: p && v !== "touch" ? lt.className : void 0
  };
  return xe("div", t, {
    ref: [i, we((I) => {
      u.set("listElement", I);
    })],
    props: [b, w]
  });
}), Ht = /* @__PURE__ */ o.createContext(void 0);
function mt() {
  const e = o.useContext(Ht);
  if (!e) throw new Error($e(57));
  return e;
}
var Kr = /* @__PURE__ */ o.memo(/* @__PURE__ */ o.forwardRef(function(t, i) {
  const { render: m, className: S, value: g = null, label: w, disabled: u = !1, nativeButton: f = !1, style: c, ...p } = t, v = o.useRef(null), y = bo({
    label: w,
    textRef: v,
    indexGuessBehavior: Ro.GuessFromOrder
  }), { store: b, getItemProps: I, setOpen: Q, setValue: R, selectionRef: $, typingRef: V, valuesRef: x, multiple: d, selectedItemTextRef: L } = Ie(), T = a(b, l.isActive, y.index), H = a(b, l.isSelected, y.index, g), le = a(b, l.isSelectedByFocus, y.index), G = a(b, l.isItemEqualToValue), E = y.index, K = E !== -1, F = o.useRef(null), B = ft(E);
  me(() => {
    if (!K) return;
    const s = x.current;
    return s[E] = g, () => {
      delete s[E];
    };
  }, [
    K,
    E,
    g,
    x
  ]), me(() => {
    if (!K) return;
    const s = b.state.value;
    let D = s;
    d && Array.isArray(s) && s.length > 0 && (D = s[s.length - 1]), D !== void 0 && at(g, D, G) && (b.set("selectedIndex", E), v.current && (L.current = v.current));
  }, [
    K,
    E,
    d,
    G,
    b,
    g,
    L
  ]);
  const N = {
    disabled: u,
    selected: H,
    highlighted: T
  }, k = I({
    active: T,
    selected: H
  });
  k.id = void 0;
  const ee = o.useRef(null), C = o.useRef("mouse"), _ = o.useRef(!1), { getButtonProps: ge, buttonRef: j } = It({
    disabled: u,
    focusableWhenDisabled: !0,
    native: f,
    composite: !0
  });
  function U(s) {
    const D = b.state.value;
    if (d) {
      const W = Array.isArray(D) ? D : [];
      R(H ? Bo(W, g, G) : [...W, g], Ee(st, s));
    } else
      R(g, Ee(st, s)), Q(!1, Ee(st, s));
  }
  const r = {
    role: "option",
    "aria-selected": H,
    tabIndex: T ? 0 : -1,
    onTouchStart() {
      $.current = {
        allowSelectedMouseUp: !1,
        allowUnselectedMouseUp: !1
      };
    },
    onKeyDown(s) {
      ee.current = s.key, b.set("activeIndex", E), s.key === " " && V.current && s.preventDefault();
    },
    onClick(s) {
      _.current = !1, !(s.type === "keydown" && ee.current === null) && (u || s.type === "keydown" && ee.current === " " && V.current || C.current !== "touch" && !T || (ee.current = null, U(s.nativeEvent)));
    },
    onPointerEnter(s) {
      C.current = s.pointerType;
    },
    onPointerDown(s) {
      C.current = s.pointerType, _.current = !0;
    },
    onMouseUp() {
      if (u) return;
      if (_.current) {
        _.current = !1;
        return;
      }
      const s = !$.current.allowSelectedMouseUp && H, D = !$.current.allowUnselectedMouseUp && !H;
      s || D || C.current !== "touch" && !T || F.current?.click();
    }
  }, n = xe("div", t, {
    ref: [
      j,
      i,
      y.ref,
      F
    ],
    state: N,
    props: [
      k,
      r,
      p,
      ge
    ]
  }), ue = o.useMemo(() => ({
    selected: H,
    indexRef: B,
    textRef: v,
    selectedByFocus: le,
    hasRegistered: K
  }), [
    H,
    B,
    v,
    le,
    K
  ]);
  return /* @__PURE__ */ (0, se.jsx)(Ht.Provider, {
    value: ue,
    children: n
  });
})), Xr = /* @__PURE__ */ o.forwardRef(function(t, i) {
  const m = t.keepMounted ?? !1, { selected: S } = mt();
  return m || S ? /* @__PURE__ */ (0, se.jsx)(Ko, {
    ...t,
    ref: i
  }) : null;
}), Ko = /* @__PURE__ */ o.memo(/* @__PURE__ */ o.forwardRef((e, t) => {
  const { render: i, className: m, style: S, keepMounted: g, ...w } = e, { selected: u } = mt(), f = o.useRef(null), { transitionStatus: c, setMounted: p } = ct(u), v = xe("span", e, {
    ref: [t, f],
    state: {
      selected: u,
      transitionStatus: c
    },
    props: [{
      "aria-hidden": !0,
      children: "✔️"
    }, w],
    stateAttributesMapping: Tt
  });
  return tt({
    open: u,
    ref: f,
    onComplete() {
      u || p(!1);
    }
  }), v;
})), Jr = /* @__PURE__ */ o.memo(/* @__PURE__ */ o.forwardRef(function(t, i) {
  const { indexRef: m, textRef: S, selectedByFocus: g, hasRegistered: w } = mt(), { selectedItemTextRef: u } = Ie(), { className: f, render: c, style: p, ...v } = t;
  return xe("div", t, {
    ref: [
      o.useCallback((y) => {
        if (!y || !w) return;
        const b = u.current === null || !u.current.isConnected;
        (g || b && m.current === 0) && (u.current = y);
      }, [
        u,
        m,
        g,
        w
      ]),
      i,
      S
    ],
    props: v
  });
})), Ut = /* @__PURE__ */ o.forwardRef(function(t, i) {
  const { render: m, className: S, style: g, direction: w, keepMounted: u = !1, ...f } = t, c = w === "up", { store: p, popupRef: v, listRef: y, handleScrollArrowVisibility: b, scrollArrowsMountedCountRef: I } = Ie(), { side: Q, scrollDownArrowRef: R, scrollUpArrowRef: $ } = pt(), V = a(p, c ? l.scrollUpArrowVisible : l.scrollDownArrowVisible), x = a(p, l.openMethod), d = V && x !== "touch", L = qe(), T = c ? $ : R, { transitionStatus: H, setMounted: le } = ct(d);
  me(() => (I.current += 1, p.state.hasScrollArrows || p.set("hasScrollArrows", !0), () => {
    I.current = Math.max(0, I.current - 1), I.current === 0 && p.state.hasScrollArrows && p.set("hasScrollArrows", !1);
  }), [p, I]), tt({
    open: d,
    ref: T,
    onComplete() {
      d || le(!1);
    }
  });
  const G = xe("div", t, {
    ref: [i, T],
    state: {
      direction: w,
      visible: d,
      side: Q,
      transitionStatus: H
    },
    props: [{
      "aria-hidden": !0,
      children: c ? "▲" : "▼",
      style: { position: "absolute" },
      onMouseMove(E) {
        if (E.movementX === 0 && E.movementY === 0 || L.isStarted()) return;
        p.set("activeIndex", null);
        function K() {
          const F = p.state.listElement ?? v.current;
          if (!F) return;
          p.set("activeIndex", null), b();
          const B = ut(F.scrollHeight, F.clientHeight), N = Qe(F.scrollTop, B), k = N === (c ? 0 : B), ee = y.current;
          if (N !== F.scrollTop && (F.scrollTop = N), ee.length === 0 && p.set(c ? "scrollUpArrowVisible" : "scrollDownArrowVisible", !k), k) {
            L.clear();
            return;
          }
          if (ee.length > 0) {
            const C = T.current?.offsetHeight || 0;
            F.scrollTop = Xo(ee, c, N, F.clientHeight, C, B);
          }
          L.start(40, K);
        }
        L.start(40, K);
      },
      onMouseLeave() {
        L.clear();
      }
    }, f]
  });
  return d || u ? G : null;
});
function Xo(e, t, i, m, S, g) {
  if (t) {
    let p = 0;
    const v = i + S - 1;
    for (let I = 0; I < e.length; I += 1) {
      const Q = e[I];
      if (Q && Q.offsetTop >= v) {
        p = I;
        break;
      }
    }
    const y = Math.max(0, p - 1), b = e[y];
    return y < p && b ? Qe(b.offsetTop - S, g) : 0;
  }
  let w = e.length - 1;
  const u = i + m - S + 1;
  for (let p = 0; p < e.length; p += 1) {
    const v = e[p];
    if (v && v.offsetTop + v.offsetHeight > u) {
      w = Math.max(0, p - 1);
      break;
    }
  }
  const f = Math.min(e.length - 1, w + 1), c = e[f];
  return f > w && c ? Qe(c.offsetTop + c.offsetHeight - m + S, g) : g;
}
var Zr = /* @__PURE__ */ o.forwardRef(function(t, i) {
  return /* @__PURE__ */ (0, se.jsx)(Ut, {
    ...t,
    ref: i,
    direction: "down"
  });
}), Qr = /* @__PURE__ */ o.forwardRef(function(t, i) {
  return /* @__PURE__ */ (0, se.jsx)(Ut, {
    ...t,
    ref: i,
    direction: "up"
  });
}), Dt = /* @__PURE__ */ o.createContext(void 0);
function Jo() {
  const e = o.useContext(Dt);
  if (e === void 0) throw new Error($e(56));
  return e;
}
var en = /* @__PURE__ */ o.forwardRef(function(t, i) {
  const { className: m, render: S, style: g, ...w } = t, [u, f] = o.useState(), c = o.useMemo(() => ({
    labelId: u,
    setLabelId: f
  }), [u, f]), p = xe("div", t, {
    ref: i,
    props: [{
      role: "group",
      "aria-labelledby": u
    }, w]
  });
  return /* @__PURE__ */ (0, se.jsx)(Dt.Provider, {
    value: c,
    children: p
  });
}), tn = /* @__PURE__ */ o.forwardRef(function(t, i) {
  const { className: m, render: S, id: g, style: w, ...u } = t, { setLabelId: f } = Jo(), c = jt(g);
  return me(() => {
    f(c);
  }, [c, f]), xe("div", t, {
    ref: i,
    props: [{ id: c }, u]
  });
});
export {
  Jr as a,
  Gr as c,
  Yr as d,
  qr as f,
  _r as h,
  Zr as i,
  $r as l,
  jr as m,
  en as n,
  Xr as o,
  Wr as p,
  Qr as r,
  Kr as s,
  tn as t,
  zr as u
};

//# sourceMappingURL=SelectGroupLabel.js.map