"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../node_modules/tslib/tslib.es6.js"),t=require("react"),r=require("../store/index.js");require("../node_modules/react-redux/es/index.js");var o=require("../utils/customHooks/useEventListener.js"),s=require("../utils/customHooks/useLocalStorage.js"),n=require("../utils/customHooks/useLongPress.js"),i=require("../utils/genericFunctions/styleTransformValues.js"),a=require("../lib/island/island.js"),u=require("../node_modules/framer-motion/dist/es/gestures/drag/use-drag-controls.mjs.js"),l=require("../node_modules/framer-motion/dist/es/animation/hooks/use-animation.mjs.js"),d=require("../node_modules/framer-motion/dist/es/render/components/motion/proxy.mjs.js"),c=require("../node_modules/react-redux/es/hooks/useSelector.js"),m=require("../node_modules/react-redux/es/hooks/useDispatch.js");function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f=p(t),g=function(p){var g=p.children,v=p.islandContainerRef,j=c.useSelector((function(e){return e.island})).startPosition,x=t.useState(!1),h=x[0],y=x[1],_=m.useDispatch(),q=u.useDragControls(),b=l.useAnimation(),S=s.useLocalStorage("phone-island",null),D=S[0],P=S[1],L=t.useRef(null),k=t.useState(D&&D.position?D.position:null),C=k[0],w=k[1];o.useEventListener("phone-island-reset-position",(function(){return e.__awaiter(void 0,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return localStorage.removeItem("phone-island"),w(null),[4,b.start({x:j.x,y:j.y,transition:{duration:.3,ease:"easeOut"}})];case 1:return e.sent(),[2]}}))}))}));var E=n.useLongPress((function(){}),(function(e){var t,o;if(e&&e.target){var s=e.target;if(s.closest('[data-stop-propagation="true"]')||s.hasAttribute("data-stop-propagation"))return}!(null===(o=null===(t=null===r.store||void 0===r.store?void 0:r.store.getState())||void 0===t?void 0:t.island)||void 0===o?void 0:o.isOpen)&&_.island.handleToggleIsOpen()}),h,(function(){return y(!1)}),{shouldPreventDefault:!0,delay:250});return f.default.createElement(d.motion.div,e.__assign({drag:!0,onPointerDown:function(e){var t=e.target;t.closest('[data-stop-propagation="true"]')||t.hasAttribute("data-stop-propagation")||q.start(e)},onDragStart:function(){y(!0)},dragTransition:{power:0,timeConstant:300},initial:{x:(null==C?void 0:C.x)||j.x,y:(null==C?void 0:C.y)||j.y},animate:b,dragControls:q,dragListener:!1,dragConstraints:v,onDragEnd:function(){if(L.current){var e=i.styleTransformValues(L.current),t=e.x,r=e.y;t=a.xPosition(Math.round(t),L.current,v.current),r=a.yPosition(Math.round(r),L.current,v.current),P({position:{x:t,y:r}}),w({x:t,y:r})}},ref:L},E,{className:"pi-absolute"}),g&&g)};exports.IslandDrag=g,exports.default=g;
//# sourceMappingURL=IslandDrag.js.map
