import { useState, useEffect } from "react"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Switch } from "@/components/ui/switch"; import { Label } from "@/components/ui/label"; import { Cookie, X, Settings, Shield } from "lucide-react"; import { Link } from "react-router-dom"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; interface CookiePreferences { necessary: boolean; analytics: boolean; marketing: boolean; } const COOKIE_CONSENT_KEY = "cookie-consent"; const COOKIE_PREFERENCES_KEY = "cookie-preferences"; const CookieConsent = () => { const [showBanner, setShowBanner] = useState(false); const [showSettings, setShowSettings] = useState(false); const [preferences, setPreferences] = useState({ necessary: true, // Always required analytics: false, marketing: false, }); useEffect(() => { const consent = localStorage.getItem(COOKIE_CONSENT_KEY); if (!consent) { // Small delay to avoid flash on page load const timer = setTimeout(() => setShowBanner(true), 1000); return () => clearTimeout(timer); } else { const savedPreferences = localStorage.getItem(COOKIE_PREFERENCES_KEY); if (savedPreferences) { setPreferences(JSON.parse(savedPreferences)); } } }, []); const handleAcceptAll = () => { const allAccepted: CookiePreferences = { necessary: true, analytics: true, marketing: true, }; saveConsent(allAccepted); }; const handleRejectAll = () => { const onlyNecessary: CookiePreferences = { necessary: true, analytics: false, marketing: false, }; saveConsent(onlyNecessary); }; const handleSavePreferences = () => { saveConsent(preferences); setShowSettings(false); }; const saveConsent = (prefs: CookiePreferences) => { localStorage.setItem(COOKIE_CONSENT_KEY, "true"); localStorage.setItem(COOKIE_PREFERENCES_KEY, JSON.stringify(prefs)); setPreferences(prefs); setShowBanner(false); // Dispatch custom event for analytics scripts to listen to window.dispatchEvent( new CustomEvent("cookie-consent-updated", { detail: prefs }) ); }; if (!showBanner) return null; return ( <> {/* Cookie Banner */}

We value your privacy

We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies.{" "} Read our Privacy Policy

{/* Cookie Settings Dialog */} Cookie Preferences Manage your cookie preferences. You can enable or disable different types of cookies below.
{/* Necessary Cookies */}

Essential for the website to function properly. Cannot be disabled.

{/* Analytics Cookies */}

Help us understand how visitors interact with our website to improve user experience.

setPreferences((prev) => ({ ...prev, analytics: checked })) } />
{/* Marketing Cookies */}

Used to track visitors across websites to display relevant advertisements.

setPreferences((prev) => ({ ...prev, marketing: checked })) } />
); }; export default CookieConsent;