import { color } from "echarts";

export const getLineOption = (xData = [], seriesData = []) => ({
  tooltip: {
    trigger: "axis",
  },
  grid: {
    left: "3%",
    right: "4%",
    bottom: "15%",
    top: "5%",
    containLabel: true,
  },
  legend: {
    data: ["健康度指数（%）"],
    bottom: "0%",
    icon: "circle",
    itemWidth: 10,
    itemHeight: 10,
    itemGap: 10,
  },
  xAxis: {
    type: "category",
    axisTick: {
      show: false,
    },
    axisLine: {
      lineStyle: {
        color: "#E9ECF2",
      },
    },
    axisLabel: {
      color: "rgba(0,0,0,0.6)",
    },
    data: xData,
  },
  yAxis: {
    type: "value",
    axisLabel: {
      color: "rgba(0,0,0,0.6)",
    },
    splitLine: {
      lineStyle: {
        color: "#E9ECF2",
        type: "dashed",
      },
    },
  },
  series: [
    {
      name: "健康度指数（%）",
      type: "line",
      color: "#399DFA",
      data: seriesData,
      smooth: true,
    },
  ],
});

export const getDustLineOption = (xData = [], seriesData = []) => ({
  tooltip: {
    trigger: "axis",
  },
  grid: {
    left: "3%",
    right: "4%",
    bottom: "15%",
    top: "5%",
    containLabel: true,
  },
  legend: {
    data: ["周期(天数)"],
    bottom: "0%",
    itemWidth: 20,
    itemHeight: 10,
    itemGap: 10,
  },
  xAxis: {
    type: "category",
    axisTick: {
      show: false,
    },
    axisLine: {
      lineStyle: {
        color: "#E9ECF2",
      },
    },
    axisLabel: {
      color: "rgba(0,0,0,0.6)",
    },
    data: xData,
  },
  yAxis: {
    type: "value",
    axisLabel: {
      color: "rgba(0,0,0,0.6)",
    },
    splitLine: {
      lineStyle: {
        color: "#E9ECF2",
        type: "dashed",
      },
    },
  },
  series: [
    {
      name: "周期(天数)",
      type: "line",
      color: "#399DFA",
      data: seriesData,
      smooth: true,
    },
  ],
});

// 布袋监测图表配置
export const getBagMonitoringChartOption = (xData = [], seriesData = []) => ({
  tooltip: {
    trigger: "axis",
    axisPointer: {
      type: "line",
      lineStyle: {
        color: "#6E7079",
        width: 1,
      },
    },
  },
  grid: {
    left: "20",
    right: "20",
    bottom: "30",
    top: "3%",
    containLabel: true,
  },
  // x轴的文字去除年月日
  xAxis: {
    type: "category",
    boundaryGap: false,
    axisLine: {
      lineStyle: {
        color: "#E9ECF2",
      },
    },
    axisLabel: {
      color: "rgba(0,0,0,0.6)",
      fontSize: 12,
      interval: "auto",
      rotate: 0,
      formatter: function (value) {
        return value.split(' ')[1];
      }
    },
    axisTick: {
      show: false,
    },
    data: xData,
  },
  yAxis: {
    type: "value",
    min: 0,
    // max: 600,
    // interval: 200,
    axisLabel: {
      color: "rgba(0,0,0,0.6)",
      formatter: "{value}",
    },
    splitLine: {
      lineStyle: {
        color: "#E9ECF2",
        type: "dashed",
      },
    },
  },
  series: [
    {
      name: "监测值",
      type: "line",
      smooth: false,
      symbol: "none",
      sampling: "average",
      itemStyle: {
        color: "#7B68EE",
      },
      lineStyle: {
        width: 1,
      },
      areaStyle: {
        color: {
          type: "linear",
          x: 0,
          y: 0,
          x2: 0,
          y2: 1,
          colorStops: [
            {
              offset: 0,
              color: "rgba(123, 104, 238, 0.4)",
            },
            {
              offset: 1,
              color: "rgba(123, 104, 238, 0.1)",
            },
          ],
        },
      },
      data: seriesData,
    },
  ],
});

export const getLineOption2 = (xData = [], seriesData = [], legendDesc = "健康度指数（%）") => ({
  tooltip: {
    trigger: "axis",
  },
  grid: {
    left: "5%",
    right: "5%",
    bottom: "15%",
    top: "20%",
  },
  legend: {
    data: [legendDesc],
    top: "0%",
    icon: "circle",
    itemWidth: 10,
    itemHeight: 10,
    itemGap: 10,
  },
  xAxis: {
    type: "category",
    axisTick: {
      show: false,
    },
    axisLine: {
      lineStyle: {
        color: "#E9ECF2",
      },
    },
    axisLabel: {
      color: "rgba(0,0,0,0.6)",
    },
    data: xData,
  },
  yAxis: {
    type: "value",
    axisLabel: {
      color: "rgba(0,0,0,0.6)",
    },
    splitLine: {
      lineStyle: {
        color: "#E9ECF2",
        type: "dashed",
      },
    },
  },
  series: [
    {
      name: legendDesc,
      type: "line",
      color: "#399DFA",
      data: seriesData,
      smooth: true,
    },
  ],
});

export const getGaugeOption = (option) => {
  return {
    series: [
      {
        type: "gauge",
        startAngle: 220,
        endAngle: 320,
        center: ["50%", "50%"],
        radius: "90%",
        min: option.min || 0,
        max: option.max || 100,
        splitNumber: 8,
        axisLine: {
          lineStyle: {
            width: 30,
            color: [
              [0.2, "#fd666d"],
              [0.8, "#48cd4d"],
              [1, "#fd666d"],
            ],
          },
        },
        pointer: {
          itemStyle: {
            color: 'auto',
          }
        },
        axisTick: {
          distance: -30,
          length: 10,
          lineStyle: {
            color: "#fff",
            width: 2,
          },
        },
        splitLine: {
          distance: -30,
          length: 38,
          lineStyle: {
            color: '#fff',
            width: 2
          },
          
        },
        axisLabel: {
          color: 'inherit',
          fontSize: 10,
          distance: 30,
          rotate: "tangential",
          formatter: option.formatter || "{value}",
        },
        title: {
          offsetCenter: [0, "70%"],
          fontSize: 14,
          fontWeight: "bolder",
        },
        detail: {
          fontSize: 20,
          offsetCenter: [0, 40],
          valueAnimation: true,
          formatter: function (value) {
            return Math.round(value * 100) + "";
          },
          color: "inherit",
        },
        data: [
          {
            value: option.value || 0,
            name: option.chartName || '',
          },
        ],
      },
    ],
  };
}