<script lang="ts">
	import { getBundle, alternatePath, type Locale } from '$lib/i18n';

	interface Props {
		/** Titre de page (sans le nom du site). Absent = home. */
		title?: string;
		description?: string;
		/** Chemin canonique courant, ex. `/dons/`. */
		path: string;
		locale: Locale;
	}

	let { title, description, path, locale }: Props = $props();

	const site = $derived(getBundle(locale).site);
	const altLocale: Locale = $derived(locale === 'fr' ? 'en' : 'fr');
	const altPath = $derived(alternatePath(path, altLocale));

	const fullTitle = $derived(title ? `${title} | ${site.name}` : `${site.name} | ${site.shortName}`);
	const ogTitle = $derived(title ?? `${site.name} - ${site.og_tagline}`);
	const desc = $derived(description ?? site.description);
	const canonical = $derived(`https://o-k-i.net${path}`);

	const orgJsonLd = $derived(
		JSON.stringify({
			'@context': 'https://schema.org',
			'@type': 'Organization',
			name: site.name,
			alternateName: site.shortName,
			url: 'https://o-k-i.net',
			logo: 'https://o-k-i.net/images/logo-512x512.png',
			description: site.description,
			address: {
				'@type': 'PostalAddress',
				streetAddress: '36 Rue Lethière',
				addressLocality: 'Basse-Terre',
				postalCode: '97100',
				addressCountry: 'GP'
			},
			contactPoint: {
				'@type': 'ContactPoint',
				email: 'kontak@o-k-i.net',
				contactType: 'customer service'
			},
			sameAs: [
				'https://niyaj.o-k-i.net/',
				'https://kute.o-k-i.net/',
				'https://labola.o-k-i.net/',
				'https://liberapay.com/OKI/donate'
			],
			foundingDate: '2024',
			nonprofitStatus: 'NonprofitANBI'
		})
	);

	const djangokamJsonLd = JSON.stringify({
		'@context': 'https://schema.org',
		'@type': 'MusicGroup',
		name: 'DJANGOKAM',
		genre: ['Reggae', 'Zouk', 'Konpa', 'K-pop'],
		url: 'https://djangokam.pawol.nu',
		sameAs: ['https://djangokam.pawol.nu'],
		member: {
			'@type': 'Organization',
			name: 'ORGANISATION KA INTERNATIONALE',
			url: 'https://o-k-i.net'
		}
	});

	// {@html} sur contenu first-party (JSON-LD généré au build, aucune donnée utilisateur).
	// `<\/script>` : échappement requis pour ne pas fermer le bloc <script> du composant.
	const orgJsonLdScript = $derived(`<script type="application/ld+json">${orgJsonLd}<\/script>`);
	const djangokamJsonLdScript = `<script type="application/ld+json">${djangokamJsonLd}<\/script>`;
</script>

<svelte:head>
	<title>{fullTitle}</title>
	<meta name="description" content={desc} />
	<meta name="keywords" content={site.keywords} />
	<meta name="author" content={site.name} />

	<link rel="canonical" href={canonical} />
	<link rel="alternate" hreflang={locale} href={canonical} />
	<link rel="alternate" hreflang={altLocale} href={`https://o-k-i.net${altPath}`} />
	<link rel="alternate" hreflang="x-default" href="https://o-k-i.net/" />

	<meta property="og:type" content="website" />
	<meta property="og:url" content={canonical} />
	<meta property="og:title" content={ogTitle} />
	<meta property="og:description" content={desc} />
	<meta property="og:image" content="https://o-k-i.net/images/logo-512x512.png" />
	<meta property="og:image:width" content="512" />
	<meta property="og:image:height" content="512" />
	<meta property="og:image:alt" content="Logo {site.name}" />
	<meta property="og:locale" content={site.og_locale} />
	<meta property="og:site_name" content={site.name} />

	<meta name="twitter:card" content="summary_large_image" />
	<meta name="twitter:url" content={canonical} />
	<meta name="twitter:title" content={ogTitle} />
	<meta name="twitter:description" content={desc} />
	<meta name="twitter:image" content="https://o-k-i.net/images/logo-512x512.png" />
	<meta name="twitter:image:alt" content="Logo {site.name}" />

	{@html orgJsonLdScript}
	{@html djangokamJsonLdScript}
</svelte:head>
