<template>
    <uv-cell-group :border="false">
        <uv-cell v-for="item in list" :key="item.id" cell-style="padding: 10px 0" @click="handlePreview(item)">
            <template #title>
                <view class="text-28 text-fore-title mb-20">{{ item.title }}</view>
            </template>
            <template #label>
                <view class="text-24 text-fore-light">{{ item.createTime }}</view>
            </template>
        </uv-cell>
    </uv-cell-group>
</template>

<script setup lang="ts">
import {UniversityBrochure, UniversityDetail} from "@/types/university";
import {UNIVERSITY_DETAIL} from "@/types/injectionSymbols";
import {useTransferPage} from "@/hooks/useTransferPage";
import {EnumBrochureType} from "@/common/enum";
import {routes} from "@/common/routes";

withDefaults(defineProps<{
    list: UniversityBrochure[]
}>(), {
    list: () => []
})

const detail = inject(UNIVERSITY_DETAIL, ref({} as UniversityDetail))
const baseInfo = computed(() => detail.value.baseInfo || {})
const {transferTo} = useTransferPage()

const handlePreview = function (brochure: UniversityBrochure) {
    if (brochure.url) {
        uni.openDocument({
            filePath: brochure.url,
            fail: result => {
                uni.setClipboardData({
                    data: brochure.url,
                    showToast: false,
                    success: () => {
                        uni.$ie.showModal({
                            title: '提示',
                            content: '已将文件地址复制到粘贴板',
                            showCancel: false
                        })
                    }
                })
            }
        })
    } else {
        brochure.logo = baseInfo.value.logo
        transferTo(routes.universityIntroduction, {bigData: brochure})
    }
}
</script>

<style scoped>

</style>