import Component from 'ember-component';

/**
* Shamelessly stolen from http://stackoverflow.com/a/27107157
*
* Attributes:
*  - src: image URL
*  - errorSrc: fallback image URL
*/
export default Component.extend({
  tagName: 'img',
  attributeBindings: ['src', 'errorSrc', 'testSelector:data-test-selector'],
  testSelector: null,

  didInsertElement() {
    this._super();
    this.addEventListener(this.$(), 'error', () => {
      this.set('src', this.get('errorSrc'));
    });
  }
});
