<!-- webview only -->
<template>
  <div class="bl___cover-button"
       @click="clickEvent"
       @touchstart="touchstartEvent"
       @touchmove="touchmoveEvent"
       @touchend="touchendEvent"
       @touchcancel="touchcancelEvent"
  >
    <slot></slot>
  </div>
</template>

<script>

export default {
  name: 'Bili_CoverButton',
  data() {
    return {};
  },
  props: {
    "animation": {
      type: String,
      default: ''
    }
  },
  watch: {
    animation(value) {
      // 修复默认v-show为false，然后再设置为true，cover-view展示错误。
      // if (getComputedStyle(this.$el).display !== 'none') {
      //   this.changeAttr('animation', value);
      // }
    }
  },
  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,
            }
          })
        }
      });
    }
  }
};
</script>

<style>
.bl___cover-button {
  font-size: 18px;
  padding-left: 14px;
  padding-right: 14px;
  text-align: center;
  background-color: #f8f8f8;
  line-height: 2.55555556;
  border-radius: 5px;
  border-style: solid;
  border-width: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: auto;
  overflow: hidden;
}
</style>

