import { isArray as n, cloneDeep as u } from "lodash";
const y = (o, l) => {
  const e = {};
  n(o) ? o.forEach((t) => {
    const a = t.key;
    n(t.data) && t.data.forEach((r) => {
      const s = r.category, c = r.value;
      e[s] || (e[s] = { category: s }), e[s][a] ? e[s][a] += c : e[s][a] = c;
    });
  }) : e.key = {};
  const f = Object.values(e);
  return {
    dimensions: l || Object.keys(f[0]),
    source: Object.values(u(e))
  };
};
export {
  y as parseDataset
};
