<script setup lang="ts">
    import dayjs from 'dayjs'
    import { checkUpgrade, closeSplashscreenAndChechUpgrade } from '@/utils/upgrade'
    import { useRuntime } from '@/hooks/app/useRuntime'
    import { useConcealedExit } from '@/hooks/app/useConcealedExit'
    import * as Pages from '@/utils/pages'
    import * as Notice from '@/pages/common/notice'

    const { exit } = useConcealedExit()
    const { app } = useRuntime()
    const version = computed(() => app.value.version)
    const year = ref(dayjs().year())
    const title = ref('Hello World')

    onLoad(() => {
        // 关闭启动页并检查更新
        closeSplashscreenAndChechUpgrade()
    })

    onShow(() => {
        // 检查是否有全局通知
        Notice.inspect({
            tenantId: 'YR',
        })
    })

    function surprise() {
        // #ifdef APP-PLUS
        const orientation = plus.navigator.getOrientation()
        if (orientation === 0) {
            plus.screen.lockOrientation('landscape-primary')
        } else if (orientation === 90) {
            plus.screen.lockOrientation('portrait-primary')
        }
        Message.toast('🥳 surprise~')
        // #endif

        // #ifndef APP-PLUS
        Message.toast(`在手机上运行点击有惊喜~ ╰(*°▽°*)╯`)
        // #endif
    }
</script>

<template>
    <view class="content flex-center flex-col">
        <fui-avatar
            src="/static/logo.png"
            radius="14"
            size="large"
            background="transparent"
            class="!mb-3"
            @click="surprise"
        />
        <view class="flex-center flex-col mb-3">
            <text class="title">{{ title }}</text>
            <text class="title">{{ $t('app.hello') }}</text>
            <Icon icon="emojione-grinning-face" size="48" class="mt-3" />

            <fui-divider />

            <fui-button type="link" size="large" @click="Pages.to('/pages/example/index')">
                <Icon icon="material-symbols-arrow-right-alt" size="48" color="gray" class="mr-1" />
                <text class="color-gray">Examples</text>
            </fui-button>
        </view>
        <fui-footer isFixed>
            <template #text>
                <view v-if="version" @tap="checkUpgrade(true)">V{{ version }}</view>
                <view class="mt-1">壹润科技 版权所有</view>
                <view class="mt-1" @tap="exit">Copyright © 2021-{{ year }} YiRing. All Ringhts Reserved</view>
            </template>
        </fui-footer>
    </view>
</template>

<style lang="less" scoped>
    .content {
        height: calc(100vh - 100rpx);
    }

    .title {
        display: flex;
        justify-content: center;
        font-size: 36rpx;
        color: #8f8f94;
    }
</style>
