<template>
  <img class="bl___cover-image"
       :src="src"
       @load="load"
       @error="error"
       @click="clickEvent"
       @touchstart="touchstartEvent"
       @touchmove="touchmoveEvent"
       @touchend="touchendEvent"
       @touchcancel="touchcancelEvent"
  />
</template>

<script>
export default {
  name: 'Bili_CoverImage',
  props: {
    "src": {
      type: String,
      default: ''
    },
    "animation": {
      type: String,
      default: ''
    },
  },
  watch: {
    animation(value) {
      this.changeAttr('animation', value);
    }
  },
  data() {
    return {};
  },
  methods: {
    clickEvent(e) {
      this.$emit('click', {
        detail: {
          position: {
            x: e.x,
            y: e.y
          }
        }
      });
    },
    touchstartEvent(e) {
      this.$emit('touchstart', {
        detail: {
          changedTouches: Array.from(e.changedTouches).map(x=>{
            return {
              x: x.pageX,
              y: x.pageY,
            }
          })
        }
      });
    },
    touchmoveEvent(e) {
      this.$emit('touchmove', {
        detail: {
          changedTouches: Array.from(e.changedTouches).map(x=>{
            return {
              x: x.pageX,
              y: x.pageY,
            }
          })
        }
      });
    },
    touchendEvent(e) {
      this.$emit('touchend', {
        detail: {
          changedTouches: Array.from(e.changedTouches).map(x=>{
            return {
              x: x.pageX,
              y: x.pageY,
            }
          })
        }
      });
    },
    touchcancelEvent(e) {
      this.$emit('touchcancel', {
        detail: {
          changedTouches: Array.from(e.changedTouches).map(x=>{
            return {
              x: x.pageX,
              y: x.pageY,
            }
          })
        }
      });
    },
    load(e) {
      this.$emit('load', e);
    },
    error(e) {
      if (Object.keys(this.$listeners).indexOf('error') > -1) {
        this.$emit('error', e);
      }
    },
  }
};
</script>

<style lang="less">
.bl___cover-image {
  width: 100%;
  height: 100%;
  overflow: hidden;
}
</style>

