import { jsx as l } from "react/jsx-runtime";
import p from "react";
import { createRoot as f } from "react-dom/client";
import * as o from "d3";
import y from "./Tooltip.js";
import { loadJSON as T } from "./Utils.js";
let L = class extends p.Component {
  constructor() {
    super(), this.loadJSON = this.loadJSON.bind(this), this.create = this.create.bind(this), this.createLayer = this.createLayer.bind(this), this.loadJSON = this.loadJSON.bind(this), this.showToolTip = this.showToolTip.bind(this), this.moveToolTip = this.moveToolTip.bind(this), this.gRef = p.createRef(), this.state = { json: null };
  }
  loadJSON(e) {
    return T(e);
  }
  createLayer(e) {
    alert("please implement createLayer");
  }
  applyInitialTransform() {
    const { editing: e, initialPosition: t, width: s, height: a } = this.props;
    if (t && t.width) {
      const { x: i, y: n, k: r, width: h, height: c } = t, d = i + (s - h) / 2 * (1 - r), m = n + (a - c) / 2 * (1 - r);
      o.select(this.gRef.current).attr("transform", `translate(${d},${m}) scale(${r})`);
    } else
      o.select(this.gRef.current).attr("transform", `translate(${t.x},${t.y}) scale(${t.k})`);
  }
  create() {
    const {
      file: e
    } = this.props;
    this.state.json ? this.createLayer(this.state.json) : this.loadJSON(e).then((t) => {
      this.setState({ json: t }), this.createLayer(t);
    });
  }
  showToolTip(e, t, s, a) {
    if (t) {
      const i = o.select("body").append("div").attr("class", "d3MapTooltip").style("position", "absolute").html("").style("left", window.event.pageX + 15 + "px").style("top", window.event.pageY - 50 + "px");
      f(i._groups[0][0]).render(/* @__PURE__ */ l(
        y,
        {
          intl: this.props.intl,
          tooltip: e,
          data: t,
          tooltipEnableMarkdown: !1
        }
      ));
    }
  }
  moveToolTip(e) {
    o.select(".d3MapTooltip").style("left", window.event.pageX + 15 + "px").style("top", window.event.pageY - 50 + "px");
  }
  hiddenToolTip(e) {
    o.selectAll(".d3MapTooltip").remove();
  }
  componentDidMount() {
    this.props.zoom && this.gRef.current && this.applyInitialTransform(), this.create();
  }
  render() {
    const { name: e, height: t, width: s } = this.props;
    return /* @__PURE__ */ l("g", { className: "layer", ref: this.gRef });
  }
};
export {
  L as default
};
