<template>
  <div class="safety-platform-container">
    <header class="safety-platform-container__header">
      <span class="breadcrumb-title">灾害损失上报</span>
      <el-tabs v-model="activeName">
        <el-tab-pane v-for="item in LOSS_REPORT_TABS" :key="item.value" :label="item.label" :name="item.value" />
      </el-tabs>
    </header>
    <main class="safety-platform-container__main">
      <component :is="dynamicComponent" />
    </main>
  </div>
</template>

<script setup lang="ts">
  import { computed, ref, defineAsyncComponent, onUnmounted } from 'vue';
  import { LOSS_REPORT_TABS } from './src/constant';

  const activeName = ref(sessionStorage.getItem('loss-report-active') || LOSS_REPORT_TABS[0].value);
  const dynamicComponent = computed(() => {
    switch (activeName.value) {
      case LOSS_REPORT_TABS[0].value:
        return defineAsyncComponent(() => import('./src/components/ReportTask.vue'));
      case LOSS_REPORT_TABS[1].value:
        return defineAsyncComponent(() => import('./src/components/LossRecord.vue'));
    }
  });
  onUnmounted(() => {
    sessionStorage.setItem('loss-report-active', activeName.value);
  });
</script>

<style scoped lang="scss">
  @use '@/styles/page-details-layout.scss' as *;
  .safety-platform-container__header {
    padding-bottom: 0 !important;
  }
  :deep(.el-tabs__header) {
    margin: 0;
  }
  :deep(.el-tabs__item) {
    font-size: 14px !important;
  }
</style>
