import pkg from '../package.json'
import Line from '../packages/line'
import Bar from '../packages/bar'
import Pie from '../packages/pie'
import Scatter from '../packages/scatter'
import Treemap from '../packages/treemap'
import Clock from '../packages/clock'
import Count from '../packages/count'
import Rank from '../packages/rank'
import Carousel from '../packages/carousel'
import CarouselItem from '../packages/carousel-item'

const components = [
  Line,
  Bar,
  Pie,
  Scatter,
  Treemap,
  Clock,
  Count,
  Rank,
  Carousel,
  CarouselItem
]

const install = function(Vue, opts = {}) {
  /* istanbul ignore if */
  if (install.installed) return

  let VueECharts = require('vue-echarts')
  Vue.component('chart', VueECharts) // vue-charts

  components.map(component => {
    Vue.component(component.name, component)
  })
}

/* istanbul ignore if */
if (typeof window !== 'undefined' && window.Vue) {
  install(window.Vue)
}

module.exports = {
  version: pkg.version,
  install,
  Line,
  Bar,
  Pie,
  Scatter,
  Treemap,
  Clock,
  Count,
  Rank,
  Carousel,
  CarouselItem
}
