<template>
  <div>
    <svg-icon :icon-class="isFullscreen?'exit-fullscreen':'fullscreen'" @click="click"  />
  </div>
</template>

<script>
import screenfull from 'screenfull'

export default {
  name: 'Screenfull',
  data() {
    return {
      isFullscreen: false,
      marginLeft:'54px'
    }
  },
  mounted() {
    this.init()
  },
  beforeDestroy() {
    this.destroy()
  },
  methods: {
    click() {
      if (!screenfull.isEnabled) {
        this.$message({ message: '你的浏览器不支持全屏', type: 'warning' })
        return false
      }
      screenfull.toggle()
    },
    change() {
      this.isFullscreen = screenfull.isFullscreen
      this.fullScreen()
    },
    init() {
      if (screenfull.isEnabled) {
        screenfull.on('change', this.change)
      }
    },
    destroy() {
      if (screenfull.isEnabled) {
        screenfull.off('change', this.change)
      }
    },
    fullScreen(){
      if (this.isFullscreen) {
        document.getElementsByClassName("sidebar-container")[0].style.display = 'none';
        document.getElementsByClassName("navbar")[0].style.display='none';
        document.getElementById("tags-view-container").style.display='none';
        document.getElementsByClassName("app-main")[0].
        setAttribute("style","min-height:calc(100vh - 2px)");
        this.marginLeft = document.getElementsByClassName("main-container")[0].style.marginLeft;
        console.log(this.marginLeft)
        document.getElementsByClassName("main-container")[0].
        setAttribute("style","margin-left:2px");
        //this.isFullscreen = true;
      } else {
        document.getElementsByClassName("sidebar-container")[0].style.display = '';
        document.getElementsByClassName("navbar")[0].style.display='';
        document.getElementById("tags-view-container").style.display='';
        document.getElementsByClassName("app-main")[0].
        setAttribute("style","min-height:calc(100vh - 84px)");
        document.getElementsByClassName("main-container")[0].
        setAttribute("style",this.marginLeft );
        // document.getElementsByClassName("app-main")[0].style.min-height =calc(100vh - 84px);
        //this.isFullscreen = false;

      }

    },
  }
}
</script>

<style scoped>
.screenfull-svg {
  display: inline-block;
  cursor: pointer;
  fill: #5a5e66;;
  width: 20px;
  height: 20px;
  vertical-align: 10px;
}
</style>
