interface SeoOptions {
  title: string
  description?: string
  image?: string
  url?: string
}

export const useSeo = () => {
  const config = useRuntimeConfig()
  const route = useRoute()
  const { locale } = useI18n()

  const setPageMeta = (options: SeoOptions) => {
    const siteUrl = config.public.siteUrl as string || 'https://skycel.fr'
    const fullUrl = options.url || `${siteUrl}${route.fullPath}`
    const imageUrl = options.image || `${siteUrl}/og-image.jpg`

    useHead({
      title: options.title,
    })

    useSeoMeta({
      title: options.title,
      description: options.description,
      ogTitle: options.title,
      ogDescription: options.description,
      ogImage: imageUrl,
      ogUrl: fullUrl,
      ogLocale: locale.value === 'fr' ? 'fr_FR' : 'en_US',
      twitterCard: 'summary_large_image',
      twitterTitle: options.title,
      twitterDescription: options.description,
      twitterImage: imageUrl,
    })
  }

  return { setPageMeta }
}
