import React, { useEffect, useRef } from 'react' import WorldCampaignMeta from './WorldCampaignMeta' import WorldCard from './WorldCard' import WorldStatusBadge from './WorldStatusBadge' import { trackWorldSourceClick, trackWorldSourceImpression, withWorldSource } from '../../lib/worldAnalytics' export default function ActiveWorldSpotlight({ spotlight, secondary = [], indexUrl = '/worlds', eyebrow = 'World spotlight', secondaryTitle = 'Campaign rail', className = '', sourceSurface = '', sourceDetail = '', secondarySourceSurface = '', secondarySourceDetail = '', }) { const spotlightRef = useRef(null) const primaryHref = spotlight && sourceSurface ? withWorldSource(spotlight.public_url || spotlight.cta_url, sourceSurface, sourceDetail) : (spotlight?.public_url || spotlight?.cta_url) useEffect(() => { if (!spotlight?.id || !sourceSurface || typeof window === 'undefined') { return undefined } const node = spotlightRef.current if (!node) { return undefined } if (typeof window.IntersectionObserver !== 'function') { trackWorldSourceImpression({ worldId: spotlight.id, worldTitle: spotlight.title || spotlight.headline, sourceSurface, sourceDetail, sectionKey: 'spotlight', }) return undefined } const observer = new window.IntersectionObserver((entries) => { entries.forEach((entry) => { if (!entry.isIntersecting || entry.intersectionRatio < 0.45) { return } trackWorldSourceImpression({ worldId: spotlight.id, worldTitle: spotlight.title || spotlight.headline, sourceSurface, sourceDetail, sectionKey: 'spotlight', }) observer.disconnect() }) }, { threshold: [0.45] }) observer.observe(node) return () => observer.disconnect() }, [spotlight?.headline, spotlight?.id, spotlight?.title, sourceDetail, sourceSurface]) if (!spotlight) { return null } return (
{spotlight.cover_url ? {spotlight.title : null}
{eyebrow}
{(Array.isArray(spotlight.status_badges) ? spotlight.status_badges : []).map((badge) => ( ))} {spotlight.campaign_label ? : null}
{spotlight.title && spotlight.headline && spotlight.title !== spotlight.headline ?

{spotlight.title}

: null}

{spotlight.headline || spotlight.title}

{spotlight.tagline ?

{spotlight.tagline}

: null} {spotlight.summary ?

{spotlight.summary}

: null} {spotlight.supporting_item ? (
{spotlight.supporting_item.entity_label || 'Related item'}
{spotlight.supporting_item.title}
{spotlight.supporting_item.context_label ?
{spotlight.supporting_item.context_label}
: null}
) : null}
Campaign state
{spotlight.theme?.label || 'Editorial world'}
{spotlight.timeframe_label ?
{spotlight.timeframe_label}
: null} {spotlight.promotion_window_label ?
{spotlight.promotion_window_label}
: null} {Number(spotlight.live_submission_count || 0) > 0 ?
{spotlight.live_submission_count} live submissions are already part of this campaign.
: null}
{Array.isArray(secondary) && secondary.length > 0 ? (

{secondaryTitle}

More live or upcoming worlds that are being actively surfaced right now.

{secondary.length} worlds
{secondary.map((world) => )}
) : null}
) }