import * as echarts from "echarts";
const getMultiLineChart = (dataX, dataY1, dataY2, dataY3, dataY4, dataY5, dataY6) => {
  const colors = ['#055FC2', '#14A8A8', '#722FD1', '#FA8C15', '#69B2FF', '#D35E61']
  const names = ['科技法案', '出口管制', '科技政令', '合作限制', '市场准入', '人才限制']
  const dataArr = [dataY1, dataY2, dataY3, dataY4, dataY5, dataY6]

  const series = dataArr.map((d, i) => ({
    name: names[i],
    type: 'line',
    symbol: 'none',
    lineStyle: { width: 2, color: colors[i] },
    areaStyle: {
      color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
        { offset: 0, color: colors[i] },
        { offset: 1, color: 'rgba(255,255,255,0)' }
      ])
    },
    data: d,
    emphasis: { focus: 'series' },
    // 关键：只在最后一个点显示跟随文字
    label: {
      show: true,
      position: 'end',               // 最后一个点右侧
      formatter: p => `{a|${names[i]}} {b|${names[i]}}`,
      rich: {
        a: { color: '#757B82', fontSize: 12, padding: [0, 6, 0, 0] },
        b: { color: colors[i], fontSize: 12 }
      }
    }
  }))

  return {
    tooltip: { trigger: 'axis', axisPointer: { type: 'cross' } },
    grid: { top: '5%', right: '20%', bottom: '0%', left: '0%', containLabel: true },
    xAxis: { type: 'category', boundaryGap: false, data: dataX },
    yAxis: { type: 'value', splitLine: { lineStyle: { color: '#ebebeb' } } },
    legend: { show: false },   // 隐藏官方 legend
    color: colors,
    series
  }
}

export default getMultiLineChart