<script setup>
import BookingPortalView from '~/components/track/BookingPortalView.vue'
import { buildTrackPageSeo, useTrackFlowContent } from '~/content/bookingFlow'
import { resolvePrivateFlowToken } from '~/utils/private-flow-route'
import { buildTrackRoute } from '~/utils/public-routes'
import { buildPublicSeoLinks } from '~/utils/public-seo'

definePageMeta({
  sitePageSurfaceClass: 'bg-[#FCF3EA]',
})

const route = useRoute()
const { locale } = usePublicLocale()
const queryToken = computed(() => String(route.query.token || '').trim())
const token = computed(() => resolvePrivateFlowToken(route, '/track', 'id'))

const { trackPage } = useTrackFlowContent(token)
const trackPageSeo = computed(() => buildTrackPageSeo(trackPage.value, {
  privateFlow: Boolean(token.value),
}))

useSeoMeta({
  title: () => trackPageSeo.value.title,
  description: () => trackPageSeo.value.description,
  ogTitle: () => trackPageSeo.value.ogTitle,
  ogDescription: () => trackPageSeo.value.ogDescription,
  robots: () => trackPageSeo.value.robots,
})

useHead(() => ({
  link: buildPublicSeoLinks(trackPageSeo.value),
}))

if (queryToken.value) {
  await navigateTo(buildTrackRoute(queryToken.value, {}, {
    locale: locale.value,
  }), { replace: true })
}
</script>

<template>
  <BookingPortalView :token="token" />
</template>
