'use client' import React, { useState, useEffect } from 'react' type LinkGroup = { type?: 'reference' | 'custom' | null reference?: { slug?: string | null; relationTo?: string } | null url?: string | null newTab?: boolean | null } type Props = { text?: string | null buttonLabel?: string | null buttonLink?: LinkGroup | null dismissible?: boolean | null backgroundColor?: 'yellow' | 'navy' | 'mint' | null } function resolveUrl(link?: LinkGroup | null): string | null { if (!link) return null if (link.type === 'reference' && link.reference) { const slug = link.reference.slug return slug ? `/${slug}` : null } return link.url ?? null } export const AnnouncementBarComponent: React.FC = ({ text, buttonLabel, buttonLink, dismissible = true, backgroundColor = 'yellow', }) => { const [dismissed, setDismissed] = useState(false) useEffect(() => { const key = `fd-announcement-${text?.slice(0, 20)}` if (typeof window !== 'undefined' && localStorage.getItem(key) === 'dismissed') { setDismissed(true) } }, [text]) if (dismissed || !text) return null const bgClass = backgroundColor === 'navy' ? 'bg-fd-navy text-white' : backgroundColor === 'mint' ? 'bg-fd-mint text-fd-navy' : 'bg-fd-yellow text-fd-navy' const handleDismiss = () => { const key = `fd-announcement-${text?.slice(0, 20)}` if (typeof window !== 'undefined') localStorage.setItem(key, 'dismissed') setDismissed(true) } const href = resolveUrl(buttonLink) const newTab = buttonLink?.newTab ?? false return (
{/* Centered content — px-10 leaves room for the dismiss button on both sides */}
{text} {buttonLabel && href && ( {buttonLabel} )}
{/* Dismiss — truly absolute so it doesn't affect centering */} {dismissible && ( )}
) }