"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const x=require("react/jsx-runtime"),v=require("react"),k=require("d3"),A=require("./Layer.js");function j(o){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const t in o)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(o,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>o[t]})}}return e.default=o,Object.freeze(e)}const f=j(k);class z extends A.default{constructor(){super(),this.gRef=v.createRef()}createPaths(e){const{path:t,fillColor:s,borderColor:i,projection:a}=this.props;this.gRef&&this.gRef.current&&(this.g=f.select(this.gRef.current),this.g.attr("class","base-layer zoomable"),this.g.selectAll(".borders").remove(),this.g.selectAll(".feature-label").remove(),this.g.selectAll(".borders").data(e.features).enter().append("path").attr("fill",s).attr("stroke",i).attr("id","state-borders").attr("class","borders").attr("d",t).style("vector-effect","non-scaling-stroke"))}createLabels(e){const{path:t,labelFilter:s=[],labelSettings:i={},labelField:a,labelFontSize:h,labelColor:l,projection:u,initialPosition:d,minLabelZoomVisible:b}=this.props;if(this.gRef&&this.gRef.current){this.g=f.select(this.gRef.current);const n=u.scale(),c=this.props.transform?this.props.transform.k:d.k;this.g.selectAll(".feature-label").data(e.features.filter(r=>s.indexOf(r.properties[a])==-1)).enter().append("text").attr("class","feature-label").attr("font-size",r=>Math.max(.5,h/c)+"px").style("pointer-events","none").text(function(r){return r.properties[a]}).attr("color",l).attr("fill",l).attr("transform",function(r){const p=i[r.properties[a]+"_rotation"]||0,g=i[r.properties[a]+"_offsetX"]||0,m=i[r.properties[a]+"_offsetY"]||0,y=t.centroid(r)[0]+g/n,R=t.centroid(r)[1]+m/n;return"translate("+[y,R]+"),rotate("+(p||0)+")"}).attr("text-anchor","middle").attr("dominant-baseline","middle"),c<b?this.g.selectAll(".feature-label").transition().style("display","none"):this.g.selectAll(".feature-label").style("display","")}}resize(){const{labelFontSize:e,minLabelZoomVisible:t=-1}=this.props,s=this.props.transform?this.props.transform.k:1;s<t?this.g.selectAll(".feature-label").transition().style("display","none"):this.g.selectAll(".feature-label").style("display",""),this.g.selectAll(".feature-label").attr("font-size",i=>Math.max(.5,e/s)+"px")}createLayer(e){this.createPaths(e),this.createLabels(e),this.props.onReady&&this.props.onReady()}componentDidMount(){super.componentDidMount()}componentDidUpdate(e,t,s){const{editing:i}=this.props;(i||e.path!==this.props.path)&&this.create(),e.visible!=this.props.visible&&this.g.style("display",this.props.visible?"block":"none"),this.g&&this.resize()}render(){const{name:e,height:t,width:s}=this.props;return x.jsx("g",{ref:this.gRef})}}exports.default=z;
