<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 Notice from '@/pages/common/notice'

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

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

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

    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
    }

    const animate = ref()
    function handUp() {
        if (animate.value) {
            return
        }

        Message.toast('👋🏻')
        animate.value = 'animate-swing'
        setTimeout(() => (animate.value = null), 1500)
    }
</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 />

            <uni-icons type="hand-up" size="30" :class="[animate]" @tap="handUp" />
        </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>
