<template>
  <div :class="classObj" class="jd-wrapper">
    <div v-if="device==='mobile'&&sidebar.opened" class="drawer-bg" @click="handleClickOutside" />
    <jd-sidebar />
    <div :class="{hasTagsView:needTagsView}" class="jd-container">
      <div :class="{'fixed-header':fixedHeader}" />
      <jd-navbar />
      <app-main class="app-main" />
    </div>
  </div>
</template>

<script>
import { AppMain } from './components'
import ResizeMixin from './mixin/ResizeHandler'
import { mapState } from 'vuex'
import JdSidebar from './components/JdSidebar'
import JdNavbar from './components/JdNavbar'

export default {
  name: 'Jdlayout',
  components: {
    AppMain,
    JdSidebar,
    JdNavbar
  },
  mixins: [ResizeMixin],
  computed: {
    ...mapState({
      sidebar: state => state.app.sidebar,
      device: state => state.app.device,
      showSettings: state => state.settings.showSettings,
      needTagsView: state => state.settings.tagsView,
      fixedHeader: state => state.settings.fixedHeader
    }),
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened,
        withoutAnimation: this.sidebar.withoutAnimation,
        mobile: this.device === 'mobile'
      }
    }
  },
  methods: {
    handleClickOutside() {
      this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
    }
  }
}
</script>

<style lang="scss" scoped>
  @import "~@/styles/mixin.scss";
  @import "~@/styles/variables.scss";

  .jd-wrapper{
    width: 1360px;
    margin: 0 auto;
  }
  .jd-container{
    margin-left: 240px;
    position: relative;
    min-height: 100%;
  }
  .app-main{
    margin-top: 24px;
  }
</style>
