import type { EChartsOption } from '@vben/plugins/echarts';

/** 能耗趋势：综合能耗柱状 + 成本折线（双 Y 轴） */
export function getEnergyTrendChartOptions(
  dates: string[],
  tce: number[],
  cost: number[],
): EChartsOption {
  return {
    grid: { bottom: 50, left: 60, right: 60, top: 30 },
    legend: { bottom: 0, data: ['综合能耗', '能耗成本'] },
    series: [
      {
        barMaxWidth: 28,
        data: tce,
        itemStyle: { borderRadius: [4, 4, 0, 0], color: '#409EFF' },
        name: '综合能耗',
        type: 'bar',
      },
      {
        data: cost,
        itemStyle: { color: '#E6A23C' },
        name: '能耗成本',
        smooth: true,
        type: 'line',
        yAxisIndex: 1,
      },
    ],
    tooltip: { axisPointer: { type: 'cross' }, trigger: 'axis' },
    xAxis: {
      data: dates,
      type: 'category',
      axisLabel: { hideOverlap: true },
    },
    yAxis: [
      { name: '吨标煤', type: 'value' },
      {
        name: '元',
        splitLine: { show: false },
        type: 'value',
      },
    ],
  };
}

/** 能源结构：按折标煤占比的饼图 */
export function getEnergyTypeChartOptions(
  data: Array<{ color?: string; name: string; value: number }>,
): EChartsOption {
  return {
    legend: { bottom: 0, type: 'scroll' },
    series: [
      {
        avoidLabelOverlap: true,
        data,
        emphasis: { label: { fontSize: 14, fontWeight: 'bold', show: true } },
        itemStyle: { borderColor: '#fff', borderRadius: 6, borderWidth: 2 },
        label: { formatter: '{b}\n{d}%', show: true },
        radius: ['42%', '70%'],
        type: 'pie',
      },
    ],
    tooltip: { formatter: '{b}: {c} 吨标煤 ({d}%)', trigger: 'item' },
  };
}

/** 车间能耗排行：横向柱状图 */
export function getWorkshopChartOptions(
  names: string[],
  values: number[],
): EChartsOption {
  return {
    grid: { bottom: 20, left: 100, right: 40, top: 10 },
    series: [
      {
        barMaxWidth: 18,
        data: values,
        itemStyle: { borderRadius: [0, 4, 4, 0], color: '#7C3AED' },
        label: { position: 'right', show: true },
        name: '综合能耗',
        type: 'bar',
      },
    ],
    tooltip: {
      axisPointer: { type: 'shadow' },
      formatter: '{b}: {c} 吨标煤',
      trigger: 'axis',
    },
    xAxis: { name: '吨标煤', type: 'value' },
    yAxis: { data: names, inverse: true, type: 'category' },
  };
}
