import m from "react";
import { measuresMap as M, typesMap as O, getTranslatedValue as n } from "./Utils.js";
const x = (E) => {
  const { children: b, data: i, measures: y, locale: o, customLabels: h } = E, c = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set(), w = M(i);
  if (i && i.children) {
    const v = [], s = O(i), p = [];
    i.children.forEach((e) => {
      if (c.add(s[e.type]), e.children)
        e.children.forEach((a) => {
          const l = new Object(), u = new Object();
          u[e.type] = n(
            s[e.type].items.filter((t) => t.value === e.value)[0],
            o
          ) || e.value, u[a.type] = n(
            s[a.type].items.filter((t) => t.value === a.value)[0],
            o
          ) || a.value, Object.keys(a).forEach((t) => {
            u[t] = a[t];
          }), l.id = n(
            s[e.type].items.filter((t) => t.value === e.value)[0],
            o
          ) + " - " + n(
            s[a.type].items.filter((t) => t.value === a.value)[0],
            o
          ), p.push(e.value + " - " + a.value), l.value = a[y[0]], l.label = n(
            s[e.type].items.filter((t) => t.value === e.value)[0],
            o
          ) + " - " + n(
            s[a.type].items.filter((t) => t.value === a.value)[0],
            o
          ), l.variables = u, v.push(l);
          let r = Array.from(c).find((t) => t.dimension === a.type) || { ...s[a.type] };
          Array.from(c).some((t) => t.dimension === a.type) || c.add(r);
          let j = r.items.find((t) => t.id === l.id) || {
            dimension: a.type,
            type: a.type,
            categoryStyle: { color: "#484848" },
            position: 0,
            labels: {},
            code: l.id,
            value: l.id,
            id: l.id
          };
          r.items.some((t) => t.id === l.id) || r.items.push(j);
        });
      else {
        const a = s[e.type].items.filter(
          (r) => r.value === e.value
        )[0], l = new Object(), u = new Object();
        u[e.type] = n(a, o) || e.value, Object.keys(i).forEach((r) => {
          u[r] = e[r];
        }), c.add(s[e.type]), l.id = n(a, o) || e.value, l.label = n(a, o) || e.value, l.position = a.position || 0, l.value = e[y[0]], l.variables = u, v.push(l);
      }
    });
    const f = {
      indexBy: "id",
      keys: [],
      measuresMetadata: d,
      dimensionsMetadata: c,
      data: v.sort((e, a) => a.value - e.value),
      metadata: i.metadata
    };
    return m.Children.map(
      b,
      (e) => m.cloneElement(e, { options: f })
    );
  } else {
    const v = i.metadata.measures.filter(
      (e) => y.includes(e.value)
    ), s = [], p = {};
    Object.keys(i).forEach((e) => {
      p[e] = i[e];
    }), v.forEach((e) => {
      const a = {};
      a.type = "measure", a.measureFieldName = e.value, a.id = h[e.value] || n(w[e.value], o), a.position = e.position, a.label = h[e.value] || n(w[e.value], o), a.value = i[e.value], a.variables = p, s.push(a);
    });
    const f = {
      indexBy: "id",
      keys: [],
      measuresMetadata: d,
      dimensionsMetadata: c,
      data: s.sort((e, a) => a.value - e.value),
      metadata: i.metadata
    };
    return m.Children.map(
      b,
      (e) => m.cloneElement(e, { options: f })
    );
  }
};
export {
  x as PieData,
  x as default
};
