"use strict";const _=require("react/jsx-runtime"),g=require("react"),F=require("./field-error-text-FhQulSV5.js"),S=require("./field-helper-text-DSKO-Tce.js"),x=require("./check-circle-filled.es-5-GXE9l4.js"),h=require("./chevron-down.es-BMjgiS3F.js"),z=require("./label-yHK80hhV.js"),R=require("./spinner-tKunS_o-.js"),E=require("./bind-DeUYJ6m9.js"),H={"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"},r=E.c.bind(H),e="purpur-select",j=g.forwardRef(({label:i,options:n,className:u,errorText:t,helperText:p,negative:l=!1,placeholder:d,readOnly:a=!1,["data-testid"]:$,valid:q,loading:w,...s},y)=>{const c=f=>$?`${$}-${f}`:void 0,o=q&&!t,C=g.useId(),b=s.id??C,v=p?`${b}-helper-text`:void 0,I=r(`${e}__select-container`,{[`${e}__select-container--disabled`]:s.disabled,[`${e}__select-container--readonly`]:a&&!s.disabled,[`${e}__select-container--negative`]:l});return h.l,r(`${e}__select-icon`,{[`${e}__select-icon--disabled`]:s.disabled,[`${e}__select-icon--readonly`]:a&&!s.disabled,[`${e}__select-icon--is-valid`]:o,[`${e}__select-icon--negative`]:l}),c("dropdown-icon"),o&&(x.r,c("valid-icon"),r(`${e}__valid-icon`)),_.jsxs("div",{className:r(e,u,{[`${e}--negative`]:l}),children:[i&&_.jsxs(z.Label,{htmlFor:b,className:r(`${e}__label`),"data-testid":c("label"),disabled:s.disabled,negative:l,children:[s.required&&_.jsx("span",{"aria-hidden":!0,children:"*"}),i]}),_.jsx("div",{className:r(`${e}__field-row`),children:_.jsxs("div",{className:I,children:[_.jsxs("select",{...s,onChange:a?void 0:s?.onChange,id:b,ref:y,"data-testid":c("select"),"aria-describedby":s["aria-describedby"]||v,"aria-invalid":s["aria-invalid"]||!!t,"aria-disabled":s["aria-disabled"]||s.disabled,"aria-readonly":s["aria-readonly"]||a&&!s.disabled,className:r(`${e}__select`,{[`${e}__select--error`]:!!t,[`${e}__select--is-valid`]:o,[`${e}__select--negative`]:l}),children:[d&&_.jsx("option",{value:d.value??d.label,disabled:!0,children:d.label}),n.map((f,m)=>k(f)?D(f,b,m,a):N(f,b,m,a))]}),_.jsxs("div",{className:r(`${e}__end-adornments`),children:[w?_.jsx(R.Spinner,{disabled:s.disabled,size:"xxs",negative:l,"data-testid":c("spinner")},"spinner"):_.jsx(h.l,{className:r(`${e}__select-icon`,{[`${e}__select-icon--disabled`]:s.disabled,[`${e}__select-icon--readonly`]:a&&!s.disabled,[`${e}__select-icon--is-valid`]:o,[`${e}__select-icon--negative`]:l}),"data-testid":c("dropdown-icon"),size:"sm"},"chevron-down-icon"),o&&_.jsx(x.r,{"data-testid":c("valid-icon"),className:r(`${e}__valid-icon`)},"valid-icon")]}),_.jsx("div",{className:r(`${e}__frame`,{[`${e}__frame--negative`]:l})})]})}),v&&_.jsx(S.FieldHelperText,{disabled:s.disabled,"data-testid":c("helper-text"),id:v,negative:l,children:p}),t&&_.jsx(F.FieldErrorText,{negative:l,"data-testid":c("error-text"),children:t})]})}),k=i=>i.hasOwnProperty("options"),D=(i,n,u,t)=>{const p=`${n}--group--${u}`;return _.jsx("optgroup",{label:i.label,children:i.options.map((l,d)=>N(l,p,d,t))},p)},N=(i,n,u,t)=>_.jsx("option",{value:i.value??i.label,disabled:t,children:i.label},`${n}--option--${u}`);j.displayName="Select";exports.Select=j;
//# sourceMappingURL=select-DOqTJgTj.js.map
