Liferay.Loader.define("@liferay/frontend-data-set-web@1.0.31/management_bar/components/filters/CheckboxesFilter",["module","exports","require","@frontend-taglib-clay$clayui/button","@frontend-taglib-clay$clayui/drop-down","@frontend-taglib-clay$clayui/form","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../../utils/index"],(function(e,t,l){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=t.getOdataString=t.getSelectedItemsLabel=void 0;var a=i(l("@frontend-taglib-clay$clayui/button")),n=i(l("@frontend-taglib-clay$clayui/drop-down")),r=l("@frontend-taglib-clay$clayui/form"),d=(i(l("liferay!frontend-js-react-web$prop-types")),function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=c();if(t&&t.has(e))return t.get(e);var l={},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var r=a?Object.getOwnPropertyDescriptor(e,n):null;r&&(r.get||r.set)?Object.defineProperty(l,n,r):l[n]=e[n]}l.default=e,t&&t.set(e,l);return l}(l("liferay!frontend-js-react-web$react"))),u=l("../../../utils/index");function c(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return c=function(){return e},e}function i(e){return e&&e.__esModule?e:{default:e}}const e=({items:e,selectedData:t})=>{const l=t.itemsValues,a=l?l.map((t=>e.reduce(((e,l)=>e||(l.value===t?l.label:null)),null))).join(", "):"";return((null==t?void 0:t.exclude)?"(".concat(Liferay.Language.get("exclude"),") "):"")+a};t.getSelectedItemsLabel=e;const f=({id:e,selectedData:t})=>{const{exclude:l,itemsValues:a}=t;return(null==a?void 0:a.length)?"".concat(e,"/any(x:").concat(a.map((e=>"(x ".concat(l?"ne":"eq"," ").concat("string"==typeof e?"'".concat(e,"'"):e,")"))).join(l?" and ":" or "),")"):null};t.getOdataString=f;var o=function({id:t,items:l,selectedData:c,setFilter:i}){const[o,s]=(0,d.useState)((null==c?void 0:c.itemsValues)||[]),[m,g]=(0,d.useState)((null==c?void 0:c.exclude)||!1);(0,d.useEffect)((()=>{s((null==c?void 0:c.itemsValues)||[]),g((null==c?void 0:c.exclude)||!1)}),[c]);let y="edit";(null==c?void 0:c.itemsValues)&&!o.length&&(y="delete"),c||(y="add");let p=!0;return("delete"===y||!c&&o.length||c&&(0,u.isValuesArrayChanged)(c.itemsValues,o)||c&&o.length&&c.exclude!==m)&&(p=!1),d.default.createElement(d.default.Fragment,null,d.default.createElement(n.default.Caption,{className:"pb-0"},d.default.createElement("div",{className:"row"},d.default.createElement("div",{className:"col"},d.default.createElement("label",{htmlFor:"autocomplete-exclude-".concat(t)},Liferay.Language.get("exclude"))),d.default.createElement("div",{className:"col-auto"},d.default.createElement(r.ClayToggle,{id:"autocomplete-exclude-".concat(t),onToggle:()=>g(!m),toggled:m})))),d.default.createElement(n.default.Divider,null),d.default.createElement(n.default.Caption,null,d.default.createElement("div",{className:"inline-scroller mb-n2 mx-n2 px-2"},l.map(((e,t)=>{let l=!1;return o&&(l=o.reduce(((t,l)=>t||l===e.value),!1)),d.default.createElement(r.ClayCheckbox,{"aria-label":e.label,checked:l,key:t,label:e.label,onChange:()=>{return t=e.value,o.includes(t)?s(o.filter((e=>e!==t))):s(o.concat(t));var t}})})))),d.default.createElement(n.default.Divider,null),d.default.createElement(n.default.Caption,null,d.default.createElement(a.default,{disabled:p,onClick:()=>{if("delete"===y)i({active:!1,id:t});else{const a={exclude:m,itemsValues:o};i({active:!0,id:t,odataFilterString:f({id:t,selectedData:a}),selectedData:a,selectedItemsLabel:e({items:l,selectedData:a})})}},small:!0},"add"===y&&Liferay.Language.get("add-filter"),"edit"===y&&Liferay.Language.get("edit-filter"),"delete"===y&&Liferay.Language.get("delete-filter"))))};t.default=o}}));
//# sourceMappingURL=CheckboxesFilter.js.map