Liferay.Loader.define("layout-admin-web@5.0.105/js/miller_columns/MillerColumns",["module","exports","require","@liferay/frontend-js-react-web","liferay!frontend-js-react-web$react","liferay!frontend-js-react-web$react-dnd","liferay!frontend-js-react-web$react-dnd-html5-backend","./DragPreview","./MillerColumnsColumn"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=r("@liferay/frontend-js-react-web"),o=function(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=u();if(t&&t.has(e))return t.get(e);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var a=n?Object.getOwnPropertyDescriptor(e,o):null;a&&(a.get||a.set)?Object.defineProperty(r,o,a):r[o]=e[o]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react")),a=r("liferay!frontend-js-react-web$react-dnd"),i=r("liferay!frontend-js-react-web$react-dnd-html5-backend"),c=s(r("./DragPreview")),l=s(r("./MillerColumnsColumn"));function s(e){return e&&e.__esModule?e:{default:e}}function u(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return u=function(){return e},e}function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function f(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(Object(r),!0).forEach((function(t){p(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function p(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const e=(e,t=new Map)=>{const r=new Map;let n,o;return e.forEach(((e,a)=>{let i,c,l=0;e.forEach((e=>{l++;const s=Array.from(t.values()).find((t=>t.id===e.id));r.set(e.key,f(f({},e),{},{checked:!!s&&s.checked,columnIndex:a,parentId:n,parentKey:o})),e.active&&e.hasChild&&(i=e.id,c=e.key)})),o&&r.set(o,f(f({},r.get(o)),{},{childrenCount:l})),n=i,o=c})),r},y=()=>{};var m=({initialColumns:t=[],isPrivateLayoutsEnabled:r,namespace:s,onColumnsChange:u=y,onItemMove:d=y,onItemStayHover:p,rtl:m,searchContainer:b})=>{const h=(0,o.useRef)(),[v,w]=(0,o.useState)((()=>e(t))),j=(0,o.useMemo)((()=>{const e=[];for(const t of v.values()){e[t.columnIndex]||(e[t.columnIndex]={items:[],parent:Array.from(v.values()).find((e=>e.id===t.parentId))});e[t.columnIndex].items.push(t)}const t=e[e.length-1].items.find((e=>e.active));return t&&!t.hasChild&&e.push({items:[],parent:t}),e}),[v]),O=(0,n.usePrevious)(j),g=(0,n.usePrevious)(t);(0,o.useEffect)((()=>{g!==t&&w(e(t,v))}),[t,v,g]),(0,o.useEffect)((()=>{O!==j&&u(j)}),[j,u,O]),(0,o.useEffect)((()=>{h.current&&(h.current.scrollLeft=h.current.scrollWidth)}),[]),(0,o.useEffect)((()=>{b&&b.on("rowToggled",(e=>{w((t=>{const r=new Map(t);return r.forEach((t=>{const n=e.elements.allElements._nodes.find((e=>e.value===t.id));n&&r.set(t.id,f(f({},r.get(t.id)),{},{checked:n.checked}))})),r}))}))}),[b]);const P=(e,t,r)=>{const n=new Map(v);e.forEach((e=>{e.checked&&n.set(e.id,e)})),w(n),d(((e,t,r)=>{const n=Array.from(v.values()).filter((e=>e.parentId===t));if(!n.length)return e.map(((e,t)=>({plid:e.id,position:r+t})));const o=new Map;let a=0;return n.forEach(((t,n)=>{n===r&&(e.forEach(((e,t)=>{o.set(e.id,{plid:e.id,position:n-a+t})})),a=e.length-a),e.some((e=>e.id===t.id))?a=n<r?a+1:a-1:a&&o.set(t.id,{plid:t.id,position:n<r?n-a:n+a})})),e.forEach(((e,t)=>{o.has(e.id)||o.set(e.id,{plid:e.id,position:r+t})})),Array.from(o.values())})(e,t,r),t)};return o.default.createElement(a.DndProvider,{backend:i.HTML5Backend},o.default.createElement(c.default,{rtl:m}),o.default.createElement("div",{className:"bg-white miller-columns-row",ref:h},j.map(((e,t)=>o.default.createElement(l.default,{columnItems:e.items,columnsContainer:h,isPrivateLayoutsEnabled:r,items:v,key:t,namespace:s,onItemDrop:P,onItemStayHover:p,parent:e.parent,rtl:m})))))};t.default=m}}));
//# sourceMappingURL=MillerColumns.js.map