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

<script>
import {naDataToObj} from '../util/logic';

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: {
    framechange(e) {
      naDataToObj(this.$el, e.data);
    },
    clickEvent(e) {
      this.$emit('click', {
        detail: e.data
      });
    },
    touchstartEvent(e) {
      this.$emit('touchstart', {
        detail: e.data
      });
    },
    touchmoveEvent(e) {
      this.$emit('touchmove', {
        detail: e.data
      });
    },
    touchendEvent(e) {
      this.$emit('touchend', {
        detail: e.data
      });
    },
    touchcancelEvent(e) {
      this.$emit('touchcancel', {
        detail: e.data
      });
    },
    changeAttr(key, value) {
      let _obj = {};
      _obj[key] = value;
      SmallApp.postMessage({
        "module": "dom", // cover-view 的所有通信固定使用 dom
        "method": "updateAttrs", // addElement...
        "args": {
          id: this.$el.getAttribute('nodeid'),
          attrs: _obj
        }
      });
    },
  }
};
</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: var(--width);
  height: var(--height);
  --width: 'auto';
  --height: 'auto';
  overflow: hidden;
}
</style>

