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