import { describe, expect, it } from 'vitest'
import {
  appPrivacyHref,
  appTermsHref,
  footerPageHref,
  footerPageSlugs,
  getFooterPageContent,
  isFooterPageSlug,
} from './footerContent'
import type { CarplaceLanguage } from './i18n'

const languages: CarplaceLanguage[] = ['en', 'fr', 'ar']

describe('carplace footer content registry', () => {
  it('keeps every declared slug routable and recognizable', () => {
    expect(footerPageSlugs.length).toBeGreaterThan(5)

    for (const slug of footerPageSlugs) {
      expect(isFooterPageSlug(slug)).toBe(true)
      expect(footerPageHref[slug]).toBe(`/carplace/footer/${slug}`)
    }

    expect(isFooterPageSlug('privacy')).toBe(false)
    expect(isFooterPageSlug('../admin')).toBe(false)
  })

  it('provides localized title and paragraph content for every footer page', () => {
    for (const language of languages) {
      for (const slug of footerPageSlugs) {
        const content = getFooterPageContent(language, slug)

        expect(content.title.trim()).not.toBe('')
        expect(content.paragraphs.length).toBeGreaterThan(0)
        expect(content.paragraphs.every((paragraph) => paragraph.trim().length > 0)).toBe(true)

        for (const section of content.sections ?? []) {
          expect(section.heading.trim()).not.toBe('')
          expect(section.paragraphs.length).toBeGreaterThan(0)
        }
      }
    }
  })

  it('keeps website privacy and application privacy links separate by locale', () => {
    expect(footerPageHref['privacy-policy']).toBe('/carplace/footer/privacy-policy')
    expect(appPrivacyHref).toEqual({
      en: '/carplace/app-privacy-en',
      fr: '/carplace/app-privacy-fr',
      ar: '/carplace/app-privacy-ar',
    })
    expect(appTermsHref).toEqual({
      en: '/carplace/app-tc-en',
      fr: '/carplace/app-tc-fr',
      ar: '/carplace/app-tc-ar',
    })
  })

  it('exposes footer policy copy that points users to the locale-matched app policy pages', () => {
    expect(getFooterPageContent('en', 'privacy-policy').paragraphs[0]).toContain('app-privacy-en')
    expect(getFooterPageContent('fr', 'privacy-policy').paragraphs[0]).toContain('app-privacy-fr')
    expect(getFooterPageContent('ar', 'privacy-policy').paragraphs[0]).toContain('app-privacy-ar')

    expect(getFooterPageContent('en', 'general-conditions').paragraphs[0]).toContain('app-tc-en')
    expect(getFooterPageContent('fr', 'general-conditions').paragraphs[0]).toContain('app-tc-fr')
    expect(getFooterPageContent('ar', 'general-conditions').paragraphs[0]).toContain('app-tc-ar')
  })
})
