<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" v-if="!['2', '3', '4'].includes(activeTab)">
          <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: "1"
  },
  {
    label: "年度计划数据",
    value: "2"
  },
  {
    label: "年度总结数据",
    value: "3"
  },
  {
    label: "安委会会议数据",
    value: "4"
  },
  {
    label: "安全投入数据",
    value: "5"
  },
  {
    label: "卷烟物流配送中心信息数据",
    value: "7"
  },
  // {
  //   label: "复烤厂信息数据",
  //   value: "8"
  // },
  {
    label: "烟叶收购站（点）信息数据",
    value: "10"
  }
];
const activeTab = ref(route.query.tab ? route.query.tab : "1");
const isOpen = ref(false);
const title = ref(tabs.find((item) => item.value === activeTab.value).label);

const onToggle = () => {
  isOpen.value = !isOpen.value;
};
const onTabClick = (tab) => {
  router.push({
    query: {
      tab: tab.props.name
    }
  });

  isOpen.value = false;
  currentCom.value = markRaw(defineAsyncComponent(() => import(`./tabs/tab${tab.props.name}.vue`)));
  title.value = tabs.find((item) => item.value === tab.props.name).label;
};

onMounted(() => {
  currentCom.value = markRaw(defineAsyncComponent(() => import(`./tabs/tab${activeTab.value}.vue`)));
});
</script>

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