<template>
  <div>
    <el-container>
      <el-aside :width="siderConfig.width">
        <div :style="siderStyle">
          <el-header>header</el-header>
          <Menu :config="menuConfig" />
        </div>
      </el-aside>
      <el-container>
        <div class="layout-header-wrapper">
          <el-header><Header :breadList="breadList" /></el-header>
        </div>
        <el-main>
          <PageHeader />
          <div class="container-wrapper">
            <transition name="squish">
              <router-view></router-view>
            </transition>
          </div>
        </el-main>
        <el-footer><Footer /></el-footer>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { breads } from '@/router/routes'
import { useModel } from '@/store'
import Header from './components/Header.vue'
import Footer from './components/Footer.vue'
import Menu from './components/Menu/index.vue'
import PageHeader from './components/PageHeader.vue'

export default {
  components: {
    Header,
    Footer,
    Menu,
    PageHeader,
  },
  
  setup(props) {

    // 配置相关
    const { config } = useModel('system')
    const menuConfig = computed(() => config.menu)
    const siderConfig = computed(() => config.sider)
    const siderStyle = computed(() => {
      return {
        minHeight: '100vh',
        backgroundColor: config.menu.backgroundColor
      }
    })

    // 路由相关
    const route = useRoute()
    const breadList = computed(() => {
      let arr
      for (let items of breads) {
        let found = false
        for (let it of items) {
          if (it.name === route.name) {
            found = true
            arr = items
            break
          }
        }

        if (found) {
          break
        }
      }

      return arr || []
    })

    return {
      siderConfig,
      siderStyle,
      menuConfig,
      breadList,
    }
  }
}
</script>

<style lang="less" scoped>
.el-menu {
  border-right: none !important;
}

.el-container {
  .el-main {
    padding: 0 !important;
    background-color: rgba(0, 0, 0, .04);
  }
}

.layout-header-wrapper {
  border-bottom: 1px solid rgba(0, 0, 0, .08);
}

.container-wrapper {
  // background-color: rgba(0, 0, 0, .02);
  margin: 1em;
  position: relative;
}

.squish {
  &-enter-active,&-leave-active {
    transition: transform 0.25s  ease-in, opacity 0.25s  ease-in;
  }

  &-enter-from, &-leave-to {
    transform: scale(0.95);
    opacity: 0;
  }
}
</style>
