import { useState, type CSSProperties } from "react" import { resolveGlobalColor } from "@/components/ui/global-color-picker" import { resolveGlobalTypography } from "@/components/ui/global-typography-picker" import type { AppearanceSettings, BehaviorSettings, ContentSettings, CookieCategory, } from "../types" type CookieConsentStyle = CSSProperties & Record<`--swift-commerce-cookie-consent-${string}`, string | number> interface CookieConsentPreviewProps { settings: AppearanceSettings behaviorSettings: BehaviorSettings contentSettings: ContentSettings categories: CookieCategory[] } const shieldIcon = ( ) export function CookieConsentPreview({ settings, behaviorSettings, contentSettings, categories, }: CookieConsentPreviewProps) { const [preferencesOpen, setPreferencesOpen] = useState(false) const isMagazine = settings.template === "magazine" const requiredCount = categories.filter((category) => category.required).length const optionalCount = Math.max(0, categories.length - requiredCount) const globalStyles = (window as any).swiftCommerceData?.globalStyles const hasGlobalColor = (id: string) => Boolean(globalStyles?.colors?.some((color: { id: string }) => color.id === id)) const hasGlobalTypography = (id: string) => Boolean(globalStyles?.typography?.some((typography: { id: string }) => typography.id === id)) const style: CookieConsentStyle = { "--swift-commerce-cookie-consent-overlay-color": settings.overlayColor || "#000000", "--swift-commerce-cookie-consent-overlay-opacity": settings.overlay ? (settings.overlayOpacity || 0) / 100 : 0, "--swift-commerce-cookie-consent-title-size": `${settings.titleFontSize || 16}px`, "--swift-commerce-cookie-consent-body-size": `${settings.bodyFontSize || 14}px`, "--swift-commerce-cookie-consent-font-weight": settings.fontWeight || "400", "--swift-commerce-cookie-consent-boxed-width": `${settings.boxedWidth || 80}%`, } if (settings.primaryColor || hasGlobalColor("primary")) { style["--swift-commerce-cookie-consent-primary"] = resolveGlobalColor(settings.primaryColor, "primary", "#00226b") } if (settings.backgroundColor || hasGlobalColor("background")) { style["--swift-commerce-cookie-consent-background"] = resolveGlobalColor(settings.backgroundColor, "background", "#ffffff") } if (settings.textColor || hasGlobalColor("text")) { const textColor = resolveGlobalColor(settings.textColor, "text", "#1f2937") style["--swift-commerce-cookie-consent-text"] = textColor style["--swift-commerce-cookie-consent-muted"] = textColor } if (settings.acceptButtonColor) { style["--swift-commerce-cookie-consent-accept-background"] = settings.acceptButtonColor } if (settings.acceptButtonTextColor) { style["--swift-commerce-cookie-consent-accept-text"] = settings.acceptButtonTextColor } if (settings.declineButtonColor) { style["--swift-commerce-cookie-consent-decline"] = settings.declineButtonColor } if ((settings.fontFamily && settings.fontFamily !== "inherit") || hasGlobalTypography("body")) { style["--swift-commerce-cookie-consent-font-family"] = resolveGlobalTypography(settings.fontFamily, "body", "inherit") } style["--swift-commerce-cookie-consent-radius"] = `${settings.borderRadius || 0}px` const classes = [ "swift-commerce-ui", "swift-commerce-cookie-consent", "swift-commerce-cookie-consent--preview", "is-visible", `swift-commerce-cookie-consent--template-${settings.template}`, `swift-commerce-cookie-consent--position-${settings.position}`, `swift-commerce-cookie-consent--layout-${settings.layout}`, `swift-commerce-cookie-consent--theme-${settings.theme}`, `swift-commerce-cookie-consent--animation-${settings.animation}`, `swift-commerce-cookie-consent--buttons-${settings.buttonStyle}`, `swift-commerce-cookie-consent--buttons-${settings.buttonSize}`, `swift-commerce-cookie-consent--decline-${settings.declineButtonStyle}`, `swift-commerce-cookie-consent--settings-${settings.settingsButtonStyle}`, settings.showIcon && !isMagazine ? "swift-commerce-cookie-consent--has-icon" : "", settings.overlayBlur || settings.blur ? "swift-commerce-cookie-consent--overlay-blur" : "", ].filter(Boolean).join(" ") return ( <>
{behaviorSettings.reopenMethod === "floating-button" && ( )} ) }