<template>
  <div :class="classObj" class="app-wrapper" :style="{'--current-color': theme}">
    <!-- 头部区域，独占一行 -->
    <div class="header-container">
      <navbar/> <!-- 导航栏组件 -->
    </div>
    
    <!-- 主内容区域 -->
    <div class="main-container">
      <!-- 侧边栏，仅在侧边栏未隐藏时显示 -->
      <sidebar v-if="!sidebar.hide" class="sidebar-container"/>
      
      <!-- 右侧内容区域 -->
      <div :class="{'content-container': true, 'sidebarHide': sidebar.hide}">
        <tags-view v-if="needTagsView"/> <!-- 标签视图组件，仅在 needTagsView 为真时显示 -->
        <app-main/> <!-- 主要内容区域 -->
      </div>
    </div>

    <!-- 右侧面板，包含设置面板 -->
    <right-panel>
      <settings/> <!-- 设置面板组件 -->
    </right-panel>
  </div>
</template>

<script>
import RightPanel from '@/components/RightPanel'
import { AppMain, Navbar, Settings, Sidebar, TagsView } from './components'
import ResizeMixin from './mixin/ResizeHandler'
import { mapState } from 'vuex'
import variables from '@/assets/styles/variables.scss'

export default {
  name: 'Layout',
  components: {
    AppMain,
    Navbar,
    RightPanel,
    Settings,
    Sidebar,
    TagsView
  },
  mixins: [ResizeMixin],
  computed: {
    ...mapState({
      theme: state => state.settings.theme,
      sideTheme: state => state.settings.sideTheme,
      sidebar: state => state.app.sidebar,
      needTagsView: state => state.settings.tagsView,
      fixedHeader: state => state.settings.fixedHeader
    }),
    classObj() {
      return {
        hideSidebar: !this.sidebar.opened,
        openSidebar: this.sidebar.opened,
        withoutAnimation: this.sidebar.withoutAnimation
      }
    },
    variables() {
      return variables;
    }
  },
  methods: {
    handleClickOutside() {
      this.$store.dispatch('app/closeSideBar', { withoutAnimation: false })
    }
  }
}
</script>

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

  .app-wrapper {
    @include clearfix;
    position: relative;
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    background-image: url("../../src/assets/images/bg@2x.png");
    background-size: 100% 100%;
  }

  .header-container {
    width: 100%;
    height: $base-header-height; 
    background-color: #fff; 
    box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
    z-index: 1000; 
  }

  .main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    background-color: #fff;
  }

  .sidebar-container {
    width: $base-sidebar-width; 
    height: 100%;
    transition: width 0.28s;
    margin-top: 60px;
    background-color: #f0f2f5;
  }

  .content-container {
    flex: 1;
    height: 100%;
    overflow: auto;
    padding: 16px; 
    background-color: #f0f2f5; 
    transition: margin-left 0.28s;

    &.sidebarHide {
      margin-left: 0;
    }
  }
</style>