import { jsx as m } from "react/jsx-runtime";
import c from "react";
const b = ({ children: i, data: e }) => {
  const {
    data: a,
    meta: { fields: n }
  } = e;
  n[0];
  const o = n.slice(1).filter((t) => !t.startsWith("_")), l = o.map((t) => {
    const r = {};
    return r.id = t, r.data = a.map((s) => {
      const f = {};
      return Object.keys(s).forEach((p) => {
        f[p] = s[p];
      }), {
        x: s[n[0]],
        y: s[t],
        variables: { ...f, field: t }
      };
    }), r;
  }), d = {
    indexBy: "id",
    keys: o,
    data: l
  };
  return c.Children.map(
    i,
    (t) => c.cloneElement(t, { options: d })
  );
}, x = ({ children: i, data: e }) => {
  const {
    data: a,
    meta: { fields: n }
  } = e;
  n[0];
  const o = e.data.map((t) => t.ID), l = a.map((t) => {
    const r = {}, s = {};
    return Object.keys(t).forEach((f) => {
      s[f] = t[f];
    }), s.field = n[1], r.variables = s, r.id = t[n[0]], r.label = t[n[0]], r.value = t[n[1]], r;
  }), d = {
    keys: o,
    indexBy: "id",
    data: l
  };
  return c.Children.map(
    i,
    (t) => c.cloneElement(t, { options: d })
  );
}, u = ({ children: i, data: e, measures: a }) => {
  const {
    data: n,
    meta: { fields: o }
  } = e, l = o[0], d = a && a.length > 0 ? a : o.slice(1).filter((r) => !r.startsWith("_")), t = {
    indexBy: l,
    keys: d,
    data: n
  };
  return c.Children.map(
    i,
    (r) => c.cloneElement(r, { options: t })
  );
}, v = ({ children: i, data: e, keys: a, type: n, measures: o }) => {
  if (n == "bar")
    return /* @__PURE__ */ m(u, { data: e, keys: a, measures: o, children: i });
  if (n == "line")
    return /* @__PURE__ */ m(b, { data: e, keys: a, measures: o, children: i });
  if (n == "bump")
    return /* @__PURE__ */ m(b, { data: e, keys: a, measures: o, children: i });
  if (n == "pie")
    return /* @__PURE__ */ m(x, { data: e, keys: a, measures: o, children: i });
  if (n == "radar")
    return /* @__PURE__ */ m(u, { data: e, keys: a, measures: o, children: i });
};
export {
  v as default
};
