<template>
  <div class="safety-platform-container">
    <header class="safety-platform-container__header">
      <BreadcrumbBack />
      <span class="breadcrumb-title">{{ headerTitle }}</span>
    </header>
    <component :is="dynamicComponent" :id="id" ref="dynamicComponentRef" @record-submitted="handleRecordSubmitted" />
  </div>
</template>

<script setup lang="ts">
  import { ref, computed, defineAsyncComponent } from 'vue';
  import { useRoute } from 'vue-router';

  const route = useRoute();
  const operate = route.query.operate;
  const id = Number(route.query.id);
  const headerTitle = computed(() => {
    switch (operate) {
      case 'act-create':
        return `创建违规行为记录`;
      case 'act-edit':
        return `编辑违规行为记录`;
      default:
        return '未知操作';
    }
  });

  const dynamicComponent = computed(() => {
    switch (operate) {
      case 'act-create':
        return defineAsyncComponent(() => import('./components/ActCreate.vue'));
      case 'act-edit':
        return defineAsyncComponent(() => import('./components/ActEdit.vue'));
      default:
        return '';
    }
  });

  const dynamicComponentRef = ref();

  function handleRecordSubmitted() {}
</script>

<style scoped lang="scss">
  @use '@/styles/page-details-layout.scss' as *;
  @use '@/styles/page-main-layout.scss' as *;

  .safety-platform-container__header {
    flex-direction: row !important;
    justify-content: flex-start !important;
    gap: 8px !important;
  }
</style>
