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

export function buildRentalInfoPageSeo(page, origin = '') {
  return buildResolvedPageSeo(page, origin, {
    ogImage: page?.heroImage || page?.featuredImage || '',
  })
}

export function useRentalInfoContent() {
  const rentalInfoPage = useResolvedPage('rental-info')
  const localeSwitchContext = computed(() => buildPublicLocaleSwitchContext(rentalInfoPage.value, { kind: 'list' }))

  useRegisterPublicLocaleSwitchContext(localeSwitchContext)
  const structuredContent = computed(() => rentalInfoPage.value?.structuredContent || {})
  const ui = computed(() => structuredContent.value.ui || {})

  const rentalInfoHero = computed(() => ({
    title: rentalInfoPage.value?.title || '',
    subtitle: rentalInfoPage.value?.subtitle || '',
    description: rentalInfoPage.value?.excerpt || '',
  }))

  const rentalInfoSections = computed(() => sortByOrder(structuredContent.value.sections || []))

  const rentalInfoNotice = computed(() => ({
    title: ui.value.noticeTitle || '',
    description: structuredContent.value.notice || '',
  }))

  return {
    rentalInfoPage,
    rentalInfoHero,
    rentalInfoSections,
    rentalInfoNotice,
  }
}
