'use client' import { useState, useEffect, useCallback } from 'react' /** * CookieBannerOverlay — Live cookie consent banner for the Compliance SDK. * * - Opens automatically on first visit (localStorage check) * - Can be reopened via FAB button (right-[10rem]) * - Records consent choice to localStorage * - Fires custom event 'sdkCookieConsentUpdated' for other components */ const STORAGE_KEY = 'bp-sdk-cookie-consent' interface ConsentState { necessary: boolean statistics: boolean marketing: boolean functional: boolean timestamp: string } function getStoredConsent(): ConsentState | null { if (typeof window === 'undefined') return null try { const raw = localStorage.getItem(STORAGE_KEY) if (!raw) return null return JSON.parse(raw) } catch { return null } } export function CookieBannerOverlay() { const [isOpen, setIsOpen] = useState(false) const [showSettings, setShowSettings] = useState(false) const [consent, setConsent] = useState({ necessary: true, statistics: false, marketing: false, functional: false, timestamp: '', }) // Check on mount if consent was already given useEffect(() => { const stored = getStoredConsent() if (!stored) { // First visit — show banner setIsOpen(true) } else { setConsent(stored) } }, []) // Listen for reopen event from FAB button useEffect(() => { const handler = () => { setIsOpen(true) setShowSettings(true) } window.addEventListener('openCookieBanner', handler) return () => window.removeEventListener('openCookieBanner', handler) }, []) const saveConsent = useCallback((state: ConsentState) => { const withTimestamp = { ...state, timestamp: new Date().toISOString() } localStorage.setItem(STORAGE_KEY, JSON.stringify(withTimestamp)) setConsent(withTimestamp) setIsOpen(false) setShowSettings(false) window.dispatchEvent(new CustomEvent('sdkCookieConsentUpdated', { detail: withTimestamp })) }, []) const handleAcceptAll = () => { saveConsent({ necessary: true, statistics: true, marketing: true, functional: true, timestamp: '' }) } const handleRejectAll = () => { saveConsent({ necessary: true, statistics: false, marketing: false, functional: false, timestamp: '' }) } const handleSaveSettings = () => { saveConsent(consent) } if (!isOpen) return null return ( <> {/* Overlay */}
{/* Don't close on overlay click — consent is required */}} /> {/* Banner */}
{/* Header */}

Cookie-Einstellungen

Wir verwenden Cookies und aehnliche Technologien, um Ihnen die bestmoegliche Erfahrung zu bieten. Sie koennen Ihre Praeferenzen jederzeit aendern.

{/* Category Settings (expandable) */} {showSettings && (
{/* Necessary — always on */} {}} /> setConsent(prev => ({ ...prev, statistics: v }))} /> setConsent(prev => ({ ...prev, marketing: v }))} /> setConsent(prev => ({ ...prev, functional: v }))} />
)} {/* Buttons */}
{!showSettings ? ( <> ) : ( <> )}
) } /** * FAB button to reopen the cookie banner settings. * Positioned next to ComplianceAdvisor and PipelineSidebar. */ export function CookieBannerFAB() { const [hasConsent, setHasConsent] = useState(false) useEffect(() => { setHasConsent(!!getStoredConsent()) const handler = () => setHasConsent(true) window.addEventListener('sdkCookieConsentUpdated', handler) return () => window.removeEventListener('sdkCookieConsentUpdated', handler) }, []) // Only show FAB after consent was given (banner is closed) if (!hasConsent) return null return ( ) } function CategoryToggle({ label, description, checked, disabled, onChange, }: { label: string description: string checked: boolean disabled?: boolean onChange: (v: boolean) => void }) { return (
{label}
{description}
) }