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