import Scatter from './ui/scatter'
import Label from './ui/label'
import Heatmap from './ui/heatmap'
import Cluster from './ui/cluster'
import Bar from './ui/bar'
import Pie from './ui/pie'
import Line from './ui/line'
import Polygon from './ui/polygon'
import Admin from './ui/admin'

class Painter {
  constructor(vMap) {
    this.vMap = vMap
    this._painer = {
      scatter: Scatter,
      label: Label,
      heatmap: Heatmap,
      cluster: Cluster,
      bar: Bar,
      pie: Pie,
      line: Line,
      polygon: Polygon,
      admin: Admin
    }
  }

  draw(layer, zIndex) {
    if (!this._painer[layer.type]) {
      throw new Error(
        `Error in component "${layer.name}(${layer.id})": Invalid component type "${layer.type}"`
      )
    }
    let component = new this._painer[layer.type](layer, this.vMap.scene, zIndex)
    return component
  }
}

export default Painter
