import { o as E } from "./rolldown-runtime.js";
import { i as U, t as q } from "./vendor/react.js";
import { t as A } from "./check.js";
import { t as I } from "./chevron-down.js";
import { t as M } from "./chevron-up.js";
import { t as c } from "./utils.js";
import { a as H, c as J, d as K, f as O, h as Q, i as W, l as X, m as Y, n as Z, o as ee, p as te, r as ae, s as re, t as oe, u as se } from "./SelectGroupLabel.js";
import { t as le } from "./use-controllable-state.js";
import { t as ie } from "./FieldTooltip.js";
import { n as ne, t as de } from "./field-props.js";
import { a as ce, c as ue, i as pe, l as me, n as fe, o as xe, r as ge, s as ve, t as he } from "./Field.js";
import { t as Se } from "./Separator.js";
var s = /* @__PURE__ */ E(U(), 1), e = q(), F = {
  xs: "h-7 px-3 py-1 text-xs [&_svg]:size-4 [@media(pointer:coarse)]:min-h-11",
  sm: "h-8 px-3 py-1.5 text-xs [&_svg]:size-[18px] [@media(pointer:coarse)]:min-h-11",
  md: "h-9 px-3 py-2 text-xs [&_svg]:size-5",
  lg: "h-10 px-3 py-2.5 text-sm [&_svg]:size-5"
}, T = s.forwardRef(({ className: a, children: r, ...t }, o) => /* @__PURE__ */ (0, e.jsx)("span", {
  ref: o,
  "data-slot": "select-trigger-icon",
  className: c("shrink-0 text-muted-foreground", a),
  ...t,
  children: r
}));
T.displayName = "SelectTrigger.Icon";
function be(a) {
  const r = {};
  let t = !1;
  function o(n) {
    s.Children.forEach(n, (l) => {
      if (!s.isValidElement(l)) return;
      const i = l.props;
      if (i.value != null) {
        r[String(i.value)] = i.children, t = !0;
        return;
      }
      i.children != null && o(i.children);
    });
  }
  return o(a), t ? r : void 0;
}
function x({ trigger: a, value: r, defaultValue: t, onValueChange: o, items: n, children: l, ...i }) {
  const [p, u] = le({
    value: r,
    defaultValue: t ?? "",
    onChange: o
  }), m = s.useCallback((b) => {
    u(b);
  }, [u]), d = n ?? be(l);
  return /* @__PURE__ */ (0, e.jsxs)(Q, {
    value: p,
    onValueChange: m,
    items: d,
    ...i,
    children: [a && /* @__PURE__ */ (0, e.jsx)(g, { render: a }), l]
  });
}
var B = s.forwardRef(({ className: a, ...r }, t) => /* @__PURE__ */ (0, e.jsx)(Z, {
  ref: t,
  "data-slot": "select-group",
  className: c("scroll-my-1 p-1", a),
  ...r
}));
B.displayName = "Select.Group";
var h = s.forwardRef(({ placeholder: a, children: r, className: t, ...o }, n) => /* @__PURE__ */ (0, e.jsx)(te, {
  ref: n,
  "data-slot": "select-value",
  className: c("flex flex-1 text-left", t),
  placeholder: !r && a ? /* @__PURE__ */ (0, e.jsx)("span", {
    className: "text-muted-foreground",
    children: a
  }) : void 0,
  ...o,
  children: r
}));
h.displayName = "Select.Value";
var g = s.forwardRef(({ className: a, size: r = "md", shape: t = "rounded", state: o = "default", readOnly: n = !1, children: l, "aria-label": i, ...p }, u) => {
  let m = i;
  return m || s.Children.forEach(l, (d) => {
    s.isValidElement(d) && typeof d.props == "object" && d.props !== null && "placeholder" in d.props && typeof d.props.placeholder == "string" && (m = d.props.placeholder);
  }), n ? /* @__PURE__ */ (0, e.jsx)("output", {
    ref: u,
    "data-slot": "select-trigger",
    "data-readonly": !0,
    "data-size": r,
    "data-shape": t,
    className: c("flex w-full items-center gap-1.5 bg-transparent", F[r], t === "rounded" && "rounded-xl", t === "round" && "rounded-full", "text-foreground", a),
    children: l
  }) : /* @__PURE__ */ (0, e.jsxs)(Y, {
    ref: u,
    "data-slot": "select-trigger",
    "data-size": r,
    "data-shape": t,
    "data-state": o,
    "aria-label": m,
    "aria-invalid": o === "error" || void 0,
    className: c("group/select flex w-full items-center justify-between gap-1.5 outline-none", "bg-background border shadow-xs transition-[color,box-shadow,border-color] duration-200 ease-smooth motion-reduce:transition-none", "disabled:cursor-not-allowed disabled:opacity-50", "*:data-[slot=select-value]:flex *:data-[slot=select-value]:flex-1 *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5", "*:data-[slot=select-value]:overflow-hidden *:data-[slot=select-value]:text-ellipsis *:data-[slot=select-value]:whitespace-nowrap", "data-[placeholder]:text-muted-foreground", F[r], t === "rounded" && "rounded-xl", t === "round" && "rounded-full", o === "default" && "border-input", o === "success" && "border-success", o === "error" && "border-destructive", "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]", o === "error" && "focus-visible:ring-destructive/20", a),
    ...p,
    children: [l, /* @__PURE__ */ (0, e.jsx)(O, { render: /* @__PURE__ */ (0, e.jsx)(I, { className: "size-4 shrink-0 text-muted-foreground transition-transform duration-200 ease-smooth group-data-[popup-open]/select:rotate-180 motion-reduce:transition-none" }) })]
  });
});
g.displayName = "Select.Trigger";
var S = s.forwardRef(({ className: a, children: r, side: t = "bottom", sideOffset: o = 4, align: n = "center", alignOffset: l = 0, alignItemWithTrigger: i = !0, ...p }, u) => /* @__PURE__ */ (0, e.jsx)(K, { children: /* @__PURE__ */ (0, e.jsx)(se, {
  side: t,
  sideOffset: o,
  align: n,
  alignOffset: l,
  alignItemWithTrigger: i,
  className: "isolate z-50",
  children: /* @__PURE__ */ (0, e.jsxs)(X, {
    ref: u,
    "data-slot": "select-popup",
    className: c("bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 motion-reduce:animate-none ring-foreground/10 min-w-36 rounded-md shadow-md ring-1 duration-100 relative isolate z-50 max-h-(--available-height) w-(--anchor-width) origin-(--transform-origin) overflow-x-hidden overflow-y-auto", a),
    ...p,
    children: [
      /* @__PURE__ */ (0, e.jsx)(_, {}),
      /* @__PURE__ */ (0, e.jsx)(J, { children: r }),
      /* @__PURE__ */ (0, e.jsx)(z, {})
    ]
  })
}) }));
S.displayName = "Select.Popup";
var G = s.forwardRef(({ className: a, ...r }, t) => /* @__PURE__ */ (0, e.jsx)(oe, {
  ref: t,
  "data-slot": "select-group-label",
  className: c("text-muted-foreground px-2 py-1.5 text-xs", a),
  ...r
}));
G.displayName = "Select.GroupLabel";
var V = s.forwardRef(({ className: a, children: r, ...t }, o) => /* @__PURE__ */ (0, e.jsxs)(re, {
  ref: o,
  "data-slot": "select-item",
  className: c("focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground gap-2 rounded-sm py-1.5 pe-8 ps-2 text-sm [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2 relative flex w-full cursor-default items-center outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0", a),
  ...t,
  children: [/* @__PURE__ */ (0, e.jsx)(H, {
    className: "flex flex-1 gap-2 shrink-0 whitespace-nowrap",
    children: r
  }), /* @__PURE__ */ (0, e.jsx)(ee, {
    render: /* @__PURE__ */ (0, e.jsx)("span", { className: "pointer-events-none absolute end-2 flex size-4 items-center justify-center" }),
    children: /* @__PURE__ */ (0, e.jsx)(A, { className: "pointer-events-none" })
  })]
}));
V.displayName = "Select.Item";
var k = s.forwardRef(({ className: a, ...r }, t) => /* @__PURE__ */ (0, e.jsx)(Se, {
  ref: t,
  "data-slot": "select-separator",
  className: c("bg-border -mx-1 my-1 h-px pointer-events-none", a),
  ...r
}));
k.displayName = "Select.Separator";
var _ = s.forwardRef(({ className: a, ...r }, t) => /* @__PURE__ */ (0, e.jsx)(ae, {
  ref: t,
  "data-slot": "select-scroll-up-button",
  className: c("bg-popover z-10 flex cursor-default items-center justify-center py-1 [&_svg:not([class*='size-'])]:size-4 top-0 w-full", a),
  ...r,
  children: /* @__PURE__ */ (0, e.jsx)(M, {})
}));
_.displayName = "Select.ScrollUpButton";
var z = s.forwardRef(({ className: a, ...r }, t) => /* @__PURE__ */ (0, e.jsx)(W, {
  ref: t,
  "data-slot": "select-scroll-down-button",
  className: c("bg-popover z-10 flex cursor-default items-center justify-center py-1 [&_svg:not([class*='size-'])]:size-4 bottom-0 w-full", a),
  ...r,
  children: /* @__PURE__ */ (0, e.jsx)(I, {})
}));
z.displayName = "Select.ScrollDownButton";
x.displayName = "SelectRoot";
function je({ placeholder: a, size: r = "md", shape: t = "rounded", readOnly: o = !1, value: n, defaultValue: l, onValueChange: i, disabled: p, children: u, className: m, name: d, ...b }) {
  const [v, we] = ne(b);
  if (!de(v)) return /* @__PURE__ */ (0, e.jsxs)(x, {
    value: n,
    defaultValue: l,
    onValueChange: i,
    disabled: p,
    name: d,
    children: [/* @__PURE__ */ (0, e.jsx)(g, {
      size: r,
      shape: t,
      readOnly: o,
      state: v.error ? "error" : "default",
      className: m,
      "aria-label": a,
      children: /* @__PURE__ */ (0, e.jsx)(h, { placeholder: a })
    }), !o && /* @__PURE__ */ (0, e.jsx)(S, { children: u })]
  });
  const { label: j, error: f, description: w, tooltip: C, labelIcon: L, topRight: y, bottomRight: N, fieldClassName: P } = v, $ = j || y, D = w || N || f;
  return /* @__PURE__ */ (0, e.jsxs)(he, {
    state: f ? "destructive" : void 0,
    disabled: p,
    className: P,
    children: [
      $ && /* @__PURE__ */ (0, e.jsxs)(ue, { children: [j && /* @__PURE__ */ (0, e.jsxs)(ve, {
        required: v.required,
        labelIcon: L,
        children: [j, C && /* @__PURE__ */ (0, e.jsx)(ie, { content: C })]
      }), y && /* @__PURE__ */ (0, e.jsx)(me, { children: y })] }),
      /* @__PURE__ */ (0, e.jsx)(pe, { children: (R) => /* @__PURE__ */ (0, e.jsxs)(x, {
        value: n,
        defaultValue: l,
        onValueChange: i,
        disabled: p,
        name: d,
        children: [/* @__PURE__ */ (0, e.jsx)(g, {
          id: R.id,
          "aria-describedby": R["aria-describedby"],
          "aria-invalid": R["aria-invalid"],
          size: r,
          shape: t,
          readOnly: o,
          state: f ? "error" : "default",
          className: m,
          "aria-label": a,
          children: /* @__PURE__ */ (0, e.jsx)(h, { placeholder: a })
        }), !o && /* @__PURE__ */ (0, e.jsx)(S, { children: u })]
      }) }),
      D && /* @__PURE__ */ (0, e.jsxs)(fe, { children: [
        f && /* @__PURE__ */ (0, e.jsx)(xe, { children: f }),
        !f && w && /* @__PURE__ */ (0, e.jsx)(ce, { children: w }),
        N && /* @__PURE__ */ (0, e.jsx)(ge, {
          className: "ms-auto",
          children: N
        })
      ] })
    ]
  });
}
je.displayName = "Select";
var ke = Object.assign(x, {
  Root: x,
  Group: B,
  Value: h,
  Trigger: Object.assign(g, { Icon: T }),
  Popup: S,
  GroupLabel: G,
  Item: V,
  Separator: k,
  ScrollUpButton: _,
  ScrollDownButton: z
});
export {
  g as a,
  x as i,
  V as n,
  h as o,
  S as r,
  je as t
};

//# sourceMappingURL=Select.js.map