import { jsx as m } from "react/jsx-runtime";
import "react";
import h from "react-markdown";
import g from "remark-gfm";
import y from "rehype-raw";
import f from "string-template";
const x = /(\+?\%)[\(]([A-z0-9,.,-]+)\)/gi, F = /(\+?\#)[\(]([A-z0-9,.,-]+)\)/gi, N = /(\+?\#C)[\(]([A-z0-9,.,-]+)\)/gi, p = (o, t, a, n, e, r) => {
  let i, s = t;
  for (; (i = o.exec(t)) !== null; ) {
    const c = i[2], l = i[1], v = ((u, d = 2) => e.formatNumber(n ? u / 100 : u, {
      maximumFractionDigits: d,
      ...a,
      signDisplay: l && l.startsWith("+") ? "never" : "auto"
    })).apply(void 0, c.split(","));
    s = s.replaceAll(i[0], v);
  }
  return s;
}, b = (o, t, a, n) => {
  let e = n ? f(o, t) : f(o, t).replace(/(?:\r\n|\r|\n)/g, "<br>");
  return e = p(x, e, { style: "percent" }, !0, a), e = p(F, e, { style: "decimal" }, !1, a), e = p(N, e, { notation: "compact" }, !1, a), e;
}, E = ({ tooltip: o, d: t, intl: a, tooltipEnableMarkdown: n }) => {
  const { color: e, data: r } = t.datum || t.point || t, i = t.value || (t.datum ? t.datum.value : null) || (t.point ? t.point.data.y : null);
  if (r) {
    const s = r.variables ? r.variables[t.id] || r.variables : r, c = { field: t.point ? t.point.serieId : t.id, ...s, value: i };
    r.measureFieldName && (c.populationValue = r.variables[r.measureFieldName + "Population"]);
    const l = b(o, c, a, n);
    return n ? /* @__PURE__ */ m("div", { className: "chart tooltip", children: /* @__PURE__ */ m(h, { children: l, remarkPlugins: [g], rehypePlugins: [y] }) }) : /* @__PURE__ */ m("div", { className: "chart tooltip", children: /* @__PURE__ */ m("div", { dangerouslySetInnerHTML: { __html: l } }) });
  } else
    return /* @__PURE__ */ m("div", {});
};
export {
  E as default,
  b as formatContent
};
