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