import{useEffect as n}from"react";import{convertDrawCoordsToApi as e}from"../utils/polygonCoords.js";var i=function(i){var t=i.mapRef,o=i.isActive,r=i.isMapReady,s=i.isDrawing,a=i.isEditingPolygon,l=i.isEditingVertices,u=i.wellsLayerId,g=i.lassoState,c=i.drawRef,d=i.prevActiveRef,f=i.isWellClickRef,v=i.handleMapClick,y=i.setIsDrawing,p=i.setDrawingPointCount,m=i.setIsEditingPolygon,w=i.setIsEditingVertices,P=i.setConfirmingPolygon,C=i.setLassoState,A=i.onPolygonChange;!function(e,i,t,o,r){n((function(){var n,s=null===(n=e.current)||void 0===n?void 0:n.getMap();if(s&&i&&t&&o)return s.on("click",r),function(){s.off("click",r)}}),[e,i,t,o,r])}(t,o,s,r,v),function(e){var i=e.isActive,t=e.prevActiveRef,o=e.drawRef,r=e.setIsDrawing,s=e.setDrawingPointCount,a=e.setIsEditingPolygon,l=e.setIsEditingVertices,u=e.setConfirmingPolygon,g=e.setLassoState,c=e.onPolygonChange;n((function(){var n=t.current;if(t.current=i,i!==n){if(s(0),a(!1),l(!1),u(null),!i)return r(!1),void g({phase:"idle"});c(void 0),r(!0),g({phase:"drawing",pointCount:0}),o.current&&(o.current.deleteAll(),o.current.changeMode("draw_polygon"))}}),[i,c,g,t,o,r,s,a,l,u])}({isActive:o,prevActiveRef:d,drawRef:c,setIsDrawing:y,setDrawingPointCount:p,setIsEditingPolygon:m,setIsEditingVertices:w,setConfirmingPolygon:P,setLassoState:C,onPolygonChange:A}),function(e,i,t,o,r){n((function(){var n,s=null===(n=e.current)||void 0===n?void 0:n.getMap();if(s&&i&&t){var a=function(n){var e=s.queryRenderedFeatures(n.point,{layers:[o]});r.current=e.length>0};return s.on("mousedown",a),function(){s.off("mousedown",a)}}}),[e,i,t,o,r])}(t,o,r,u,f),function(i,t,o,r,s,a){n((function(){var n,l,u;if("confirming"===i&&!t&&!o){var g=null===(n=r.current)||void 0===n?void 0:n.getAll(),c=null==g?void 0:g.features[0];if("Polygon"===(null==c||null===(l=c.geometry)||void 0===l?void 0:l.type)){var d=c.geometry,f=null==d||null===(u=d.coordinates)||void 0===u?void 0:u[0];if(Array.isArray(f)&&0!==f.length&&Array.isArray(f[0])){var v=e(f);s(v),a({phase:"confirming",polygon:v.map((function(n){return{latitude:n.latitude,longitude:n.longitude}}))})}}}}),[i,t,o,a,r,s])}(g.phase,a,l,c,P,C)};export{i as useLassoEffects};
//# sourceMappingURL=useLassoEffects.js.map
