import React, { useEffect, useRef } from 'react' import WorldCampaignMeta from './WorldCampaignMeta' import WorldStatusBadge from './WorldStatusBadge' import { trackWorldSourceClick, trackWorldSourceImpression, withWorldSource } from '../../lib/worldAnalytics' function themeStyle(theme) { return { '--world-accent': theme?.accent_color || '#38bdf8', '--world-accent-secondary': theme?.accent_color_secondary || '#0f172a', } } export default function WorldCard({ world, compact = false, sourceSurface = '', sourceDetail = '' }) { const cardRef = useRef(null) const href = world && sourceSurface ? withWorldSource(world.public_url, sourceSurface, sourceDetail) : world?.public_url useEffect(() => { if (!sourceSurface || !world?.id || typeof window === 'undefined') { return undefined } const node = cardRef.current if (!node) { return undefined } if (typeof window.IntersectionObserver !== 'function') { trackWorldSourceImpression({ worldId: world.id, worldTitle: world.title, sourceSurface, sourceDetail, sectionKey: compact ? 'compact_card' : 'card', }) return undefined } const observer = new window.IntersectionObserver((entries) => { entries.forEach((entry) => { if (!entry.isIntersecting || entry.intersectionRatio < 0.4) { return } trackWorldSourceImpression({ worldId: world.id, worldTitle: world.title, sourceSurface, sourceDetail, sectionKey: compact ? 'compact_card' : 'card', }) observer.disconnect() }) }, { threshold: [0.4] }) observer.observe(node) return () => observer.disconnect() }, [compact, sourceDetail, sourceSurface, world?.id, world?.title]) if (!world) { return null } return ( trackWorldSourceClick({ worldId: world.id, worldTitle: world.title, sourceSurface, sourceDetail })} className={`group relative block w-full overflow-hidden rounded-[28px] border border-white/10 bg-slate-950/70 transition duration-300 hover:-translate-y-1 hover:border-white/20 ${compact ? 'p-5' : 'p-6'}`} style={themeStyle(world.theme)} >
{world.cover_url ? {world.title} : null}
{world.is_recurring ? (
{world.family_title || 'Recurring family'} {world.edition_label ? {world.edition_label} : null}
) : null}
{(Array.isArray(world.status_badges) ? world.status_badges : []).map((badge) => ( ))} {!Array.isArray(world.status_badges) || world.status_badges.length === 0 ? : null} {world.campaign_label ? : null} {world.badge_label ? : null}
{world.teaser_title && world.teaser_title !== world.title ?

{world.title}

: null}

{world.teaser_title || world.title}

{world.tagline ?

{world.tagline}

: null} {world.summary ?

{world.summary}

: null}
{world.cta_label || world.challenge_cta_label || (world.is_recurring && !world.is_canonical_edition ? 'Open edition' : 'Open world')}
) }