Liferay.Loader.define("product-navigation-control-menu@6.0.52/js/useDragAndDrop",["module","exports","require","liferay!frontend-js-react-web$react","liferay!frontend-js-react-web$react-dnd","liferay!frontend-js-react-web$react-dnd-html5-backend","./AddPanel","./addPortlet","./constants/layoutDataItemTypes","./constants/positions"],(function(e,t,r){var o;window;{Object.defineProperty(t,"__esModule",{value:!0}),t.useDragItem=p,t.useDragSymbol=function({data:e,icon:t,label:r,portletId:o,type:a}){const i=(0,n.useMemo)((()=>({data:e,icon:t,isSymbol:!0,itemId:o,name:r,type:a})),[e,t,r,o,a]),{handlerRef:s,isDraggingSource:l,sourceRef:d}=p(i);return{isDraggingSource:l,sourceRef:e=>{d.current=e,s(e)}}},t.useDropClear=function(t){const{dropTargetColumn:r,setDropTargetColumn:o}=(0,n.useContext)(y),[,i]=(0,a.useDrop)({accept:Object.values(d.LAYOUT_DATA_ITEM_TYPES),hover(t,n){n.isOver({shallow:!0})&&(r&&(r.classList.remove(f),r.classList.remove(e)),o(null))}});i(t)},t.useDropTarget=function(t){const{dropTargetColumn:r,dropTargetItem:o,setDragIndicatorPosition:i,setDropTargetColumn:c,setDropTargetItem:u}=(0,n.useContext)(y),[p,D]=(0,n.useState)(0),[w,I]=(0,n.useState)(null),{plid:P,setWidgets:h,widgets:O}=(0,n.useContext)(s.AddPanelContext);(0,n.useEffect)((()=>{const e=()=>{D(window.scrollY)};return window.addEventListener("scroll",e),()=>{window.removeEventListener("scroll",e)}}),[]);const L=e=>e.classList.contains(g),C=e=>e.classList.contains(m)&&!e.classList.contains(v),[{validDrop:S},j]=(0,a.useDrop)({accept:Object.values(d.LAYOUT_DATA_ITEM_TYPES),collect:e=>({validDrop:e.canDrop()}),drop(o,n){if(c(null),n.isOver({shallow:!0})&&(L(t)||C(t))&&!o.disabled&&(r.classList.remove(f),r.classList.remove(e),(0,l.default)({item:o,plid:P,targetItem:t,targetPosition:w}),!o.data.instanceable)){const e=(0,s.updateUsedWidget)({item:o,widgets:O});h(e)}},hover(n,a){if(!a.isOver({shallow:!0}))return;const s=C(t);if(!L(t)&&!s)return;const l=s?t.parentElement:t.parentElement.parentElement;r!==l&&(r&&(r.classList.remove(f),r.classList.remove(e)),c(l),s?l.classList.add(f):S&&l.classList.add(e));const d=b({monitor:a,targetItem:t});if(I(d),o!==t||d!==w){u(t);const e=T({monitor:a,targetItem:t,windowScrollPosition:p});i(e)}}});j(t)},t.DragAndDropProvider=void 0;var n=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={},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var a=o?Object.getOwnPropertyDescriptor(e,n):null;a&&(a.get||a.set)?Object.defineProperty(r,n,a):r[n]=e[n]}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"),s=r("./AddPanel"),l=(o=r("./addPortlet"))&&o.__esModule?o:{default:o},d=r("./constants/layoutDataItemTypes"),c=r("./constants/positions");function u(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return u=function(){return e},e}const e="yui3-dd-drop-active-valid",g="yui3-dd-drop",f="yui3-dd-drop-over",m="portlet-dropzone",v="portlet-dropzone-disabled",D={dragIndicatorPosition:{},dropTargetColumn:null,dropTargetItem:null,setDragIndicatorPosition:()=>null,setDropTargetColumn:()=>null,setDropTargetItem:()=>null},y=n.default.createContext(D),w=y.Provider;function p(e){const t=(0,n.useCallback)((()=>e),[e]),r=(0,n.useRef)(null),[{isDraggingSource:o},s,l]=(0,a.useDrag)({collect:e=>({isDraggingSource:e.isDragging()}),item:{data:e.data,disabled:e.disabled,getSourceItem:t,icon:e.icon,itemId:e.itemId,name:e.name,type:e.type}});return(0,n.useEffect)((()=>{l((0,i.getEmptyImage)(),{captureDraggingState:!0})}),[l]),{handlerRef:s,isDraggingSource:o,sourceRef:r}}t.DragAndDropProvider=w;const I=(e,t)=>{const r=e.getClientOffset(),o=t.getBoundingClientRect(),n=t.getBoundingClientRect().height;return{hoverClientY:r.y-o.top,hoverTopLimit:n/2,targetItemBoundingRect:o}},b=({monitor:e,targetItem:t})=>{const{hoverClientY:r,hoverTopLimit:o}=I(e,t);return r<o?c.POSITIONS.top:c.POSITIONS.bottom},T=({monitor:e,targetItem:t,windowScrollPosition:r})=>{const{hoverClientY:o,hoverTopLimit:n,targetItemBoundingRect:a}=I(e,t),i=o<n?a.top:a.bottom;return{clientX:a.left,clientY:i+r,width:a.width}}}}));
//# sourceMappingURL=useDragAndDrop.js.map