import{memo as r,useRef as e,useMemo as t,useEffect as o,createElement as n}from"react";import l from"react-dom";import u from"prop-types";import c from"mapbox.js";import{get as i}from"lodash";import{usePrevious as a}from"../../effects/index.js";import s from"./Map.css.js";import{mapbox as f}from"../../../../utils/index.js";import{jsx as m}from"react/jsx-runtime";var d=f.isValidCoordinates,p=[29.749907,-95.358421];function h(r){var u=r.subjectWell,f=r.wells,h=r.offsetWells,v=r.radius,b=r.subjectWellMarkerSize,k=r.wellMarkerSize,y=r.coordsDataPath,g=e(null),j=e(null),x=e(null),C=e(null),M=a(f),W=t((function(){return u&&i(u,y)}),[u,y]);o((function(){g.current=c.mapbox.map(g.current,null,{attributionControl:!1,scrollWheelZoom:!1,zoomControl:!1}).setView(p,1),c.control.zoom({position:"bottomright"}).addTo(g.current),c.mapbox.styleLayer("mapbox://styles/mapbox/dark-v9").addTo(g.current)}),[]),o((function(){g.current&&(j.current&&g.current.removeLayer(j.current),W?(j.current=c.circle(W,1609.34*v,{stroke:!1,fill:!0,fillOpacity:.2,fillColor:"#03BCD4",className:"circle_500"}),j.current.addTo(g.current)):j.current=null)}),[v,W]);return o((function(){if(g.current){g.current.closePopup(),x.current&&x.current.removeFrom(g.current);var r=h.map((function(r){return r.id})),e=[];f.forEach((function(t){var o=i(t,y);if(o&&d(o)){var a=u&&u.id===t.id,s=r.includes(t.id),f=a?b:k,p=a||s?1:.3,h=c.circleMarker(o,{radius:f,stroke:!1,fill:!0,fillOpacity:p,fillColor:"#FFC107",className:"circle_500"});h.addEventListener("mouseover",(function(){var r=document.createElement("div"),u=n((function(r){var e=r.well;return m("div",{style:{color:"#fff",background:"##414141"},children:m("span",{style:{fontSize:"11px",lineHeight:"16px"},children:i(e,"name")})})}),{well:t});l.render(u,r),c.popup().setLatLng(o).setContent(r).openOn(g.current),function(r,e,t){C.current=c.circleMarker(e,{radius:3*t,stroke:!1,fill:!0,fillOpacity:.2,fillColor:"#FFC107",className:"circle_highlight"}),C.current.addEventListener("mouseout",(function(){x.current.removeFrom(g.current),x.current=c.featureGroup(r),x.current.addTo(g.current),g.current.closePopup()}));var o=r.concat(C.current);x.current=c.featureGroup(o),x.current.addTo(g.current)}(e,o,f)})),e.push(h)}})),e.length&&(x.current=c.featureGroup(e),x.current.addTo(g.current)),setTimeout((function(){j.current&&j.current.bringToBack(),g.current&&x.current&&f!==M&&g.current.fitBounds(x.current.getBounds())}),500)}}),[u,f,h]),m("div",{className:s.map,children:m("div",{className:s.mapMain,ref:g})})}h.propTypes={subjectWell:u.shape({id:u.number,formation:u.string}),wells:u.arrayOf(u.shape({})).isRequired,offsetWells:u.arrayOf(u.shape({})),radius:u.number.isRequired,subjectWellMarkerSize:u.number,wellMarkerSize:u.number,coordsDataPath:u.string},h.defaultProps={subjectWell:null,subjectWellMarkerSize:8,wellMarkerSize:5,coordsDataPath:"settings.top_hole.coordinates",offsetWells:null};var v=r(h);export{v as default};
