<script setup lang="ts">
import { buildAgentVipApplyH5Url } from '@/composables/useAgentVipH5'
import { ensureCurrentPageAccess } from '@/composables/useNavigationAuthGuard'

definePage({ layout: false, auth: true })

const src = ref('')

onLoad((query) => {
  const params: Record<string, string> = {}
  const type = query?.type
  if (type) {
    const normalized = String(type).toLowerCase()
    if (normalized === 'vip' || normalized === 'svip')
      params.type = normalized
  }
  src.value = buildAgentVipApplyH5Url(params)
  if (!src.value)
    uni.showToast({ title: '未配置 H5 站点地址', icon: 'none' })
})

onShow(() => {
  ensureCurrentPageAccess('redirect')
})
</script>

<template>
  <web-view v-if="src" :src="src" />
  <view v-else class="flex min-h-screen items-center justify-center bg-gray-50 px-6 text-center text-sm text-gray-500">
    无法打开会员升级页面，请检查 VITE_SITE_ORIGIN 配置
  </view>
</template>
