import e from"@babel/runtime/helpers/slicedToArray";import{useState as t,useEffect as n}from"react";import r from"prop-types";import{makeStyles as i,FormControl as l,InputLabel as a,Select as o,MenuItem as u,Checkbox as c,ListItemText as s,Divider as d}from"@material-ui/core";import{jsxs as p,jsx as m}from"react/jsx-runtime";var h=i({multiMenuItem:{paddingLeft:"9px !important",paddingRight:"18px !important"}}),f=function(r){var i=r.label,f=r.currentValues,g=r.options,v=r.ListMenuItem,y=r.ValueComponent,x=r.onChange,C=r["data-testid"],b=h(),M=t([]),R=e(M,2),V=R[0],_=R[1],k=t(!1),q=e(k,2),I=q[0],O=q[1],A=t(!1),L=e(A,2),S=L[0],T=L[1];n((function(){_(f||[])}),[f,g]);return p(l,{style:{width:"100%"},children:[m(a,{shrink:!0,children:i}),p(o,{"data-testid":"".concat(C,"_select_").concat(i),multiple:!0,displayEmpty:!0,fullWidth:!0,value:V,renderValue:function(e){return function(e){return y&&1===e.length?m(y,{value:e[0]}):0===e.length?"All":1===e.length?e[0]:"".concat(e.length," Selected")}(e)},open:I,onOpen:function(){O(!0),T(!1)},onClose:function(){O(!1),S&&x(0===V.length?null:V),T(!1)},onChange:function(e){var t=e.target.value;_(t.includes("all")?[]:t),T(!0)},children:[p(u,{value:"all",classes:{gutters:b.multiMenuItem},children:[m(c,{"data-testid":"".concat(C,"_checkbox_all"),checked:!0,indeterminate:V.length>0}),m(s,{primary:"All"})]},"all"),m(d,{}),g.map((function(e){return p(u,{value:e,classes:{gutters:b.multiMenuItem},children:[m(c,{"data-testid":"".concat(C,"_checkbox_").concat(e),checked:-1!==V.indexOf(e)}),m(v,{value:e})]},e)}))]})]})};f.propTypes={options:r.arrayOf(r.string).isRequired,currentValues:r.arrayOf(r.string).isRequired,label:r.string.isRequired,ListMenuItem:r.node.isRequired,onChange:r.func.isRequired,ValueComponent:r.node,"data-testid":r.string},f.defaultProps={ValueComponent:null,"data-testid":"MultiSelect"};export{f as MultiSelect};
