"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/slicedToArray"),t=require("react");require("../../../../stores/selection-tool-store/SelectionToolStoreContext.js"),require("../../../../stores/selection-tool-store/SelectionToolStoreProvider.js"),require("zustand");var o=require("../../../../stores/selection-tool-store/useSelectionToolStore.js"),n=require("../utils/selection-geometry.js"),s=require("../utils/polygonCoords.js"),i=require("./useLassoDrawActions.js"),a=require("./useLassoConfirmCancel.js"),r=require("./useLassoEventHandlers.js"),l=require("./useLassoEffects.js");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=u(e);exports.useLassoSelection=function(e){var u=e.mapRef,c=e.isActive,g=e.isMapReady,f=e.hasInitialPolygon,w=e.onPolygonChange,C=e.wellsLayerId,S=e.wells,h=e.onWellsSelected,y=e.onDeactivate,D=e.subjectWellId,p=o.useSelectionToolStore((function(e){return e.setLassoState})),P=o.useSelectionToolStore((function(e){return e.lassoState})),v=o.useSelectionToolStore((function(e){return e.setMode})),m=t.useRef(null),L=t.useRef(c),E=t.useRef(!1),j=t.useState(c&&!f),q=d.default(j,2),I=q[0],R=q[1],M=t.useState(0),A=d.default(M,2),T=A[0],b=A[1],k=t.useState(!1),V=d.default(k,2),W=V[0],x=V[1],H=t.useState(!1),U=d.default(H,2),_=U[0],z=U[1],O=t.useState(null),B=d.default(O,2),F=B[0],G=B[1],J=t.useMemo((function(){return!S||!F||F.length<3?[]:n.getWellsInPolygon(S,F,null!=D?D:void 0)}),[S,F,D]),K=t.useCallback((function(e){var t=s.convertDrawCoordsToApi(e);G(t),R(!1),b(0),p({phase:"confirming",polygon:t.map((function(e){return{latitude:e.latitude,longitude:e.longitude}}))})}),[p]),N=r.useLassoEventHandlers(P,w,p,G,R,x,z,b,m,E,K),Q=N.handleDrawCreate,X=N.handleDrawUpdate,Y=N.handleModeChange,Z=N.handleSelectionChange,$=N.handleMapClick,ee=i.useLassoDrawActions({drawRef:m,lassoState:P,drawingPointCount:T,onPolygonChange:w,setLassoState:p,setConfirmingPolygon:G,setIsDrawing:R,setIsEditingPolygon:x,setIsEditingVertices:z,setDrawingPointCount:b,enterConfirmingPhase:K}),te=ee.discardDrawing,oe=ee.completeDrawing,ne=ee.deletePolygon,se=ee.handleDrawDelete,ie=a.useLassoConfirmCancel(P,F,J,h,y,m,p,v,G,R,x,z),ae=ie.confirm,re=ie.cancel;return l.useLassoEffects({mapRef:u,isActive:c,isMapReady:g,isDrawing:I,isEditingPolygon:W,isEditingVertices:_,wellsLayerId:C,lassoState:P,drawRef:m,prevActiveRef:L,isWellClickRef:E,handleMapClick:$,setIsDrawing:R,setDrawingPointCount:b,setIsEditingPolygon:x,setIsEditingVertices:z,setConfirmingPolygon:G,setLassoState:p,onPolygonChange:w}),{lassoState:P,isDrawing:I,drawingPointCount:T,isEditingPolygon:W,isEditingVertices:_,isActivelyEditing:W||_,wellsInPolygonCount:J.length,drawRef:m,handleDrawCreate:Q,handleDrawUpdate:X,handleDrawDelete:se,handleModeChange:Y,handleSelectionChange:Z,discardDrawing:te,completeDrawing:oe,deletePolygon:ne,confirm:ae,cancel:re}};
//# sourceMappingURL=useLassoSelection.js.map
