<template>
  <div @click="toggleFull">
    <svg-icon class-name="size-icon" icon-class="screenfull" />
  </div>
</template>

<script>
import screenfull from 'screenfull'
import { Message } from 'element-ui'

export default {
  name: 'Screenfull',
  data () {
    return {
      isFullscreen: false
    }
  },
  mounted () {
    this.init()
  },
  beforeDestroy () {
    this.destroy()
  },
  methods: {
    toggleFull () {
      if (!screenfull.isEnabled) {
        Message.warning('you browser can not work')
        return false
      }
      screenfull.toggle()
    },
    change () {
      this.isFullscreen = screenfull.isFullscreen
    },
    init () {
      if (screenfull.isEnabled) {
        screenfull.on('change', this.change)
      }
    },
    destroy () {
      if (screenfull.isEnabled) {
        screenfull.off('change', this.change)
      }
    }
  }
}
</script>
