"use client";
import { jsxs as m, jsx as a } from "react/jsx-runtime";
import { CaretUpDownIcon as H, CheckIcon as J } from "@phosphor-icons/react";
import { useId as Q, forwardRef as g } from "react";
import { b as X } from "./button-ebfdg9mkhojue36n.js";
import { K as Y } from "./input-ckl5misj0jd9cu5r.js";
import { S as Z } from "./skeleton-line-omxgxia23vpav94x.js";
import { L as q } from "./label-i1xbmg8y1n0tbtkx.js";
import { F as ee } from "./field-bmglk138wa8bf3ei.js";
import { u as te } from "./portal-provider-hwmkdmkpvct0cb76.js";
import { c as l } from "./vendor-styling-ofvnbcuht98q88oo.js";
import { b4 as ae, b5 as oe, b6 as se, b7 as ne, b8 as le, b9 as ie, ba as re, bb as ce, bc as de, bd as ue, be as me, bf as be, bg as fe, bh as pe, S as ge } from "./vendor-base-ui-elpbzr8xeffrz4h2.js";
Y.size;
const A = {
  size: "base"
};
function he({
  size: e = A.size
} = {}) {
  return l(
    X({ size: e }),
    "justify-between font-normal",
    "focus:opacity-100 focus:ring-kumo-focus/50 focus-visible:ring-inset *:in-focus:opacity-100"
  );
}
const z = {
  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 O(e) {
  if (e == null || typeof e != "object" || Array.isArray(e) || "$$typeof" in e || e instanceof Promise) return !1;
  const o = e;
  return "label" in o && o.label !== void 0;
}
function C(e) {
  return Array.isArray(e) ? e : Object.entries(e).map(([o, s]) => ({
    value: o,
    label: O(s) ? s.label : s
  }));
}
function Se(e) {
  const o = C(e), s = /* @__PURE__ */ new Map();
  if (!Array.isArray(e))
    for (const [t, i] of Object.entries(e))
      O(i) && s.set(t, { disabled: i.disabled });
  return o.filter((t) => t.value !== null).map((t, i) => {
    const c = typeof t.value == "string" ? t.value : `option-${i}`, u = typeof t.value == "string" ? s.get(t.value) : void 0;
    return /* @__PURE__ */ a(F, { value: t.value, disabled: u?.disabled, children: t.label }, c);
  });
}
function d({
  children: e,
  className: o,
  renderValue: s,
  label: t,
  hideLabel: i,
  placeholder: c,
  loading: u,
  size: b = A.size,
  labelTooltip: h,
  description: f,
  error: n,
  required: S,
  container: _,
  ...r
}) {
  const y = Q(), E = te(), T = _ ?? E ?? void 0, x = r, U = x["aria-label"], V = x["aria-labelledby"], D = typeof t == "string" ? t : c;
  process.env.NODE_ENV !== "production" && i !== 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 N = t && i !== !0, k = N ? void 0 : V ?? (t ? y : void 0), K = U ?? (k ? void 0 : D), M = r.items ? C(r.items) : void 0, R = e || (r.items ? Se(r.items) : null), $ = s ? (p) => {
    const I = c != null ? /* @__PURE__ */ a("span", { className: "text-kumo-placeholder", children: c }) : null;
    if (p == null || p === "")
      return I;
    const w = s(p);
    return w ?? I;
  } : void 0, { items: ye, ...B } = r, W = t ? /* @__PURE__ */ a(de, { className: "m-0 select-none text-base font-medium text-kumo-default", children: /* @__PURE__ */ a(
    q,
    {
      showOptional: S === !1,
      tooltip: i ? void 0 : h,
      asContent: !0,
      children: t
    }
  ) }) : null, v = /* @__PURE__ */ m(
    ae,
    {
      ...B,
      items: M,
      disabled: u || r.disabled,
      children: [
        W,
        /* @__PURE__ */ m(
          oe,
          {
            "data-kumo-component": "Select",
            "data-kumo-part": "trigger",
            className: l(
              he({ size: b }),
              r.disabled && "cursor-not-allowed opacity-50",
              n && "!ring-kumo-danger focus:ring-kumo-danger/50 focus:ring-[1.5px]",
              o
            ),
            "aria-label": K,
            "aria-labelledby": k,
            children: [
              u ? /* @__PURE__ */ a(Z, { className: "w-32" }) : /* @__PURE__ */ a(
                se,
                {
                  placeholder: c,
                  className: "min-w-0 truncate data-[placeholder]:text-kumo-placeholder",
                  children: $
                }
              ),
              /* @__PURE__ */ a(
                ne,
                {
                  className: l(
                    "flex shrink-0 items-center",
                    z[b].className
                  ),
                  children: /* @__PURE__ */ a(
                    H,
                    {
                      size: z[b].iconSize,
                      className: "fill-current"
                    }
                  )
                }
              )
            ]
          }
        ),
        /* @__PURE__ */ a(le, { container: T, children: /* @__PURE__ */ a(ie, { children: /* @__PURE__ */ a(
          re,
          {
            className: l(
              "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(
              ce,
              {
                className: l(
                  "min-h-0 flex-1 overflow-y-auto overscroll-none scroll-pt-2 scroll-pb-2"
                ),
                children: R
              }
            )
          }
        ) }) })
      ]
    }
  );
  if (N)
    return /* @__PURE__ */ a(
      ee,
      {
        label: t,
        required: S,
        labelTooltip: h,
        description: f,
        error: n ? typeof n == "string" ? { message: n, match: !0 } : n : void 0,
        hideLabel: !0,
        children: v
      }
    );
  const L = n ? typeof n == "string" ? { message: n } : n : void 0;
  return /* @__PURE__ */ m("div", { className: "grid gap-2", children: [
    t && /* @__PURE__ */ a("span", { id: y, className: "sr-only", children: t }),
    v,
    L ? /* @__PURE__ */ a("span", { className: "text-sm text-kumo-danger", children: L.message }) : f && /* @__PURE__ */ a("span", { className: "text-sm leading-snug text-kumo-subtle", children: f })
  ] });
}
function F({ children: e, value: o, disabled: s, className: t }) {
  return /* @__PURE__ */ m(
    ue,
    {
      "data-kumo-component": "Select",
      "data-kumo-part": "option",
      value: o,
      disabled: s,
      className: l(
        "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(me, { children: e }),
        /* @__PURE__ */ a(be, { children: /* @__PURE__ */ a(J, {}) })
      ]
    }
  );
}
const G = g(
  ({ children: e, className: o }, s) => /* @__PURE__ */ a(fe, { ref: s, className: l(o), children: e })
);
G.displayName = "Select.Group";
const j = g(
  ({ children: e, className: o }, s) => /* @__PURE__ */ a(
    pe,
    {
      ref: s,
      className: l(
        "px-3.5 py-1.5 text-sm font-semibold text-kumo-subtle",
        o
      ),
      children: e
    }
  )
);
j.displayName = "Select.GroupLabel";
const P = g(
  ({ className: e }, o) => /* @__PURE__ */ a(
    ge,
    {
      ref: o,
      className: l("-mx-1 my-1 h-px bg-kumo-hairline", e)
    }
  )
);
P.displayName = "Select.Separator";
d.Option = F;
d.Group = G;
d.GroupLabel = j;
d.Separator = P;
d.Option.displayName = "Select.Option";
export {
  d as S
};
//# sourceMappingURL=select-p8adn2tnpom25hpl.js.map
