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