export const columnsObj = {
  0: "A",
  1: "B",
  2: "C",
  3: "D",
  4: "E",
  5: "F",
  6: "G",
};

export type DataResListType = {
  id: number;
  createTime: string;
};

export type DataResTabListTabCutType = "表格" | "柱状图" | "折线图" | "饼图";

export type DataResTabListOptionsType = {
  pcs: number;
  score: null | number;
  customDesc: string;
  name: string;
};

export type DataResTabListTxtType = "单选" | "多选" | "排序" | "填空";

export type DataResTabListType = {
  id: number;
  type: DataResTabListTxtType;
  question: string;
  tabCut: {
    name: DataResTabListTabCutType;
    done: boolean;
  }[];
  tabAc: DataResTabListTabCutType;
  optionsCount: DataResTabListOptionsType[];
};

// ech Type
export type DataResType = {
  name: string;
  value: number;
  index: string;
  bai: string;
  customDesc: string[];
};

export const colorRes = [
  "#5470c6",
  "#91cc75",
  "#fac858",
  "#ee6666",
  "#73c0de",
  "#3ba272",
  "#fc8452",
  "#9a60b4",
  "#ea7ccc",
];

// ech数据获取总数
export const echResMax = (arr: DataResTabListOptionsType[], flag: boolean) => {
  const max = arr
    .map((v) => (flag ? v.score || 0 : v.pcs))
    .reduce(function (prev, curr) {
      return prev + curr;
    });
  return max;
};

// ech数据整理
export const echResData = (
  arr: DataResTabListOptionsType[],
  flag: boolean,
  max: number
) => {
  const newArr: DataResType[] = arr.map((v, i) => ({
    name: v.name,
    value: flag ? v.score || 0 : v.pcs,
    index: v.name === "其他" ? "自定义回答" : Reflect.get(columnsObj, i),
    bai: Math.round(((flag ? v.score || 0 : v.pcs) / max) * 100) + "%",
    customDesc:
      v.name === "其他"
        ? (v.customDesc || "").split(";").filter((v) => v)
        : ([] as string[]),
  }));
  return newArr;
};
