<template>
	<view class="index-boot">
		<view class="index-boot__spinner" />
		<text class="index-boot__text">{{ bootText }}</text>
	</view>
</template>

<script>
import { getToken } from '@/utils/request.js'

/**
 * 主包入口：仅做启动跳转，首页 UI 在分包 packageA/home，避免主包超 2M。
 */
export default {
	data() {
		return {
			bootText: '加载中...'
		}
	},
	onLoad() {
		const token = getToken()
		const url = token ? '/packageA/home/index' : '/packageA/auth/login'
		this.bootText = token ? '正在进入首页...' : '正在前往登录...'
		uni.reLaunch({
			url,
			fail: (err) => {
				console.error('entry reLaunch fail', err)
				this.bootText = '打开失败，请删除小程序后重试'
				uni.showToast({ title: '页面打开失败', icon: 'none' })
			}
		})
	},
	onShareAppMessage() {
		return {
			title: '用工邀请',
			path: '/pages/worker/job-offer?scene=',
			imageUrl: '/static/images/job.jpg'
		}
	}
}
</script>

<style lang="scss" scoped>
.index-boot {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 24rpx;
	width: 100%;
	height: 100vh;
	background: $fe-surface;
	box-sizing: border-box;
}

.index-boot__spinner {
	width: 56rpx;
	height: 56rpx;
	border: 4rpx solid $fe-gray-200;
	border-top-color: $fe-primary;
	border-radius: 50%;
	animation: index-spin 0.8s linear infinite;
}

.index-boot__text {
	font-size: 28rpx;
	color: $fe-gray-500;
}

@keyframes index-spin {
	to {
		transform: rotate(360deg);
	}
}
</style>
