/**
 * 路段-统计信息-作业完成率
 */
import React from 'react';
import * as echarts from 'echarts';
import ReactEcharts from 'echarts-for-react';
import SubTitle from '../../../vm-sub-title';
import NoData from '../../../vm-nodata';

interface TypeProps {
    data: Array<any>;
}

function Zywcl(props: TypeProps) {
    const { data } = props;
    let xData = [],
        values = [];
    if (data?.length > 0) {
        xData = data.map(ele => ele.workDate);
        values = data.map(ele => ele.rate);
    }
    const option = {
        color: ['#00FFE7'],
        tooltip: {
            trigger: 'axis',
        },
        legend: {
            show: false,
        },
        grid: {
            left: '8%',
            right: '6%',
            bottom: 20,
        },
        xAxis: {
            type: 'category',
            boundaryGap: true,
            axisTick: {
                show: false,
            },
            axisLabel: {
                color: '#fff',
            },
            data: xData,
        },
        yAxis: {
            type: 'value',
            name: '(%)',
            min: 0,
            nameTextStyle: {
                color: '#fff',
            },
            splitNumber: 5,
            axisLabel: {
                color: '#fff',
            },
            splitLine: {
                lineStyle: {
                    type: 'dashed',
                    color: 'rgba(151,151,151,0.28)',
                },
            },
        },
        series: [
            {
                name: '作业完成率',
                type: 'line',
                data: values,
                areaStyle: {
                    color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [
                        {
                            offset: 0,
                            color: 'rgba(0, 0, 0, 0.5)',
                        },
                        {
                            offset: 1,
                            color: '#00FFE7',
                        },
                    ]),
                },
            },
        ],
    };

    return (
        <div className="road-statistic-charts-zywcl">
            <SubTitle title="作业完成率分析" />
            <div className="road-statistic-charts-lcfx-contain">
                {data?.length > 0 ? (
                    <ReactEcharts
                        option={option}
                        notMerge
                        lazyUpdate
                        style={{ height: '100%', width: '100%' }}
                    />
                ) : (
                    <NoData />
                )}
            </div>
        </div>
    );
}

export default Zywcl;
