import { computed } from 'vue'
import { buildPublicLocaleSwitchContext, useRegisterPublicLocaleSwitchContext } from '~/composables/usePublicLocaleSwitchContext'
import { useResolvedPage } from '~/content/pages'

export function buildNotFoundPageSeo(page) {
  const seo = page?.seo || {}
  const title = seo.title || page?.title || 'Page Not Found'
  const description = seo.description || page?.excerpt || ''

  return {
    title,
    description,
    ogTitle: title,
    ogDescription: description,
    ogImage: '',
    robots: 'noindex,nofollow',
    canonical: null,
    hreflang: [],
    xDefault: null,
  }
}

export function useNotFoundContent(options = {}) {
  const notFoundPage = useResolvedPage('/404')
  const shouldRegisterLocaleSwitchContext = options.registerLocaleSwitchContext !== false

  const localeSwitchContext = computed(() => buildPublicLocaleSwitchContext(notFoundPage.value, {
    kind: 'list',
  }))

  if (shouldRegisterLocaleSwitchContext) {
    useRegisterPublicLocaleSwitchContext(localeSwitchContext)
  }

  const notFoundUi = computed(() => notFoundPage.value?.structuredContent?.ui || {})

  return {
    notFoundPage,
    notFoundUi,
  }
}
