import { jsx as v } from "react/jsx-runtime";
import I from "react";
import j from "../data/DataProvider.js";
import N from "../data/DataConsumer.js";
import * as p from "d3";
import { injectIntl as O } from "react-intl";
import * as U from "react-dom";
import V from "./Tooltip.js";
class X extends I.Component {
  constructor() {
    super(), this.create = this.create.bind(this), this.showToolTip = this.showToolTip.bind(this), this.moveToolTip = this.moveToolTip.bind(this), this.resize = this.resize.bind(this), this.gRef = I.createRef();
  }
  showToolTip(e, n, s, r) {
    const a = p.select("body").append("div").attr("class", "d3MapTooltip").style("position", "absolute").html("").style("left", r.pageX + 15 + "px").style("top", r.pageY - 50 + "px");
    U.render(/* @__PURE__ */ v(
      V,
      {
        intl: this.props.intl,
        tooltip: e,
        data: n,
        tooltipEnableMarkdown: !1
      }
    ), a._groups[0][0]);
  }
  moveToolTip(e) {
    p.select(".d3MapTooltip").style("left", e.pageX + 15 + "px").style("top", e.pageY - 50 + "px");
  }
  hiddenToolTip(e) {
    p.selectAll(".d3MapTooltip").remove();
  }
  create() {
    const {
      app: e,
      tooltip: n,
      data: s,
      markFillColor: r,
      markBorderColor: a,
      markSizeScale: m,
      markerLabelSize: g,
      measures: y,
      projection: c,
      id: T,
      format: l,
      intl: x,
      useBreaks: L,
      breaks: d,
      pointDimensionStyles: u = [],
      pointStyleBy: f,
      dimension2: b,
      visible: D = !0,
      showDim2OnLegends: A,
      dim2LegendLabel: q
    } = this.props, E = {
      style: l.style === "compacted" ? "decimal" : l.style,
      notation: l.style === "compacted" ? "compact" : "standard",
      currency: l.currency,
      minimumFractionDigits: parseInt(l.minimumFractionDigits),
      maximumFractionDigits: parseInt(l.maximumFractionDigits)
    }, B = p.scaleThreshold().domain(d.map((t) => t.end)).range(d.map((t) => m + t.size)), C = p.scaleThreshold().domain(d.map((t) => t.end)).range(d.map((t) => t.color)), M = p.scaleThreshold().domain(d.map((t) => t.end)).range(d.map((t) => t.borderColor));
    let S = [];
    const z = p.select(this.gRef.current);
    if (e != "csv" && s && s.children)
      S = s.children.map((t) => {
        const o = t.value.split(",");
        let h = { color: r, size: m, border: a }, i = 1;
        return f === "measure" ? (i = t[y[0]], h = { color: C(i), size: B(i), border: M(i) }) : f === "dimension" && t.children && A && (i = t.children[0].value, h = {
          color: u[i + "_color"] || r,
          size: u[i + "_size"] || m,
          border: u[i + "_border"] || a
        }), {
          x: o[0],
          y: o[1],
          value: i,
          metadata: t,
          pointStyle: h
        };
      }), S.sort((t, o) => t.pointStyle.size - o.pointStyle.size);
    else if (e == "csv") {
      const t = s.meta.fields[0], o = s.meta.fields[1], h = s.meta.fields[2];
      S = s.data.map((i) => {
        let _ = { color: r, size: m, border: a };
        return {
          x: i[t],
          y: i[o],
          value: i[h],
          meta: i,
          pointStyle: _
        };
      });
    }
    const F = (t) => {
      const { pointStyleBy: o, dimension2: h } = this.props, i = {};
      return h != "none" && (i[h] = t.metadata.children[0].value), { ...i, ...t, ...t.metadata };
    }, R = this.props.transform ? this.props.transform.k : 1;
    z.attr("class", "zoomable lat-long " + T), z.selectAll(".point-group").remove();
    const w = z.selectAll(".point-group").data(S).enter().append("g").attr("class", "point-group");
    w.append("circle").attr("cx", function(t) {
      return c([t.y, t.x])[0];
    }).attr("cy", function(t) {
      return c([t.y, t.x])[1];
    }).attr("class", "latLong").attr("r", (t) => t.pointStyle.size * 1 / R).attr("stroke-width", 2).style("vector-effect", "non-scaling-stroke").attr("stroke", (t) => t.pointStyle.border).attr("fill", (t) => t.pointStyle.color).on("mouseenter", (t, o) => {
      this.showToolTip(n, F(o), o.pointStyle.color, t);
    }).on("mousemove", (t, o) => {
      this.moveToolTip(t);
    }).on("mouseleave", (t, o) => {
      this.hiddenToolTip(t);
    }), w.append("text").attr("class", "point-label").attr("text-anchor", "middle").attr("dominant-baseline", "middle").attr("x", (t) => c([t.y, t.x])[0]).attr("y", (t) => c([t.y, t.x])[1]).attr("font-size", (t) => g * (10 / R) + "px").attr("fill", "#EEE").text((t) => x.formatNumber(t.value, E)).on("mouseenter", (t, o) => {
      this.showToolTip(n, F(o), o.pointStyle.color, t);
    }).on("mousemove", (t, o) => {
      this.moveToolTip(t);
    }).on("mouseleave", (t, o) => {
      this.hiddenToolTip(t);
    }), this.props.transform && z.attr("transform", this.props.transform);
  }
  componentDidUpdate(e, n, s) {
    const { editing: r, selectedItem: a, onZoomToPoint: m, data: g } = this.props, y = p.select(this.gRef.current);
    if ((r || e.data !== g || e.path !== this.props.path) && this.create(), e.visible != this.props.visible && p.select(this.gRef.current).style("display", this.props.visible ? "block" : "none"), a != null && this.props.selectedItem != e.selectedItem) {
      const T = y.selectAll(".point-group circle").filter((l) => l.metadata.children.find((x) => x.value == a) != null);
      m({ x: T.datum().x, y: T.datum().y });
    }
    this.resize();
  }
  resize() {
    const { markerLabelSize: e } = this.props, n = p.select(this.gRef.current), s = this.props.transform ? this.props.transform.k : 1;
    n && (n.selectAll(".point-group circle").attr("r", (r) => r.pointStyle.size * 1 / s), n.selectAll(".point-group text.point-label").attr("font-size", (r) => e * (10 / s) + "px"));
  }
  componentDidMount() {
    this.create();
  }
  render() {
    const {
      id: e
    } = this.props;
    return /* @__PURE__ */ v("g", { className: "latLong " + e, ref: this.gRef });
  }
}
const Y = (k) => {
  const {
    id: e,
    unique: n,
    filters: s,
    csv: r,
    app: a,
    group: m = "default",
    apiJoinAttribute: g,
    editing: y,
    dimension2: c,
    pointStyleBy: T,
    dvzProxyDatasetId: l,
    settings: x,
    waitForFilters: L
  } = k, d = c != "none" ? "/" + c : "", u = {}, f = s || {};
  return f && f.forEach && f.forEach((b) => {
    b.value != null && b.value.filter((D) => D != null && D.toString().trim() != "").length > 0 && (u[b.param] = b.value);
  }), l && (u.dvzProxyDatasetId = l), /* @__PURE__ */ v(
    j,
    {
      editing: y,
      params: u,
      waitForFilters: L,
      app: a,
      csv: decodeURIComponent(r),
      group: m,
      ignoreErrors: !0,
      isSvg: !0,
      store: [a, n, e],
      source: [g + d],
      children: /* @__PURE__ */ v(N, { children: /* @__PURE__ */ v(X, { ...k }) })
    }
  );
}, K = O(Y);
export {
  K as default
};
