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


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

  const option = useMemo(() => {
    return {
      color: ['#3CE88F', '#5F8BFF', '#F69552'],
      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: '10%',
        top: '25%',
        containLabel: true,
      },
      legend: {
        data: ['立案数', '结案数', '结案率'],
        icon: "circle",
        top: 40,
        itemGap: 50,
        textStyle: {
          fontSize: '16px',
          color: '#E4EDFF',
        }
      },
      xAxis: [
        {
          type: 'category',
          boundaryGap: true, //坐标轴两端不留空
          axisLine: {
            show: false, //隐藏X轴轴线
          },
          axisLabel: {
            show: true,
            textStyle: {
              padding: [2, 0, 0, 0],
              color: '#CBEDFF',
            },
            // formatter: (params) => {
            //   console.log(params)
            // },
          },
          axisTick: {
            show: false, //隐藏X轴刻度
          },
          axisPointer: {
            type: 'shadow',
          },
          data: dataSource?.map(item => item.name),
        },
      ],
      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, 0],
            fontSize: 16
          },
          splitLine: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        },
        {
          type: 'value',
          name: '%',
          min: 0,
          max: 100,
          interval: 25,
          nameTextStyle: {
            color: '#CBEDFF',
            padding: [0, 0, 20, 0],
            fontSize: 16
          },
          axisLabel: {
            textStyle: {
              color: '#CBEDFF',
              fontSize: 16
            },
          },
          //name的样式设计
          splitLine: {
            show: false,
          },
          axisLine: {
            show: false,
          },
          axisTick: {
            show: false,
          },
        },
      ],
      series: [
        {
          name: '立案数',
          type: 'bar',
          stack: true, //堆叠柱状图
          barWidth: 14, //柱状图宽度
          itemStyle: {
            // barBorderRadius: [12, 12, 12, 12],
          },
          data: dataSource?.map(item => item.total),
        },
        {
          name: '结案数',
          type: 'bar',
          stack: true, //堆叠柱状图
          barWidth: 14, //柱状图宽度
          itemStyle: {
            // barBorderRadius: [12, 12, 0, 0],
          },
          data: dataSource?.map(item => item.caseClosedNum),
        },
        {
          name: '结案率',
          type: 'line',
          yAxisIndex: 1,
          data: dataSource?.map(item => item.completionRate),
        },
      ]
    }
  }, [dataSource])

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

export default LineBarCharts
