<script lang="ts" setup>
import { computed } from "vue"
import Header from "@/layout/components/Header/index.vue"
import { useAppStore } from "@/store/modules/app"
import { useSettingsStore } from "@/store/modules/settings"
import { AppMain, RightPanel, Settings, Sidebar } from "./components"
import useResize from "./hooks/useResize"

const appStore = useAppStore()
const settingsStore = useSettingsStore()

/** Layout 布局响应式 */
useResize()

const classObj = computed(() => {
  return {
    hideSidebar: !appStore.sidebar.opened,
    openSidebar: appStore.sidebar.opened,
    withoutAnimation: appStore.sidebar.withoutAnimation,
    showGreyMode: showGreyMode.value,
    showColorWeakness: showColorWeakness.value
  }
})

const showSettings = computed(() => settingsStore.showSettings)
const showGreyMode = computed(() => settingsStore.showGreyMode)
const showColorWeakness = computed(() => settingsStore.showColorWeakness)
</script>

<template>
  <div :class="classObj" class="app-wrapper">
    <Header />
    <Sidebar class="sidebar-container" />
    <div class="main-container">
      <AppMain />
      <RightPanel v-if="showSettings">
        <Settings />
      </RightPanel>
    </div>
  </div>
</template>

<style lang="scss" scoped>
@import "@/styles/mixins.scss";

.app-wrapper {
  position: relative;
  width: 100%;
  @include clearfix;
}

.showGreyMode {
  filter: grayscale(1);
}

.showColorWeakness {
  filter: invert(0.8);
}

.main-container {
  padding-top: var(--v3-global-header-height);
  min-height: 100%;
  transition: margin-left 0.28s;
  margin-left: var(--v3-sidebar-width);
  position: relative;
}

.sidebar-container {
  transition: width 0.28s;
  width: var(--v3-sidebar-width) !important;
  height: 100%;
  position: fixed;
  font-size: 0px;
  top: var(--v3-global-header-height);
  bottom: 0;
  left: 0;
  z-index: 1001;
}

// 顶部布局：侧边栏宽度固定，main-container 始终与之对齐（不随响应式折叠改变）

.withoutAnimation {
  .main-container,
  .sidebar-container {
    transition: none;
  }
}
</style>
