export default function getLine(data, xAxisData, color, commonOpt, lineOpt, type) {
    let tooltip;
    if (data.length < 2) {
        tooltip = {
            trigger: 'item'
        }
    } else {
        tooltip = {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        }
    }
    return {
        color,
        tooltip,
        legend: {
            icon: "circle",
            textStyle: {
                color: type == "dark" ? "#fff" : "#000"
            }
        },
        toolbox: {
            show: true,
        },
        xAxis: {
            type: 'category',
            data: xAxisData,
            axisLine: {
                lineStyle: {
                    color: type == "dark" ? "#2f309c" : "#000",
                    type: "dotted"
                }
            },
            axisLabel: {
                color: type == "dark" ? "#bac4e8" : "#000"
            },
            axisTick: {
                show: false
            },
        },
        yAxis: {
            type: 'value',
            axisLine: {
                show: false,
                lineStyle: {
                    color: type == "dark" ? "#2f309c" : "#000"
                }
            },
            axisLabel: {
                color: type == "dark" ? "#bac4e8" : "#000"
            },
            axisTick: {
                show: false
            },
            splitLine: {
                lineStyle: {
                    color: type == "dark" ? "#2f309c" : '#000',
                    type: "dotted"
                }
            }
        },
        ...commonOpt,
        series: getSeries(data, lineOpt)
    }
}

function getSeries(data, lineOpt) {
    let arr = [];
    data.forEach(element => {
        arr.push({
            name: element.name,
            type: 'line',
            symbolSize: 10,
            symbol: 'circle',
            itemStyle: {
                borderWidth: 0,
            },
            data: element.data,
            ...lineOpt
        })
    });
    return arr
}