'use client' import { CalendarIcon, ExternalLinkIcon, MapPinIcon, VideoIcon } from 'lucide-react' import Image from 'next/image' import { useEffect, useState } from 'react' import { CampaignFooter } from '@/components/CampaignFooter' import { CampaignPageHeader } from '@/components/CampaignPageHeader' import { SAFE_FOCUS } from '@/components/shareLink/menuControls' import { ShareLinkAgendaMenu } from '@/components/shareLink/ShareLinkAgendaMenu' import { ShareLinkShareMenu } from '@/components/shareLink/ShareLinkShareMenu' import type { ShareLinkLiveTarget } from '@/lib/shareLink' import type { ShareLinkAnnouncementView } from '@/lib/shareLinkAnnouncement' import { cn } from '@/lib/utils' const POLL_INTERVAL_MS = 30_000 const PRIMARY_ACTION = cn( 'inline-flex min-h-14 w-full items-center justify-center gap-2.5 rounded-[10px] bg-(--pt-yellow) px-4', 'font-[family-name:var(--font-exo2)] text-lg font-black text-(--pt-yellow-ink) no-underline', 'shadow-[0_5px_0_#cfb900,0_10px_22px_rgb(0_0_0/12%)]', ) const PRIMARY_ACTION_DISABLED = cn( PRIMARY_ACTION, 'cursor-not-allowed bg-[#e7e2d5] text-[rgb(0_0_0/48%)] shadow-[0_3px_0_#cfc9bb]', ) /** * S29 — the public announcement page of a share link (design artefato cenas * 01–03): honest pre-broadcast state with a disabled "Entrar", date/location in * Bahia time, agenda and share options, and the live swap — the poll reads the * fresh "no ar" target every 30s (paused on hidden tabs) and flips the CTA * without a reload, so the place of the button never changes for whoever left * the page open. The link itself keeps redirecting after a reload; this page * only exists while nothing is on air. */ export const ShareLinkAnnouncement = ({ view, showJingles = false, }: { view: ShareLinkAnnouncementView showJingles?: boolean }) => { const [live, setLive] = useState(null) const isLive = live !== null const hasEventDetails = Boolean(view.eventLabel || view.location) useEffect(() => { let cancelled = false const refetch = async () => { try { const response = await fetch(`/api/share-link/${encodeURIComponent(view.slug)}/live`, { cache: 'no-store', }) if (!response.ok) return const { target } = (await response.json()) as { target: ShareLinkLiveTarget | null } if (cancelled || !target) return setLive((current) => current?.href === target.href && current?.label === target.label ? current : target, ) } catch { // A transient failure is a lost tick: the next poll retries. } } // Read immediately: the server render may be a cached pre-broadcast page // that is already out of date. void refetch() const interval = setInterval(() => { if (document.visibilityState === 'visible') void refetch() }, POLL_INTERVAL_MS) const handleVisibility = () => { if (document.visibilityState === 'visible') void refetch() } document.addEventListener('visibilitychange', handleVisibility) return () => { cancelled = true clearInterval(interval) document.removeEventListener('visibilitychange', handleVisibility) } }, [view.slug]) return (
) }