import Dom from '../../libs/dom'
import Widget from '../widget'

class Image extends Widget {
  constructor(layer, screen) {
    super(layer, screen)
    let container = Dom.createElement('div', 'image-container comp', this.el)
    if (layer.paint.href) {
      this.linkDom = Dom.createElement('a', '', container)
      this.image = Dom.createElement('img', '', this.linkDom)
    } else {
      this.image = Dom.createElement('img', '', container)
    }
    this.image.draggable = false
  }

  setPaint() {
    let newPaint = this._mergePaint()
    if (this.linkDom) {
      this.linkDom.href = newPaint.href
      this.linkDom.target = newPaint.target
    }
    this.image.src = newPaint.src
    this.image.alt = newPaint.alt
    Dom.css(this.image, newPaint.style)
  }
}

export default Image
