<script setup>
import {ref} from 'vue'
import {useRoute} from 'vue-router'

const route = useRoute()

const isCollapse = ref(false)
const switchFold = () => {
  isCollapse.value = !isCollapse.value
}


</script>

<template>
  <el-container style="height: 100vh">
    <el-header style="display: flex; align-items: center;">
      <el-menu
        :ellipsis="false"
        mode="horizontal"
        router
        style="flex: 1;"
      >
        <!-- 左侧 -->
        <el-menu-item index="">
          <h1 style="margin: 0;">信息管理系统</h1>
        </el-menu-item>

        <!-- 右侧：margin-left: auto 把它推到底部 -->
        <el-menu-item index="/login" style="margin-left: auto">
          <el-icon><SwitchButton/></el-icon>
          <template #title>LogOut</template>
        </el-menu-item>
      </el-menu>
    </el-header>

    <el-container>
      <el-aside style="display: flex; flex-direction: column" width="200px">
        <el-menu
          :collapse="isCollapse"
          :default-active="route.path"
          router
          style="flex: 1; display: flex; flex-direction: column"
        >
          <!-- <el-sub-menu index="1">
            <template #title>
              <el-icon><IconMenu/></el-icon>
              <span>一号栏</span>
            </template>
          </el-sub-menu> -->

           <el-menu-item index="/panel/home">
              <el-icon><House /></el-icon>
              <template #title>首页</template>
            </el-menu-item>

          <el-menu-item index="/panel/page1">
              <el-icon><Avatar /></el-icon>
              <template #title>客户管理</template>
            </el-menu-item>

          <el-menu-item index="/panel/page2">
            <el-icon><Document /></el-icon>
            <template #title>合同管理</template>
          </el-menu-item>
          <el-menu-item index="/panel/page3">
            <el-icon><Service /></el-icon>
            <template #title>售后管理</template>
          </el-menu-item>
          <el-menu-item index="/panel/page3">
            <el-icon><IceTea /></el-icon>
            <template #title>产品管理</template>
          </el-menu-item>
          <el-menu-item index="/panel/page3">
            <el-icon><User /></el-icon>
            <template #title>员工管理</template>
          </el-menu-item>

          <!-- ⭐ 关键：margin-top: auto 把它推到最底部 -->
          <el-menu-item style="margin-top: auto" @click="switchFold">
            <el-icon :class="{'rotate-180-animation':!isCollapse,'rotate-180-animation-reverse':isCollapse}" ><ArrowLeft /></el-icon>
            <template #title>收缩</template>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <el-main>
        <!-- ⭐ 这个 router-view 渲染嵌套的子路由（page1/page2/page3） -->
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<style scoped>

.rotate-180-animation {
  /* 修改为你想要的动画：旋转180度，执行一次，持续0.5秒 */
  animation: rotate-180 0.3s ease-in-out;
  animation-fill-mode:forwards;
}

.rotate-180-animation-reverse {
  /* 修改为你想要的动画：旋转180度，执行一次，持续0.5秒 */
  animation: rotate-180-reverse 0.3s ease-in-out;
  animation-fill-mode:forwards;
}

@keyframes rotate-180 {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(180deg);
  }
}

@keyframes rotate-180-reverse {
  from {
    transform: rotate(180deg);
  }
  to {
    transform: rotate(0deg);
  }
}


</style>

