import { jsx as e, jsxs as f } from "react/jsx-runtime";
import b from "react";
import { Select as x, SelectTrigger as y, SelectValue as S, SelectContent as N, SelectGroup as $, SelectLabel as g, SelectItem as V } from "./SelectPrimitives.js";
import { c as s } from "../../index-BtlgVD4m.js";
import z from "../box/Box.js";
import w from "../text/Text.js";
import j from "./utils/isSelectGroup.js";
import o from "./utils/isValidValue.js";
const d = (r, a) => /* @__PURE__ */ e(V, { value: String(a.value), disabled: a.disabled, children: a.label }, r), C = (r, a) => {
  const { label: n, value: l, children: m } = r;
  return j(r) ? /* @__PURE__ */ f(b.Fragment, { children: [
    /* @__PURE__ */ e(g, { children: n }),
    m.map((c, t) => {
      const { value: i } = c;
      return o(i) ? d(`child-${i}-${t}`, c) : null;
    })
  ] }, `group-${n}-${a}`) : o(l) ? d(`item-${l}-${a}`, r) : null;
}, G = ({
  ref: r,
  label: a,
  description: n,
  options: l,
  placeholder: m,
  disabled: c,
  errorMessage: t,
  size: i = "default",
  onChange: h,
  isPortal: u = !0,
  isError: p,
  ...v
}) => /* @__PURE__ */ e(x, { onValueChange: h, ...v, children: /* @__PURE__ */ f("div", { className: "flex flex-col gap-[var(--spacing-2)]", children: [
  a && /* @__PURE__ */ e(
    "label",
    {
      className: s(
        "font-[family-name:var(--typography-font-family-font-sans)]",
        "text-[length:var(--typography-base-sizes-small-font-size)]",
        "text-[var(--base-foreground)]",
        "font-[var(--font-weight-medium)] leading-none",
        !!t && "text-[var(--base-danger-text)]"
      ),
      children: a
    }
  ),
  /* @__PURE__ */ e(
    y,
    {
      ref: r,
      size: i,
      className: s((!!t || p) && "ring-1 ring-[var(--base-danger-border)] focus:ring-[var(--base-danger-border)]"),
      disabled: c,
      children: /* @__PURE__ */ e(S, { placeholder: m })
    }
  ),
  n && /* @__PURE__ */ e(z, { className: "flex items-center", children: /* @__PURE__ */ e(w, { type: "muted", weight: "regular", children: n }) }),
  t && /* @__PURE__ */ e(
    "p",
    {
      className: s(
        "text-[var(--base-danger-text)]",
        "text-[length:var(--typography-base-sizes-extra-small-font-size)]",
        "font-[family-name:var(--typography-font-family-font-sans)]",
        "font-[var(--font-weight-normal)]",
        "leading-none"
      ),
      children: t
    }
  ),
  /* @__PURE__ */ e(N, { className: "bg-[var(--base-popover)] border-[var(--base-border)]", isPortal: u, children: /* @__PURE__ */ e($, { children: l != null && l.length ? l.map(C) : /* @__PURE__ */ e(g, { children: "No options available" }) }) })
] }) });
G.displayName = "Select";
export {
  G as default
};
//# sourceMappingURL=Select.js.map
