
import { useMemo } from 'react'
import ReactEcharts from 'echarts-for-react';


const LineCharts = ({ dataSource }: { dataSource: any[] }) => {

  const option = useMemo(() => {

    const names = dataSource?.map(item => item.name)

    const series = dataSource?.map(item => {
      return {
        name: item?.name,
        type: 'line',
        data: item?.data?.map((v: any) => v.num),
      }
    })

    console.log(series)

    return {
      color: ['#36BD3B', '#FF9743', '#FF67CB', '#9259FF', '#FFE543'],
      tooltip: {
        trigger: 'axis',
        borderWidth: '0',
        backgroundColor: 'rgba(73,81,92,.95)', //背景颜色
        textStyle: {
          color: '#fff', //字体颜色
        },
        axisPointer: {
          type: 'cross',
          crossStyle: {
            color: '#999',
          },
        },
      },
      grid: {
        left: '0',
        right: '0',
        bottom: '2%',
        top: '25%',
        containLabel: true,
      },
      legend: {
        data: names,
        icon: "path://M0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z",
        top: 10,
        itemGap: 50,
        textStyle: {
          fontSize: '16px',
          color: '#E4EDFF',
        },
        type: 'scroll', // 启用滚动
        pageIconColor: '#E4EDFF',           // 翻页按钮颜色
        pageIconInactiveColor: '#546AA2',   // 禁用按钮颜色
        pageIconSize: 14,                   // 按钮大小
        pageTextStyle: {                    // 页码文字样式
          color: '#E4EDFF'
        },
      },
      xAxis: [
        {
          type: 'category',
          boundaryGap: true, //坐标轴两端不留空
          axisLine: {
            show: false, //隐藏X轴轴线
          },
          axisLabel: {
            show: true,
            interval: 0,
            textStyle: {
              padding: [2, 0, 0, 0],
              color: '#CBEDFF',
            },
          },
          axisTick: {
            show: false, //隐藏X轴刻度
          },
          axisPointer: {
            type: 'shadow',
          },
          data: ['0点', '1点', '2点', '3点','4点', '5点', '6点', '7点','8点','9点','10点','11点', '12点', '13点','14点','15点', '16点','17点','18点','19点','20点', '21点','22点', '23点'],
        },
      ],
      yAxis: [
        {
          type: 'value',
          name: '件',
          min: 0,
          max: 'dataMax',
          // interval: 50,
          axisLabel: {
            textStyle: {
              color: '#CBEDFF',
              fontSize: 16
            },
          },
          //name的样式设计
          nameTextStyle: {
            align: 'left',
            color: '#CBEDFF',
            padding: [0, 0, 20, -20],
            fontSize: 16
          },
          splitLine: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        }
      ],
      series: series
    }
  }, [dataSource])

  return (
    <ReactEcharts
      option={option} // option：图表配置项
      style={{ width: '880px', height: '353px', margin: '0 auto' }}
    />
  )
}

export default LineCharts
