<template>
  <section class="stage-wrapper">
    <div class="header">
      <div class="topper">
        <span class="base">
          <el-icon>
            <WarningFilled />
          </el-icon>
          {{ title }}
        </span>
      </div>
      <div class="bottom">
        <el-tabs v-model="activeTab" type="card" @tab-click="onTabClick">
          <el-tab-pane :label="item.label" :name="item.value" v-for="(item, i) in tabs" :key="i" />
        </el-tabs>
        <!-- <div class="toggle" :class="{ active: !isOpen }" @click="onToggle">
          <span>{{ isOpen ? "收起" : "展开" }}</span>
          <el-icon>
            <DArrowLeft />
          </el-icon>
        </div> -->
      </div>
    </div>
    <component :is="currentCom" :isOpen="isOpen" :id="activeTab" :title="title" />
  </section>
</template>

<script setup>
import { onMounted, ref, reactive, defineAsyncComponent, markRaw } from "vue";
import { useRouter, useRoute } from "vue-router";
const route = useRoute();
const router = useRouter();
const currentCom = ref(null);
const tabs = [
  {
    label: "重点人员安全培训（管理层）",
    value: '13',//13管理层 14员工曾
    index: '0'
  },
  {
    label: "重点人员安全培训（员工层）",
    value: '14',//13管理层 14员工
    index: '1'
  },
  {
    label: "持证人员台账",
    value: '15',
    index: '2'
  },
];
const activeTab = ref(route.query.tab ? route.query.tab : "13");
const isOpen = ref(false);
const title = ref(tabs.find((item) => item.value === activeTab.value).label);
const indexs = ref(tabs.find((item) => item.value === activeTab.value).index);

const onTabClick = (tab) => {
  router.push({
    query: {
      tab: tab.props.name
    }
  });
  isOpen.value = false;
  currentCom.value = markRaw(defineAsyncComponent(() => import(`./tabs/tab${tab.index}.vue`)));
  title.value = tabs.find((item) => item.value === tab.props.name).label;
};
const onToggle = () => {
  isOpen.value = !isOpen.value;
};
onMounted(() => {
  currentCom.value = markRaw(defineAsyncComponent(() => import(`./tabs/tab${indexs.value}.vue`)));
});
</script>

<style lang="scss" scoped></style>
