<template>
    <view class="page-content">
        <mx-nav-bar :title="major.name||prevData.name"/>
        <mx-tabs-swiper v-if="major.code" :tabs="tabs" border>
            <template #base>
                <base-info :major="major"/>
            </template>
            <template #college>
                <open-college :major="major"/>
            </template>
        </mx-tabs-swiper>
        <uv-empty v-else text="暂无相关专业介绍" margin-top="100"/>
    </view>
</template>

<script setup>
import {ref, computed, onMounted} from 'vue';
import {useTransfer} from "@/hooks/useTransfer";
import {findTreeNode} from "@/utils/tree-helper";
import {useCacheStore} from "@/hooks/useCacheStore";
import {cacheActions} from "@/hooks/defineCacheActions";
import {useUserStore} from "@/hooks/useUserStore";
import BaseInfo from "@/pages/major-library/detail/components/base-info.vue";
import OpenCollege from "@/pages/major-library/detail/components/open-college.vue";

const {prevData} = useTransfer()
const {dispatchCache} = useCacheStore()
const {isCultural} = useUserStore()
const majorTree = ref([])
const major = computed(() => findTreeNode(majorTree.value, m => m.code == prevData.value.code) || {})

const tabs = ref([
    {name: '专业概况', template: 'base'},
    {name: isCultural.value ? '招生院校' : '开设院校', template: 'college'}
])

onMounted(async () => {
    majorTree.value = await dispatchCache(cacheActions.getMajorTree)
})
</script>

<style lang="scss">

</style>
