import { jsx as l, jsxs as b } from "react/jsx-runtime";
import { forwardRef as S, useId as z } from "react";
import { F as j } from "./field-error-text-CBSX8dGx.mjs";
import { F as L } from "./field-helper-text-C5ee4SFV.mjs";
import { r as h } from "./check-circle-filled.es-umBwOv5_.mjs";
import { l as N } from "./chevron-down.es-PCIIj6oG.mjs";
import { L as q } from "./label-7sJe5-pX.mjs";
import { a as E } from "./spinner-DRQN6YdK.mjs";
import { c as H } from "./bind-CU-R61T-.mjs";
const K = {
  "purpur-select": "_purpur-select_1gf3p_1",
  "purpur-select__label": "_purpur-select__label_1gf3p_7",
  "purpur-select__field-row": "_purpur-select__field-row_1gf3p_12",
  "purpur-select__frame": "_purpur-select__frame_1gf3p_16",
  "purpur-select__frame--negative": "_purpur-select__frame--negative_1gf3p_23",
  "purpur-select__select-container": "_purpur-select__select-container_1gf3p_26",
  "purpur-select__select-container--disabled": "_purpur-select__select-container--disabled_1gf3p_33",
  "purpur-select__select": "_purpur-select__select_1gf3p_26",
  "purpur-select__select-container--readonly": "_purpur-select__select-container--readonly_1gf3p_33",
  "purpur-select__select-container--negative": "_purpur-select__select-container--negative_1gf3p_41",
  "purpur-select__select--error": "_purpur-select__select--error_1gf3p_91",
  "purpur-select__select--is-valid": "_purpur-select__select--is-valid_1gf3p_97",
  "purpur-select__select--negative": "_purpur-select__select--negative_1gf3p_103",
  "purpur-select__end-adornments": "_purpur-select__end-adornments_1gf3p_120",
  "purpur-select__select-icon": "_purpur-select__select-icon_1gf3p_130",
  "purpur-select__select-icon--readonly": "_purpur-select__select-icon--readonly_1gf3p_133",
  "purpur-select__select-icon--disabled": "_purpur-select__select-icon--disabled_1gf3p_133",
  "purpur-select__select-icon--negative": "_purpur-select__select-icon--negative_1gf3p_136",
  "purpur-select__valid-icon": "_purpur-select__valid-icon_1gf3p_142"
}, a = H.bind(K), e = "purpur-select", R = S(
  ({
    label: r,
    options: n,
    className: p,
    errorText: s,
    helperText: u,
    negative: i = !1,
    placeholder: d,
    readOnly: c = !1,
    ["data-testid"]: $,
    valid: w,
    loading: x,
    ..._
  }, C) => {
    const t = (f) => $ ? `${$}-${f}` : void 0, o = w && !s, F = z(), m = _.id ?? F, v = u ? `${m}-helper-text` : void 0, I = a(`${e}__select-container`, {
      [`${e}__select-container--disabled`]: _.disabled,
      [`${e}__select-container--readonly`]: c && !_.disabled,
      [`${e}__select-container--negative`]: i
    });
    return N, a(`${e}__select-icon`, {
      [`${e}__select-icon--disabled`]: _.disabled,
      [`${e}__select-icon--readonly`]: c && !_.disabled,
      [`${e}__select-icon--is-valid`]: o,
      [`${e}__select-icon--negative`]: i
    }), t("dropdown-icon"), o && (h, t("valid-icon"), a(`${e}__valid-icon`)), /* @__PURE__ */ b(
      "div",
      {
        className: a(e, p, {
          [`${e}--negative`]: i
        }),
        children: [
          r && /* @__PURE__ */ b(
            q,
            {
              htmlFor: m,
              className: a(`${e}__label`),
              "data-testid": t("label"),
              disabled: _.disabled,
              negative: i,
              children: [
                _.required && /* @__PURE__ */ l("span", { "aria-hidden": !0, children: "*" }),
                r
              ]
            }
          ),
          /* @__PURE__ */ l("div", { className: a(`${e}__field-row`), children: /* @__PURE__ */ b("div", { className: I, children: [
            /* @__PURE__ */ b(
              "select",
              {
                ..._,
                onChange: c ? void 0 : _?.onChange,
                id: m,
                ref: C,
                "data-testid": t("select"),
                "aria-describedby": _["aria-describedby"] || v,
                "aria-invalid": _["aria-invalid"] || !!s,
                "aria-disabled": _["aria-disabled"] || _.disabled,
                "aria-readonly": _["aria-readonly"] || c && !_.disabled,
                className: a(`${e}__select`, {
                  [`${e}__select--error`]: !!s,
                  [`${e}__select--is-valid`]: o,
                  [`${e}__select--negative`]: i
                }),
                children: [
                  d && /* @__PURE__ */ l("option", { value: d.value ?? d.label, disabled: !0, children: d.label }),
                  n.map(
                    (f, g) => V(f) ? k(f, m, g, c) : y(f, m, g, c)
                  )
                ]
              }
            ),
            /* @__PURE__ */ b("div", { className: a(`${e}__end-adornments`), children: [
              x ? /* @__PURE__ */ l(
                E,
                {
                  disabled: _.disabled,
                  size: "xxs",
                  negative: i,
                  "data-testid": t("spinner")
                },
                "spinner"
              ) : /* @__PURE__ */ l(
                N,
                {
                  className: a(`${e}__select-icon`, {
                    [`${e}__select-icon--disabled`]: _.disabled,
                    [`${e}__select-icon--readonly`]: c && !_.disabled,
                    [`${e}__select-icon--is-valid`]: o,
                    [`${e}__select-icon--negative`]: i
                  }),
                  "data-testid": t("dropdown-icon"),
                  size: "sm"
                },
                "chevron-down-icon"
              ),
              o && /* @__PURE__ */ l(
                h,
                {
                  "data-testid": t("valid-icon"),
                  className: a(`${e}__valid-icon`)
                },
                "valid-icon"
              )
            ] }),
            /* @__PURE__ */ l(
              "div",
              {
                className: a(`${e}__frame`, {
                  [`${e}__frame--negative`]: i
                })
              }
            )
          ] }) }),
          v && /* @__PURE__ */ l(
            L,
            {
              disabled: _.disabled,
              "data-testid": t("helper-text"),
              id: v,
              negative: i,
              children: u
            }
          ),
          s && /* @__PURE__ */ l(j, { negative: i, "data-testid": t("error-text"), children: s })
        ]
      }
    );
  }
), V = (r) => r.hasOwnProperty("options"), k = (r, n, p, s) => {
  const u = `${n}--group--${p}`;
  return /* @__PURE__ */ l("optgroup", { label: r.label, children: r.options.map((i, d) => y(i, u, d, s)) }, u);
}, y = (r, n, p, s) => /* @__PURE__ */ l(
  "option",
  {
    value: r.value ?? r.label,
    disabled: s,
    children: r.label
  },
  `${n}--option--${p}`
);
R.displayName = "Select";
export {
  R as S
};
//# sourceMappingURL=select-BEmu_fh9.mjs.map
