// echarts 图表配置

export const pieOption = (data: { names: string[]; values: number[]; total: number }) => {
  const seriesData = data.names.map((name, index) => ({
    value: data.values[index],
    name: name
  }))

  return {
    tooltip: {
      trigger: 'item',
      formatter: '{b}: {c} ({d}%)'
    },
    legend: {
      orient: 'vertical',
      left: 'right',
      data: data.names
    },
    series: [
      {
        name: '合作类型',
        type: 'pie',
        radius: ['40%', '70%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: [8, 8, 0, 0]
        },
        label: {
          show: false
        },
        emphasis: {
          label: {
            show: true
          }
        },
        labelLine: {
          show: false
        },
        data: seriesData,
        color: ['rgba(105, 177, 255, 1)', 'rgba(255, 192, 105, 1)', 'rgba(135, 232, 222, 1)']
      }
    ]
  }
}

// 完整环形饼图配置
export const semiDonutOption = (data: { names: string[]; values: number[] }) => {
  const seriesData = data.names.map((name, index) => ({
    value: data.values[index],
    name: name
  }))

  return {
    tooltip: {
      trigger: 'item',
      formatter: '{b}: {c} ({d}%)'
    },
    legend: {
      show: false
    },
    series: [
      {
        name: '合作类型',
        type: 'pie',
        center: ['50%', '50%'],
        radius: ['55%', '80%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderWidth: 2,
          borderColor: '#fff'
        },
        label: {
          show: false
        },
        emphasis: {
          label: {
            show: false
          }
        },
        labelLine: {
          show: false
        },
        data: seriesData,
        color: ['rgba(105, 177, 255, 1)', 'rgba(255, 192, 105, 1)', 'rgba(135, 232, 222, 1)']
      }
    ]
  }
}
