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