import { type PropType } from "vue";
import { EChartsOption } from "echarts";
import { getNormalizedChart, dataSource } from "../../../utils";
import { DataSourceType } from "../../../chartEnum";

export const basicPieProps = {
  width: {
    type: Number as PropType<number>,
    default: 400,
  },
  height: {
    type: Number as PropType<number>,
    default: 260,
  },
  dataSource,
  // 标题
  title: {
    type: Object as PropType<EChartsOption["title"]>,
  },
  // 图例
  legend: {
    type: Object as PropType<EChartsOption["legend"]>,
  },
  // 背景
  backgroundColor: {
    type: String as PropType<string>,
  },
  // 边框
  grid: {
    type: Object as PropType<EChartsOption["grid"]>,
  },
  // 提示框
  tooltip: {
    type: Object as PropType<EChartsOption["tooltip"]>,
  },
  // 饼图数据
  series: {
    type: Array as PropType<EChartsOption["series"]>,
  },
  // color
  color: {
    type: Object as PropType<EChartsOption["color"]>
  }
};

const chartOptions = getNormalizedChart({
  title: {
    text: "饼图标题",
  },
  grid: {
    show: false
  },
  xAxis: {
    show: false
  },
  yAxis: {
    show: false
  }
})

export const defaultPropsValue: EChartsOption = {
  // 组件容器默认属性
  container: {
    props: {
      width: 400,
      height: 260,
    },
  },
  // 图表默认属性
  props: {
    // 数据源
    dataSource: {
      sourceType: DataSourceType.STATIC,
      data: {
        series: [
          {
            type: 'pie',
            name: '系列1',
            data: [
              { value: 335, name: '直接访问' },
              { value: 310, name: '邮件营销' },
              { value: 234, name: '联盟广告' },
              { value: 135, name: '视频广告' },
            ]
          }
        ]
      },
      url: location.origin + "/mock/api/get/example/pie",
      method: "POST",
      params: {},
      headers: {},
      refreshTime: 0,
      dataProcess: `
        (res) => {
          // 取出列表
          const data = res.data;

          // 系列数据
          const series = [
            { type: 'pie', name: '价格', data: data.map(item => item.price) },
          ];

          // 返回图表数据
          return { series };
        }
      `
    },
    ...chartOptions
  },
};
