import{memo as r,useRef as e,useMemo as t,useEffect as o,createElement as n}from"react";import u from"react-dom";import i from"prop-types";import c from"mapbox.js";import{get as l,sortBy as s}from"lodash";import{usePrevious as a}from"../../effects/index.js";import d from"./Map.css.js";import{mapbox as f}from"../../../../../../utils/index.js";import{jsx as m,Fragment as p}from"react/jsx-runtime";var v=f.isValidCoordinates,h=[29.749907,-95.358421];function b(r){var i=r.open,f=r.subjectWell,b=r.wells,B=r.offsetWells,g=r.radius,D=r.formationColors,W=r.popUpFormatter,y=r.coordsDataPath,x=r.onAddOffsetWell,C=r.onDeleteOffsetWell,O=e(null),T=e(),j=e(null),F=e(null),k=a(b),L=t((function(){return f&&l(f,y)}),[f,y]);return o((function(){i&&!T.current&&(T.current=c.mapbox.map(O.current,null,{attributionControl:!1,scrollWheelZoom:!1,zoomControl:!1}).setView(h,1),c.control.zoom({position:"bottomright"}).addTo(T.current),c.mapbox.styleLayer("mapbox://styles/mapbox/dark-v9").addTo(T.current))}),[i]),o((function(){T.current&&i&&(j.current&&T.current.removeLayer(j.current),L?(j.current=c.circle(L,1609.34*g,{stroke:!1,fill:!0,fillOpacity:.2,fillColor:"#03BCD4",className:"circle_500"}),j.current.addTo(T.current)):j.current=null)}),[g,L,i]),o((function(){if(T.current&&i){F.current&&F.current.removeFrom(T.current);var r=B.map((function(r){return r.id})),e=s(b,(function(e){return r.includes(e.id)})),t=[];e.forEach((function(e){var o=l(e,y);if(o&&v(o)){var i=f&&f.id===e.id,s=r.includes(e.id),a=i?10:5,d=i||s?"#00FFFF":l(D,e.formation,"#BDBDBD"),h=i||s?1:.3,b=c.circleMarker(o,{radius:a,stroke:!1,fill:!0,fillOpacity:h,fillColor:d,className:"circle_500"});b.addEventListener("mouseover",(function(){if(W){var r=document.createElement("div"),t=n(W,{well:e,color:l(D,e.formation,"#BDBDBD")});u.render(m(p,{children:t}),r),c.popup().setLatLng(o).setContent(r).openOn(T.current)}})),b.addEventListener("mouseout",(function(){T.current.closePopup()})),b.addEventListener("click",(function(){s&&!i?C(e.id):x(e.id)})),t.push(b)}})),t.length&&(F.current=c.featureGroup(t),F.current.addTo(T.current)),setTimeout((function(){j.current&&j.current.bringToBack(),T.current&&j.current&&b!==k&&T.current.fitBounds(j.current.getBounds(),{padding:[5,5]})}),500)}}),[f,b,B,i]),o((function(){i&&setTimeout((function(){j.current&&j.current.bringToBack(),f?T.current&&j.current&&T.current.fitBounds(j.current.getBounds(),{padding:[5,5]}):T.current&&F.current&&T.current.fitBounds(F.current.getBounds())}),500)}),[g,f,i]),m("div",{className:d.map,children:m("div",{className:d.mapMain,ref:O})})}b.propTypes={open:i.bool.isRequired,subjectWell:i.shape({id:i.number,formation:i.string}),wells:i.arrayOf(i.shape({})).isRequired,offsetWells:i.arrayOf(i.shape({})),radius:i.number.isRequired,formationColors:i.shape({}).isRequired,popUpFormatter:i.func,coordsDataPath:i.string,onAddOffsetWell:i.func.isRequired,onDeleteOffsetWell:i.func.isRequired},b.defaultProps={subjectWell:null,popUpFormatter:null,coordsDataPath:"settings.top_hole.coordinates",offsetWells:null};var B=r(b);export{B as default};
//# sourceMappingURL=Map.js.map
