'use client' import React, { useState, useCallback } from 'react' import { useCompliance } from '../provider' import type { ConsentPurpose, CookieBannerPosition, CookieBannerTheme } from '@breakpilot/compliance-sdk-types' export interface ConsentBannerProps { position?: CookieBannerPosition theme?: CookieBannerTheme onConsentChange?: (consents: Record) => void privacyPolicyUrl?: string imprintUrl?: string className?: string style?: React.CSSProperties } export function ConsentBanner({ position = 'BOTTOM', theme = 'LIGHT', onConsentChange, privacyPolicyUrl = '/privacy', imprintUrl = '/imprint', className, style, }: ConsentBannerProps) { const { state, dispatch } = useCompliance() const [showSettings, setShowSettings] = useState(false) const [consents, setConsents] = useState>({ ESSENTIAL: true, FUNCTIONAL: false, ANALYTICS: false, MARKETING: false, PERSONALIZATION: false, THIRD_PARTY: false, }) const config = state.cookieBanner const handleAcceptAll = useCallback(() => { const allConsents: Record = { ESSENTIAL: true, FUNCTIONAL: true, ANALYTICS: true, MARKETING: true, PERSONALIZATION: true, THIRD_PARTY: true, } setConsents(allConsents) onConsentChange?.(allConsents) // Would save to backend here }, [onConsentChange]) const handleRejectAll = useCallback(() => { const minimalConsents: Record = { ESSENTIAL: true, FUNCTIONAL: false, ANALYTICS: false, MARKETING: false, PERSONALIZATION: false, THIRD_PARTY: false, } setConsents(minimalConsents) onConsentChange?.(minimalConsents) }, [onConsentChange]) const handleSaveSettings = useCallback(() => { onConsentChange?.(consents) setShowSettings(false) }, [consents, onConsentChange]) const handleConsentToggle = useCallback((purpose: ConsentPurpose) => { if (purpose === 'ESSENTIAL') return // Cannot disable essential setConsents(prev => ({ ...prev, [purpose]: !prev[purpose] })) }, []) const positionStyles: Record = { TOP: { top: 0, left: 0, right: 0 }, BOTTOM: { bottom: 0, left: 0, right: 0 }, CENTER: { top: '50%', left: '50%', transform: 'translate(-50%, -50%)' }, } const themeStyles: Record = { LIGHT: { backgroundColor: '#ffffff', color: '#1a1a1a' }, DARK: { backgroundColor: '#1a1a1a', color: '#ffffff' }, CUSTOM: config?.customColors ? { backgroundColor: config.customColors.background, color: config.customColors.text, } : {}, } const bannerStyle: React.CSSProperties = { position: 'fixed', zIndex: 9999, padding: '20px', boxShadow: '0 -2px 10px rgba(0, 0, 0, 0.1)', fontFamily: 'system-ui, -apple-system, sans-serif', ...positionStyles[position], ...themeStyles[theme], ...style, } const buttonBaseStyle: React.CSSProperties = { padding: '10px 20px', borderRadius: '4px', border: 'none', cursor: 'pointer', fontWeight: 500, marginRight: '10px', } const primaryButtonStyle: React.CSSProperties = { ...buttonBaseStyle, backgroundColor: theme === 'DARK' ? '#ffffff' : '#1a1a1a', color: theme === 'DARK' ? '#1a1a1a' : '#ffffff', } const secondaryButtonStyle: React.CSSProperties = { ...buttonBaseStyle, backgroundColor: 'transparent', border: `1px solid ${theme === 'DARK' ? '#ffffff' : '#1a1a1a'}`, color: theme === 'DARK' ? '#ffffff' : '#1a1a1a', } if (showSettings) { return (

{config?.texts?.settings || 'Cookie-Einstellungen'}

{Object.entries({ ESSENTIAL: { name: 'Notwendig', description: 'Erforderlich für die Grundfunktionen' }, FUNCTIONAL: { name: 'Funktional', description: 'Verbesserte Funktionen' }, ANALYTICS: { name: 'Analyse', description: 'Nutzungsstatistiken' }, MARKETING: { name: 'Marketing', description: 'Personalisierte Werbung' }, }).map(([key, { name, description }]) => (
{name}
{description}
))}
) } return (

{config?.texts?.title || 'Cookie-Einwilligung'}

{config?.texts?.description || 'Wir verwenden Cookies, um Ihre Erfahrung zu verbessern. Weitere Informationen finden Sie in unserer Datenschutzerklärung.'}

) }