Liferay.Loader.define("layout-admin-web@5.0.145/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 _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={},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=_interopRequireDefault(r("./DragPreview")),l=_interopRequireDefault(r("./MillerColumnsColumn"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function ownKeys(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 _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const getItemsMap=(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 d=Array.from(t.values()).find((t=>t.id===e.id));r.set(e.key,_objectSpread(_objectSpread({},e),{},{checked:!!d&&d.checked,columnIndex:a,parentId:n,parentKey:o})),e.active&&e.hasChild&&(i=e.id,c=e.key)})),o&&r.set(o,_objectSpread(_objectSpread({},r.get(o)),{},{childrenCount:l})),n=i,o=c})),r},noop=()=>{};var _default=({initialColumns:e=[],isLayoutSetPrototype:t,isPrivateLayoutsEnabled:r,namespace:d,onColumnsChange:u=noop,onItemMove:s=noop,onItemStayHover:f,rtl:p,searchContainer:m})=>{const y=(0,o.useRef)(),[b,h]=(0,o.useState)((()=>getItemsMap(e))),j=(0,o.useMemo)((()=>{const e=[];for(const t of b.values()){e[t.columnIndex]||(e[t.columnIndex]={items:[],parent:Array.from(b.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}),[b]),w=(0,n.usePrevious)(j),v=(0,n.usePrevious)(e);(0,o.useEffect)((()=>{v!==e&&h(getItemsMap(e,b))}),[e,b,v]),(0,o.useEffect)((()=>{w!==j&&u(j)}),[j,u,w]),(0,o.useEffect)((()=>{y.current&&(y.current.scrollLeft=y.current.scrollWidth)}),[]),(0,o.useEffect)((()=>{m&&m.on("rowToggled",(e=>{h((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,_objectSpread(_objectSpread({},r.get(t.id)),{},{checked:n.checked}))})),r}))}))}),[m]);const onItemDrop=(e,t,r)=>{const n=new Map(b);e.forEach((e=>{e.checked&&n.set(e.id,e)})),h(n),s(((e,t,r)=>{const n=Array.from(b.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:p}),o.default.createElement("div",{className:"bg-white miller-columns-row",ref:y},j.map(((e,n)=>o.default.createElement(l.default,{columnItems:e.items,columnsContainer:y,isLayoutSetPrototype:t,isPrivateLayoutsEnabled:r,items:b,key:n,namespace:d,onItemDrop:onItemDrop,onItemStayHover:f,parent:e.parent,rtl:p})))))};t.default=_default}}));
//# sourceMappingURL=MillerColumns.js.map