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