/** * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai * Project: Hilmacorp.ai — Web Platform * File: components/CookieConsent.tsx * Description: Cookie consent banner — records the visitor's choice in a first-party cookie * and can be reopened at any time via the "hilmacorp:cookie-preferences" event */ "use client"; import { useEffect, useState } from "react"; import Link from "next/link"; export const COOKIE_CONSENT_NAME = "hilmacorp_cookie_consent"; export const COOKIE_PREFERENCES_EVENT = "hilmacorp:cookie-preferences"; interface CookieStrings { title: string; body: string; acceptAll: string; essentialOnly: string; privacyLink: string; note: string; } function readConsent(): string | null { const match = document.cookie.match( new RegExp(`(?:^|; )${COOKIE_CONSENT_NAME}=([^;]*)`) ); return match ? decodeURIComponent(match[1]) : null; } function writeConsent(value: "all" | "essential") { document.cookie = `${COOKIE_CONSENT_NAME}=${value};path=/;max-age=31536000;samesite=lax`; } export default function CookieConsent({ locale, strings, }: { locale: "fr" | "en"; strings: CookieStrings; }) { const [visible, setVisible] = useState(false); useEffect(() => { if (readConsent() === null) setVisible(true); const reopen = () => setVisible(true); window.addEventListener(COOKIE_PREFERENCES_EVENT, reopen); return () => window.removeEventListener(COOKIE_PREFERENCES_EVENT, reopen); }, []); if (!visible) return null; function choose(value: "all" | "essential") { writeConsent(value); setVisible(false); } return (

{strings.title}

{strings.body}

{strings.note}

{strings.privacyLink}
); }