"use client";
import { jsxs as m, jsx as a } from "react/jsx-runtime";
import { CaretUpDownIcon as R, CheckIcon as B } from "@phosphor-icons/react";
import { useId as W, forwardRef as p } from "react";
import { c as o } from "./cn-ct4n7r74mh8y0f48.js";
import { b as q } from "./button-6by9ntsa3nj553mq.js";
import { K as H } from "./input-lpa5fc75tgrraafv.js";
import { S as J } from "./skeleton-line-epxenksfesr2fkcv.js";
import { F as Q } from "./field-lnj619xpe8zjd26r.js";
import { u as X } from "./portal-provider-hwmkdmkpvct0cb76.js";
import { a$ as Y, b0 as Z, b1 as ee, b2 as te, b3 as ae, b4 as se, b5 as le, b6 as oe, b7 as ie, b8 as ne, b9 as re, ba as ce, bb as de, S as ue } from "./vendor-base-ui-ie71jahf0czyf58j.js";
H.size;
const I = {
  size: "base"
};
function me({
  size: e = I.size
} = {}) {
  return o(
    q({ size: e }),
    "justify-between font-normal",
    "focus:opacity-100 focus:ring-kumo-focus/50 focus-visible:ring-inset *:in-focus:opacity-100"
  );
}
const k = {
  xs: { iconSize: 12, className: "text-kumo-subtle" },
  sm: { iconSize: 14, className: "text-kumo-subtle" },
  base: { iconSize: 16, className: "text-kumo-subtle" },
  lg: { iconSize: 18, className: "text-kumo-subtle" }
};
function L(e) {
  if (e == null || typeof e != "object" || Array.isArray(e) || "$$typeof" in e || e instanceof Promise) return !1;
  const s = e;
  return "label" in s && s.label !== void 0;
}
function w(e) {
  return Array.isArray(e) ? e : Object.entries(e).map(([s, l]) => ({
    value: s,
    label: L(l) ? l.label : l
  }));
}
function be(e) {
  const s = w(e), l = /* @__PURE__ */ new Map();
  if (!Array.isArray(e))
    for (const [t, r] of Object.entries(e))
      L(r) && l.set(t, { disabled: r.disabled });
  return s.filter((t) => t.value !== null).map((t, r) => {
    const c = typeof t.value == "string" ? t.value : `option-${r}`, u = typeof t.value == "string" ? l.get(t.value) : void 0;
    return /* @__PURE__ */ a(z, { value: t.value, disabled: u?.disabled, children: t.label }, c);
  });
}
function d({
  children: e,
  className: s,
  renderValue: l,
  label: t,
  hideLabel: r,
  placeholder: c,
  loading: u,
  size: b = I.size,
  labelTooltip: F,
  description: f,
  error: i,
  required: G,
  container: j,
  ...n
}) {
  const g = W(), P = X(), T = j ?? P ?? void 0, S = n, _ = S["aria-label"], E = S["aria-labelledby"], U = typeof t == "string" ? t : c;
  process.env.NODE_ENV !== "production" && r !== void 0 && console.warn(
    '[Kumo Select]: `hideLabel` is deprecated. For hidden labels, use `aria-label` instead of `label` + `hideLabel={true}`.\n  Migration:\n  - For visible labels: <Select label="Country" /> (hideLabel no longer needed)\n  - For hidden labels: <Select aria-label="Select a country" /> (remove label and hideLabel)'
  );
  const h = t && r !== !0, y = h ? void 0 : E ?? (t ? g : void 0), V = _ ?? (y ? void 0 : U), $ = n.items ? w(n.items) : void 0, D = e || (n.items ? be(n.items) : null), K = l ? (v) => v == null ? c == null ? null : /* @__PURE__ */ a("span", { className: "text-kumo-placeholder", children: c }) : l(v) : void 0, { items: fe, ...M } = n, x = /* @__PURE__ */ m(
    Y,
    {
      ...M,
      items: $,
      disabled: u || n.disabled,
      children: [
        /* @__PURE__ */ m(
          Z,
          {
            className: o(
              me({ size: b }),
              n.disabled && "cursor-not-allowed opacity-50",
              s
            ),
            "aria-label": V,
            "aria-labelledby": y,
            children: [
              u ? /* @__PURE__ */ a(J, { className: "w-32" }) : /* @__PURE__ */ a(
                ee,
                {
                  placeholder: c,
                  className: "min-w-0 truncate data-[placeholder]:text-kumo-placeholder",
                  children: K
                }
              ),
              /* @__PURE__ */ a(
                te,
                {
                  className: o(
                    "flex shrink-0 items-center",
                    k[b].className
                  ),
                  children: /* @__PURE__ */ a(
                    R,
                    {
                      size: k[b].iconSize,
                      className: "fill-current"
                    }
                  )
                }
              )
            ]
          }
        ),
        /* @__PURE__ */ a(ae, { container: T, children: /* @__PURE__ */ a(se, { children: /* @__PURE__ */ a(
          le,
          {
            className: o(
              "flex flex-col",
              "max-h-[var(--available-height)] bg-kumo-base text-kumo-default",
              "rounded-lg shadow-lg ring ring-kumo-line",
              "min-w-[calc(var(--anchor-width)+3px)] py-1.5"
            ),
            children: /* @__PURE__ */ a(
              oe,
              {
                className: o(
                  "min-h-0 flex-1 overflow-y-auto overscroll-none scroll-pt-2 scroll-pb-2"
                ),
                children: D
              }
            )
          }
        ) }) })
      ]
    }
  );
  if (h)
    return /* @__PURE__ */ a(
      Q,
      {
        label: t,
        required: G,
        labelTooltip: F,
        description: f,
        error: i ? typeof i == "string" ? { message: i, match: !0 } : i : void 0,
        children: x
      }
    );
  const N = i ? typeof i == "string" ? { message: i } : i : void 0;
  return /* @__PURE__ */ m("div", { className: "grid gap-2", children: [
    t && /* @__PURE__ */ a("span", { id: g, className: "sr-only", children: t }),
    x,
    N ? /* @__PURE__ */ a("span", { className: "text-sm text-kumo-danger", children: N.message }) : f && /* @__PURE__ */ a("span", { className: "text-sm leading-snug text-kumo-subtle", children: f })
  ] });
}
function z({ children: e, value: s, disabled: l, className: t }) {
  return /* @__PURE__ */ m(
    ie,
    {
      value: s,
      disabled: l,
      className: o(
        "group mx-1.5 flex cursor-pointer items-center justify-between gap-2 rounded px-2 py-1.5 text-base outline-none",
        "focus-visible:z-50 focus-visible:ring-2 focus-visible:ring-kumo-brand focus-visible:ring-inset",
        "data-highlighted:bg-kumo-tint",
        "data-[disabled]:pointer-events-none data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50",
        t
      ),
      children: [
        /* @__PURE__ */ a(ne, { children: e }),
        /* @__PURE__ */ a(re, { children: /* @__PURE__ */ a(B, {}) })
      ]
    }
  );
}
const A = p(
  ({ children: e, className: s }, l) => /* @__PURE__ */ a(ce, { ref: l, className: o(s), children: e })
);
A.displayName = "Select.Group";
const O = p(
  ({ children: e, className: s }, l) => /* @__PURE__ */ a(
    de,
    {
      ref: l,
      className: o(
        "px-3.5 py-1.5 text-sm font-semibold text-kumo-subtle",
        s
      ),
      children: e
    }
  )
);
O.displayName = "Select.GroupLabel";
const C = p(
  ({ className: e }, s) => /* @__PURE__ */ a(
    ue,
    {
      ref: s,
      className: o("-mx-1 my-1 h-px bg-kumo-hairline", e)
    }
  )
);
C.displayName = "Select.Separator";
d.Option = z;
d.Group = A;
d.GroupLabel = O;
d.Separator = C;
d.Option.displayName = "Select.Option";
export {
  d as S
};
//# sourceMappingURL=select-kpfbib9l8xrrmzpz.js.map
