import e from"@babel/runtime/helpers/slicedToArray";import{useState as t,useEffect as r}from"react";import i from"prop-types";import{makeStyles as a,FormControl as n,InputLabel as o,Select as c,MenuItem as l,Checkbox as s,ListItemText as u,Divider as d}from"@material-ui/core";import{jsxs as m,jsx as p}from"react/jsx-runtime";var f=a({checkBox:{color:"grey",paddingLeft:0},formControl:{marginLeft:10,marginTop:8,width:function(e){return e.size}},listItemPrimaryText:{color:"#fff"},paper:{backgroundColor:"#414141"}});function h(i){var a=i.options,h=i.currentValues,g=i.title,y=i.size,x=i.renderValue,k=i.onChange,v=i["data-testid"],C=t([]),q=e(C,2),P=q[0],R=q[1],T=t(!1),_=e(T,2),V=_[0],b=_[1],w=t(!1),z=e(w,2),I=z[0],N=z[1],O=f({size:y});r((function(){R(h.filter((function(e){return a.includes(e)})))}),[h,a]);return m(n,{className:O.formControl,children:[p(o,{shrink:!0,htmlFor:"c-owp-multi-select-".concat(g),children:g}),m(c,{"data-testid":"".concat(v,"_select_").concat(g),className:O.select,MenuProps:{classes:{paper:O.paper}},multiple:!0,displayEmpty:!0,fullWidth:!0,value:P,inputProps:{name:"c-owp-multi-select-".concat(g),id:"c-owp-multi-select-".concat(g)},renderValue:function(e){return x(e.length)},open:V,onOpen:function(){b(!0),N(!1)},onClose:function(){b(!1),I&&k(P),N(!1)},onChange:function(e){var t=e.target.value;R(t.includes("all")?[]:t),N(!0)},children:[m(l,{value:"all",children:[p(s,{"data-testid":"".concat(v,"_option_all"),checked:!0,indeterminate:P.length>0,className:O.checkBox}),p(u,{primary:x(0),classes:{primary:O.listItemPrimaryText}})]},"all"),p(d,{}),a.map((function(e){return m(l,{value:e,children:[p(s,{"data-testid":"".concat(v,"_option_").concat(e,"MenuItem"),checked:P.indexOf(e)>-1,className:O.checkBox}),p(u,{primary:e,classes:{primary:O.listItemPrimaryText}})]},e)}))]})]})}h.propTypes={options:i.arrayOf(i.string).isRequired,currentValues:i.arrayOf(i.string).isRequired,title:i.string.isRequired,size:i.number.isRequired,renderValue:i.func.isRequired,onChange:i.func.isRequired,"data-testid":i.string},h.defaultProps={"data-testid":"MultiSelect"};export{h as default};
