import React, { useEffect, useRef } from 'react' import UploadWorldHighlightCard from './UploadWorldHighlightCard' import WorldCampaignMeta from './WorldCampaignMeta' import WorldStatusBadge from './WorldStatusBadge' import { trackWorldAnalytics, trackWorldSourceImpression } from '../../lib/worldAnalytics' function modeTone(mode) { switch (mode) { case 'manual_approval': return 'border-sky-300/30 bg-sky-400/10 text-sky-100' case 'auto_add': return 'border-emerald-300/30 bg-emerald-400/10 text-emerald-100' default: return 'border-white/10 bg-white/[0.04] text-slate-300' } } function dateBadgeLabel(item) { const timeframe = String(item?.timeframe_label || '').trim() const submissionWindow = String(item?.submission_window_label || '').trim() if (timeframe && submissionWindow) { return timeframe === submissionWindow ? timeframe : `${submissionWindow} • ${timeframe}` } return submissionWindow || timeframe || '' } export default function WorldSubmissionSelector({ title = 'Add to Worlds', description = 'Attach this artwork to active worlds while keeping community participation separate from curated editorial relations.', options = [], emptyMessage = 'No worlds are currently open for creator participation.', onToggle, onNoteChange, className = '', analyticsContext = null, }) { const items = Array.isArray(options) ? options : [] const highlightedWorld = items.find((item) => item.is_active_campaign && item.is_accepting_submissions) const itemRefs = useRef(new Map()) useEffect(() => { if (!analyticsContext?.sourceSurface || typeof window === 'undefined') { return undefined } const refs = Array.from(itemRefs.current.entries()) if (refs.length === 0) { return undefined } if (typeof window.IntersectionObserver !== 'function') { refs.forEach(([worldId]) => { const item = items.find((candidate) => Number(candidate.id) === Number(worldId)) if (!item) { return } trackWorldSourceImpression({ worldId: item.id, worldTitle: item.title || item.teaser_title || '', sourceSurface: analyticsContext.sourceSurface, sourceDetail: analyticsContext.sourceDetail ? `${analyticsContext.sourceDetail}:selector` : 'selector', sectionKey: 'community_submissions', }) }) return undefined } const observer = new window.IntersectionObserver((entries) => { entries.forEach((entry) => { if (!entry.isIntersecting || entry.intersectionRatio < 0.35) { return } const worldId = Number(entry.target.getAttribute('data-world-id') || 0) const item = items.find((candidate) => Number(candidate.id) === worldId) if (!item) { return } trackWorldSourceImpression({ worldId: item.id, worldTitle: item.title || item.teaser_title || '', sourceSurface: analyticsContext.sourceSurface, sourceDetail: analyticsContext.sourceDetail ? `${analyticsContext.sourceDetail}:selector` : 'selector', sectionKey: 'community_submissions', }) observer.unobserve(entry.target) }) }, { threshold: [0.35] }) refs.forEach(([, node]) => { if (node) { observer.observe(node) } }) return () => observer.disconnect() }, [analyticsContext?.sourceDetail, analyticsContext?.sourceSurface, items]) return (

{title}

{description}

{items.filter((item) => item.selected).length} selected
{items.length === 0 ? (
{emptyMessage}
) : (
{items.map((item) => { const checked = Boolean(item.selected) const locked = Boolean(item.selection_locked) const combinedDateLabel = dateBadgeLabel(item) return (
{ if (node) { itemRefs.current.set(item.id, node) } else { itemRefs.current.delete(item.id) } }} data-world-id={item.id} className={`overflow-hidden rounded-[24px] border transition-colors ${checked ? 'border-sky-300/25 bg-sky-400/[0.07]' : 'border-white/10 bg-black/20'}`} > {/* ── Compact row (always visible) ── */} {/* ── Expanded details (only when checked) ── */} {checked ? (
{/* Full description */} {(item.teaser_summary || item.summary) ? (

{item.teaser_summary || item.summary}

) : null} {/* Date/window chips */} {(combinedDateLabel || item.promotion_window_label) ? (
{combinedDateLabel ? {combinedDateLabel} : null} {item.promotion_window_label ? {item.promotion_window_label} : null} {item.can_resubmit ? Can re-add : null}
) : null} {/* Guidelines */} {item.submission_guidelines ? (
World guidelines
{item.submission_guidelines}
) : null} {/* Locked reason */} {item.selection_locked_reason ? (
{item.selection_locked_reason}
) : null} {/* Moderator note */} {item.reviewer_note ? (
Moderator note
{item.reviewer_note}
) : null} {/* Creator note */} {item.submission_note_enabled ? (