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