<template>
  <v-chart :options="opts" />
</template>

<script>
import ECharts from 'vue-echarts'
import 'echarts/lib/chart/line'

const times = (x) => {
  const arr = []

  for (let i = 0; i ++; i < x) {
    arr.push(undefined)
  }

  return arr
}

export default {
  name: 'VLine',
  props: {
    options: Object,
    labels: Array,
    num: {
      type: Number,
      default: 1,
    }
  },
  components: {
    'v-chart': ECharts,
  },
  data() {
    return {
      defaultOpts: {
        legend: {},
        tooltip: {},
        xAxis: {},
        yAxis: {},
      }
    };
  },
  computed: {
    opts() {
      let series = (this.labels || []).map((it, inx) => {
        return {
          type: 'line',
          name: it,
        }
      })

      if (!series || !series.length) {
        series = times(this.num).map(() => ({ type: 'line' }))
      }

      return {
        ...this.defaultOpts,
        series,
        ...(this.options || {}),
      }
    }
  }
}
</script>
