// Copyright 2014 Globo.com Player authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

import Playback from 'base/playback'
import Styler from 'base/styler'
import imgStyle from './public/style.scss'

export default class HTMLImg extends Playback {
  get name() { return 'html_img' }
  get tagName() { return 'img' }
  get attributes() {
    return {
      'data-html-img': ''
    }
  }

  getPlaybackType() {
    return Playback.NO_OP
  }

  constructor(params) {
    super(params)
    this.el.src = params.src
  }

  render() {
    var style = Styler.getStyleFor(imgStyle)
    this.$el.append(style)
    return this
  }
 }

HTMLImg.canPlay = function(resource) {
  return !!resource.match(/(.*).(png|jpg|jpeg|gif|bmp)/)
}

@@ -275,16 +275,49 @@
 le.scss'
+%0Aimport Events from 'base/events'
 %0A%0Aexport
@@ -497,16 +497,132 @@
  %7D%0A  %7D%0A%0A
+  get events() %7B%0A    return %7B%0A      'load': 'onLoad',%0A      'abort': 'onError',%0A      'error': 'onError'%0A    %7D%0A  %7D%0A%0A
   getPla
@@ -835,25 +835,305 @@
     
-return this%0A  %7D%0A 
+this.trigger(Events.PLAYBACK_READY, this.name)%0A    return this%0A  %7D%0A%0A  onLoad(evt) %7B%0A    this.trigger(Events.PLAYBACK_ENDED, this.name)%0A  %7D%0A%0A  onError(evt) %7B%0A    var m = (evt.type === 'error') ? 'load error' : 'loading aborted';%0A    this.trigger(Events.PLAYBACK_ERROR, %7Bmessage: m%7D, this.name)%0A  %7D%0A
 %7D%0A%0AH
@@ -1201,16 +1201,17 @@
 ch(/(.*)
+%5C
 .(png%7Cjp
@@ -1225,13 +1225,20 @@
 gif%7Cbmp)
+%5C?%7B0,1%7D
 /)%0A%7D%0A

enable some events to html image playback