"use strict";const e=require("react/jsx-runtime"),M=require("react"),E=require("@mui/material/Select"),h=require("@mui/material/MenuItem"),F=require("@mui/material/FormControl"),N=require("@mui/material/InputLabel"),R=require("@mui/material/FormHelperText"),B=require("@mui/material/ListItemIcon"),O=require("@mui/material/ListItemText"),G=require("@mui/material/CircularProgress"),K=require("@mui/material/OutlinedInput"),U=require("@mui/material/InputBase"),V=require("@mui/material/Chip"),l=require("@mui/material/Box"),_=require("@mui/icons-material/Search"),A=require("@mui/icons-material/Clear"),m=require("./types.cjs");function b({options:u,value:v,onChange:f,size:c="md",color:P="neutral",label:i,helperText:j,placeholder:t,searchable:d=!1,multiple:p=!1,loading:I=!1,error:s,fullWidth:w,disabled:L,clearable:q=!1,sx:z}){const[x,S]=M.useState(""),D=m.toMuiInputSize(c),g=m.toMuiColor(P),H=typeof s=="string"?!!s:s,y=typeof s=="string"?s:void 0,C=M.useMemo(()=>{if(!d||!x)return u;const r=x.toLowerCase();return u.filter(n=>n.label.toLowerCase().includes(r))},[u,x,d]),T=r=>{f(r.target.value)};return e.jsxs(F,{size:D,fullWidth:w,error:H,disabled:L,style:{"--ov-input-height":m.INPUT_HEIGHTS[c]},sx:z,children:[i&&e.jsx(N,{color:g==="default"||g==="inherit"?void 0:g,shrink:!!t||void 0,children:i}),e.jsxs(E,{value:v,onChange:T,multiple:p,displayEmpty:!!t,label:i,notched:i&&!!t||void 0,input:p?e.jsx(K,{label:i}):void 0,onClose:()=>{d&&S("")},renderValue:p?r=>{const n=r;return n.length===0&&t?e.jsx(l,{sx:{color:"var(--ov-fg-faint)"},children:t}):e.jsxs(l,{sx:{display:"flex",flexWrap:"nowrap",gap:.5,overflow:"hidden",alignItems:"center"},children:[n.map(o=>{const W=u.find(a=>a.value===o);return e.jsx(V,{label:W?.label??o,size:"small",...q?{onDelete:a=>{a.stopPropagation(),f(n.filter(k=>k!==o))},onMouseDown:a=>{a.stopPropagation()}}:{}},o)}),q&&n.length>1&&e.jsx("span",{role:"button","aria-label":"Clear all",onMouseDown:o=>{o.stopPropagation(),o.preventDefault(),f([])},style:{display:"inline-flex",alignItems:"center",flexShrink:0,marginLeft:2,cursor:"pointer",color:"var(--ov-fg-faint)",lineHeight:0},children:e.jsx(A,{sx:{fontSize:16}})})]})}:t&&!v?()=>e.jsx(l,{sx:{color:"var(--ov-fg-faint)"},children:t}):void 0,MenuProps:{PaperProps:{sx:{maxHeight:300,...c==="xs"||c==="sm"?{"& .MuiMenuItem-root":{fontSize:"0.8rem",minHeight:28,padding:"3px 8px"},"& .MuiListItemText-root":{margin:0},"& .MuiListItemText-primary":{fontSize:"0.8rem"},"& .MuiListItemIcon-root":{minWidth:22}}:{}}}},children:[d&&e.jsx(l,{sx:{px:1,pb:.5,pt:.5},onKeyDown:r=>r.stopPropagation(),onClickCapture:r=>r.stopPropagation(),onMouseDown:r=>r.stopPropagation(),children:e.jsxs(l,{sx:{display:"flex",alignItems:"center",height:28,border:"1px solid var(--ov-border-default)",borderRadius:"4px",bgcolor:"var(--ov-bg-base)",px:.75,"&:focus-within":{borderColor:"var(--ov-accent)"}},children:[e.jsx(_,{sx:{fontSize:14,color:"var(--ov-fg-faint)",mr:.5}}),e.jsx(U,{autoFocus:!0,fullWidth:!0,placeholder:"Search...",value:x,onChange:r=>S(r.target.value),sx:{flex:1,fontSize:"0.75rem",color:"var(--ov-fg-default)","& input":{py:0,px:0},"& input::placeholder":{color:"var(--ov-fg-faint)",opacity:1}}})]})}),I&&e.jsxs(h,{disabled:!0,children:[e.jsx(G,{size:16,sx:{mr:1}})," Loading..."]}),C.map(r=>e.jsxs(h,{value:r.value,disabled:r.disabled,children:[r.icon&&e.jsx(B,{sx:{minWidth:28},children:r.icon}),e.jsx(O,{children:r.label})]},r.value)),C.length===0&&!I&&e.jsx(h,{disabled:!0,children:"No options"})]}),(y||j)&&e.jsx(R,{children:y??j})]})}b.displayName="Select";exports.Select=b;
