import { jsx as a, jsxs as x } from "react/jsx-runtime";
import { useRef as H, useState as O, useEffect as J } from "react";
import { Container as K } from "semantic-ui-react";
import $ from "../data/DataProvider.js";
import Q from "../data/DataConsumer.js";
import "@devgateway/wp-react-lib";
import { connect as W } from "react-redux";
import { useSpring as X, animated as Y } from "@react-spring/web";
const Z = (r) => {
  const {
    editing: e = !1,
    unique: n,
    intl: t,
    childContent: u,
    "data-csv": D = "",
    "data-dimension1": p = "none",
    "data-dvz-proxy-dataset-id": v,
    "data-no-data-message": F = "No data matches your selection",
    "data-view-mode": z = "info",
    "data-height": b,
    "data-app": o,
    "data-measures": l = "{}",
    "data-format": S = "{}",
    "data-group": f,
    "data-filters": g = "[]",
    "data-number-font-size": h = 20,
    "data-label-font-size": i = 20,
    "data-number-color": c = "#000000",
    "data-label-color": d = "#000000",
    "data-label": y = "",
    "data-group-label": P = "",
    "data-group-label-color": R = "",
    "data-group-label-font-size": T = "",
    "data-wait-for-filters": U = "false",
    "data-no-data-text": A = "-"
  } = r, E = t.locale, V = H(null), q = (s) => e ? s : decodeURIComponent(s), N = (s) => {
    try {
      return JSON.parse(q(s));
    } catch {
      console.error("error parsing value:" + s);
    }
    return null;
  }, C = N(l), m = C && C[o] ? C[o].format : null;
  console.log(m);
  const B = m ? {
    style: m.style === "compacted" ? "decimal" : m.style,
    notation: m.style === "compacted" ? "compact" : "standard",
    currency: m.currency,
    minimumFractionDigits: parseInt(m.minimumFractionDigits),
    maximumFractionDigits: parseInt(m.maximumFractionDigits)
  } : {
    notation: "standard",
    currency: "USD",
    minimumFractionDigits: 2,
    maximumFractionDigits: 2
  }, [te, ae] = O(z), G = e ? b - 80 : b - 40, L = {}, j = N(g) || {};
  j && j.forEach && j.forEach((s) => {
    s.value != null && s.value.filter((M) => M != null && M.toString().trim() != "").length > 0 && (L[s.param] = s.value);
  }), v && (L.dvzProxyDatasetId = v);
  const w = [];
  return p != "none" && w.push(p), /* @__PURE__ */ a("div", { ref: V, children: /* @__PURE__ */ a(K, { className: "chart container big-number-container", style: { height: b + "px" }, fluid: !0, children: o && o != "none" && /* @__PURE__ */ a(
    $,
    {
      style: { height: `${G}px` },
      params: L,
      app: o,
      group: f,
      source: w.join("/"),
      csv: D,
      editing: e,
      waitForFilters: U === "true",
      store: [o, n, ...w],
      children: /* @__PURE__ */ a(Q, { children: /* @__PURE__ */ a(
        _,
        {
          dimension: p,
          locale: E,
          intl: t,
          app: o,
          format: B,
          measures: N(l),
          label: y,
          numberFontSize: h,
          numberColor: c,
          labelFontSize: i,
          labelColor: d,
          noDataText: A,
          groupLabel: P,
          groupLabelColor: R,
          groupLabelFontSize: T
        }
      ) })
    }
  ) }) });
}, _ = (r) => {
  const {
    app: e,
    measures: n,
    data: t,
    format: u,
    label: D,
    numberColor: p,
    numberFontSize: v,
    dimension: F,
    labelColor: z,
    labelFontSize: b,
    noDataText: o = "-",
    intl: l,
    groupLabel: S,
    groupLabelColor: f,
    groupLabelFontSize: g
  } = r, h = n && n[e] ? Object.keys(n[e]).filter((i) => n[e][i].selected) : [];
  if (F != "none") {
    const i = t.metadata.types.filter((c) => c.dimension === F)[0];
    return t.children.map((c) => {
      const d = i.items.filter((y) => y.code == c.value)[0].value;
      return /* @__PURE__ */ x("div", { className: "big-number-group", style: { display: "flex", flexDirection: "column" }, children: [
        /* @__PURE__ */ x(
          "span",
          {
            className: "big-number-title",
            style: { color: f, fontSize: g + "px" },
            children: [
              /* @__PURE__ */ a("span", { className: "dimension-text", children: d }),
              /* @__PURE__ */ x("span", { className: "group-text", children: [
                " ",
                S
              ] })
            ]
          }
        ),
        /* @__PURE__ */ a("div", { className: "big-number-row", style: { display: "flex", flexDirection: "row" }, children: h.map((y) => /* @__PURE__ */ a("div", { className: "big-number-parent", children: /* @__PURE__ */ a(
          I,
          {
            showDimensionLabel: !0,
            metadata: i,
            dataItem: c,
            measureField: y,
            measure: n[e][y],
            ...r
          }
        ) })) })
      ] });
    });
  } else
    return /* @__PURE__ */ x("div", { children: [
      /* @__PURE__ */ x("span", { style: { color: f, fontSize: g + "px" }, children: [
        " ",
        S
      ] }),
      h.map((i) => /* @__PURE__ */ a(I, { dataItem: t, measureField: i, measure: n[e][i], ...r }))
    ] });
}, I = ({ dataItem: r, format: e, measureField: n, measure: t, numberColor: u, numberFontSize: D, labelColor: p, labelFontSize: v, noDataText: F, label: z, intl: b }) => {
  const o = (r == null ? void 0 : r[n]) ?? null, l = o ? (e == null ? void 0 : e.style) === "percent" ? o / 100 : o : null, [S, f] = O(l);
  J(() => {
    l != null && f(l);
  }, [l]);
  const { number: g } = X({
    from: { number: 0 },
    to: { number: S ?? 0 },
    // reset: true,
    config: {
      mass: 1,
      tension: 120,
      friction: 30
    }
  }), h = {
    color: decodeURIComponent(u),
    fontSize: D + "px",
    textAlign: "center"
  }, i = {
    color: decodeURIComponent(p),
    fontSize: v + "px",
    textAlign: "center"
  }, c = (d) => b.formatNumber(d, { ...e });
  return /* @__PURE__ */ x("div", { className: "big-number", children: [
    /* @__PURE__ */ a("div", { style: h, className: "big-number-value", children: l === null ? F : /* @__PURE__ */ a(Y.span, { children: g.to((d) => c(d)) }) }),
    (t == null ? void 0 : t.customLabel) && /* @__PURE__ */ a("div", { style: i, className: "big-number-label", children: t.customLabel })
  ] });
}, k = (r, e) => {
  const { "data-app": n, "data-group": t } = e, u = r.getIn(["data", "measures", n, t]);
  return u ? {
    injectedMeasures: u
  } : {};
}, ee = {}, de = W(k, ee)(Z);
export {
  de as default
};
