import { isArray as i, cloneDeep as u } from "lodash";
const g = (c, f) => {
  const e = {};
  i(c) ? c.forEach((a) => {
    const r = a.key;
    i(a.data) && a.data.forEach((o) => {
      const s = o.category, n = o.value;
      e[s] || (e[s] = {
        category: s,
        _rawData: o.userdata
        // 保存原始数据
      }), e[s][r] ? e[s][r] += n : e[s][r] = n;
    });
  }) : e.key = {};
  const l = Object.values(e), t = Object.keys(l[0]).filter((a) => a !== "_rawData"), d = t.findIndex((a) => a === "category");
  return t.splice(d, 1), t.unshift("category"), {
    dimensions: f || t,
    source: Object.values(u(e))
  };
};
export {
  g as parseDataset
};
