<template>
  <section class="stage-wrapper">
    <div class="header">
      <div class="topper">
        <span class="base">
          <el-icon>
            <WarningFilled />
          </el-icon>{{ tabTitle }}</span>
      </div>
      <div class="bottom">
        <el-tabs v-model="activeTab" type="card" @tab-click="onTabClick">
          <el-tab-pane :label="item.label" :name="item.index" 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>
    <div class="content">
      <component :is="currentCom" :title="tabTitle" :isOpen="isOpen" />
    </div>
  </section>
</template>

<script setup>
import { onMounted, ref, reactive, onUnmounted, computed, defineAsyncComponent, markRaw, provide } from "vue";
const tabs = [
  {
    label: "隐患排查治理",
    ywId: "41",
    index: '0'
  },

];
const activeTab = ref("0");
const isOpen = ref(false);
const currentCom = ref(null);
const tabTitle = computed(() => {
  return tabs.find(v => v.index == activeTab.value).label
})
const tabValue = computed(() => {
  return tabs.find(v => v.index == activeTab.value).ywId
})
provide('ywId', tabValue)
const onToggle = () => {
  isOpen.value = !isOpen.value;
};
const onTabClick = (tab) => {
  isOpen.value = true;
  currentCom.value = markRaw(defineAsyncComponent(() => import(`./tabs/Tab${tab.index}.vue`)));
};

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

<style lang="scss" scoped>
.stage-wrapper .header .topper {
  display: flex;
  align-items: center;

  >span {
    display: flex;
    align-items: center;
  }

  .base .el-icon {
    margin-right: 4px;
  }
}

.stage-wrapper .tip .el-icon {
  margin-top: 0;
}

.stage-wrapper .content {
  height: 100%;
  display: flex;
  flex-direction: column;

  .box {
    padding-top: 2px;
  }
}

.stage-wrapper .header .bottom .toggle .el-icon {
  margin-top: 0;
}

.stage-wrapper .header .bottom {
  display: flex;
  justify-content: space-between;
  padding-right: 10px;

  .toggle {
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;

    .el-icon {
      transform: rotate(90deg);
      transition: all 0.25s ease;
    }

    &.active {
      .el-icon {
        transform: rotate(-90deg);
      }
    }
  }
}
</style>
