<template>
  <div
    class="weui_dialog_alert"
    @touchmove="onTouchmove"
  >
    <div
      v-show="show"
      class="weui_mask"
      :transition="maskTransition"
      @click="onHide"
    />
    <div
      v-show="show"
      class="weui_dialog"
      :transition="dialogTransition"
    >
      <slot />
    </div>
  </div>
</template>

<script>
export default {
  props: {
    value: {
      type: Boolean,
      default: false
    },
    maskTransition: {
      type: String,
      default: 'vux-fade'
    },
    dialogTransition: {
      type: String,
      default: 'vux-dialog'
    },
    hideOnBlur: Boolean,
    scroll: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      show: false
    }
  },
  watch: {
    show (val) {
      this.$emit(val ? 'on-show' : 'on-hide')
      this.$emit('input', val)
    },
    value (val) {
      this.show = val
    }
  },
  methods: {
    onHide () {
      this.show = false
      this.$emit('on-hide')
    },
    onTouchmove(event) {
      !this.scroll && event.preventDefault()
    }
  }
}
</script>
