Liferay.Loader.define("@liferay/content-dashboard-web@2.0.83/js/components/VocabulariesSelectionBox",["module","exports","require","@frontend-taglib-clay$clayui/form","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=r("@frontend-taglib-clay$clayui/form"),n=(function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(r("liferay!frontend-js-react-web$prop-types")),function _interopRequireWildcard(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache();if(t&&t.has(e))return t.get(e);var r={},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var l=a?Object.getOwnPropertyDescriptor(e,n):null;l&&(l.get||l.set)?Object.defineProperty(r,n,l):r[n]=e[n]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react")));function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}const e=2,getItemByvalue=(e,t)=>e.find((e=>e.value===t));var _default=({leftBoxName:t,leftList:r,portletNamespace:l,rightBoxName:o,rightList:i})=>{const[c,u]=(0,n.useState)([r,i]),[f,s]=(0,n.useState)([]),[d,g]=(0,n.useState)([]),[p,b]=c,y=(0,n.useRef)(),h=(0,n.useRef)();(0,n.useEffect)((()=>{h.current=p}));const enableAllOptions=()=>{Array.from(y.current.querySelectorAll(".vocabularies-selection option")).forEach((e=>{e.disabled=!1}))},disableOptionsFromOtherSites=e=>{p.forEach((t=>{t.global||t.site===e.site||(y.current.querySelector("option[value='".concat(t.value,"']")).disabled=!0)}))},disableNonSelectableOptions=()=>{const e=b.filter((e=>!e.global));e.length&&disableOptionsFromOtherSites(e[0])};return(()=>{const e=h.current;if(void 0!==e)if(e.length<p.length){const t=p.filter((t=>!e.includes(t))).map((e=>e.value));h.current=p,s(t)}else if(e.length>p.length){const t=e.filter((e=>!p.includes(e))).map((e=>e.value));h.current=p,g(t)}})(),(0,n.useEffect)((()=>{enableAllOptions(),disableNonSelectableOptions()}),[c]),(0,n.useEffect)((()=>{enableAllOptions(),disableNonSelectableOptions(),f.forEach((e=>{const t=getItemByvalue(p,e);t.global||disableOptionsFromOtherSites(t)}))}),[f]),n.default.createElement("div",{ref:y},n.default.createElement(a.ClayDualListBox,{className:"vocabularies-selection",disableLTR:(()=>{const t=f.length+b.length>e;if(f.length<e&&!t)return!1;const r=c.flat(),a=getItemByvalue(r,f[0]),n=f.every((e=>{const t=getItemByvalue(r,e);return!(null==t?void 0:t.global)})),l=f.some((e=>getItemByvalue(r,e).site!==a.site));return t||n&&l})(),disableRTL:!b.length,items:c,left:{id:t,label:Liferay.Language.get("available"),onSelectChange:s,selected:f},onItemsChange:u,right:{id:"".concat(l).concat(o),label:Liferay.Language.get("in-use"),onSelectChange:g,selected:d}}))};t.default=_default}}));
//# sourceMappingURL=VocabulariesSelectionBox.js.map