import * as echarts from "echarts";

export const initEcharts1 = (mainRef, chartInstance, data) => {
  chartInstance.current = echarts.init(mainRef.current);

  const option = {
    color: ["#7d4449", "#009944", "#167ce4", "#00ffff"],
    tooltip: {
      trigger: "axis",
    },
    legend: {
      textStyle: {
        color: "#fff",
        fontSize: "12px",
      },
      top: 8,
      right: 10,
    },
    grid: {
      left: "4%",
      right: "4%",
      bottom: "10%",
      top: "26%",
      containLabel: true,
    },
    dataZoom: [
      {
        type: "slider",
        height: 6,
        bottom: 0,
        show: true,
        start: 0,
        end: 50,
        handleSize: 3,
        handleStyle: {
          color: "#DCE2E8",
        },
        xAxisIndex: [0],
        filterMode: "filter",
        showDetail: false,
      },
    ],
    xAxis: {
      data: data.map(item => item.departmentName),
      type: "category",
      boundaryGap: false,
      axisLine: {
        symbol: "none",
        lineStyle: {
          color: "#fff",
        },
      },
      axisTick: {
        show: false,
      },
      axisLabel: {
        interval: 0,
        color: "#fff",
        fontSize: 12,
      },
    },
    yAxis: {
      type: "value",
      axisLabel: {
        color: "#fff",
        fontSize: 12,
        padding: [0, 10, 0, 0],
      },
      splitLine: {
        lineStyle: {
          color: "rgba(255,255,255,0.79)",
          type: "dashed",
        },
      },
    },
    series: [
      {
        name: "风险点检查覆盖率",
        type: "line",
        data: data.map(item => item.riskCoverageRate),
        smooth: true,
        lineStyle: {
          width: 2,
        },
        showSymbol: false,
        symbol: "circle",
        symbolSize: 6,
      },
      {
        name: "隐患清单排查率",
        data: data.map(item => item.hiddenInvestigationRate),
        type: "line",
        smooth: true,
        lineStyle: {
          width: 2,
        },
        showSymbol: false,
        symbol: "circle",
        symbolSize: 6,
      },
      {
        name: "隐崽整改率",
        data: data.map(item => item.hiddenRectificationRate),
        type: "line",
        smooth: true,
        lineStyle: {
          width: 2,
        },
        showSymbol: false,
        symbol: "circle",
        symbolSize: 6,
      },
      {
        name: "检查任务完成率",
        data: data.map(item => item.checkTaskCompletionRate),
        type: "line",
        smooth: true,
        lineStyle: {
          width: 2,
        },
        showSymbol: false,
        symbol: "circle",
        symbolSize: 6,
      },
    ],
  };

  chartInstance.current.setOption(option);
};
