import React, { useCallback } from 'react' import ReadinessChecklist from './ReadinessChecklist' import SchedulePublishPicker from './SchedulePublishPicker' import Checkbox from '../../Components/ui/Checkbox' /** * PublishPanel * * Right-sidebar panel (or mobile bottom-sheet) that shows: * - Thumbnail preview + title * - Status pill * - ReadinessChecklist * - Visibility selector * - Publish now / Schedule controls * - Primary action button * * Props mirror what UploadWizard collects. */ const STATUS_PILL = { idle: null, initializing: { label: 'Uploading', cls: 'bg-sky-500/20 text-sky-200 border-sky-300/30' }, uploading: { label: 'Uploading', cls: 'bg-sky-500/25 text-sky-100 border-sky-300/40' }, finishing: { label: 'Processing', cls: 'bg-amber-500/20 text-amber-200 border-amber-300/30' }, processing: { label: 'Processing', cls: 'bg-amber-500/20 text-amber-200 border-amber-300/30' }, ready_to_publish: { label: 'Ready', cls: 'bg-emerald-500/20 text-emerald-100 border-emerald-300/35' }, publishing: { label: 'Publishing…', cls: 'bg-sky-500/25 text-sky-100 border-sky-300/40' }, complete: { label: 'Published', cls: 'bg-emerald-500/25 text-emerald-100 border-emerald-300/50' }, scheduled: { label: 'Scheduled', cls: 'bg-violet-500/20 text-violet-200 border-violet-300/30' }, error: { label: 'Error', cls: 'bg-red-500/20 text-red-200 border-red-300/30' }, cancelled: { label: 'Cancelled', cls: 'bg-white/8 text-white/40 border-white/10' }, } export default function PublishPanel({ // Asset primaryPreviewUrl = null, isArchive = false, screenshots = [], // Metadata metadata = {}, // Readiness machineState = 'idle', uploadReady = false, canPublish = false, isPublishing = false, isArchiveRequiresScreenshot = false, // Publish options publishMode = 'now', // 'now' | 'schedule' scheduledAt = null, timezone = Intl.DateTimeFormat().resolvedOptions().timeZone, visibility = 'public', // 'public' | 'unlisted' | 'private' onPublishModeChange, onScheduleAt, onVisibilityChange, onToggleRights, // Actions onPublish, onCancel, // Navigation helpers (for checklist quick-links) onGoToStep, }) { const pill = STATUS_PILL[machineState] ?? null const hasPreview = Boolean(primaryPreviewUrl && !isArchive) const hasAnyPreview = hasPreview || (isArchive && screenshots.length > 0) const previewSrc = hasPreview ? primaryPreviewUrl : (screenshots[0]?.preview ?? screenshots[0] ?? null) const title = String(metadata.title || '').trim() const hasTitle = Boolean(title) const hasCategory = Boolean(metadata.rootCategoryId) const hasTag = Array.isArray(metadata.tags) && metadata.tags.length > 0 const hasRights = Boolean(metadata.rightsAccepted) const hasScreenshot = !isArchiveRequiresScreenshot || screenshots.length > 0 const checklist = [ { label: 'File uploaded & processed', ok: uploadReady }, { label: 'Title', ok: hasTitle, onClick: () => onGoToStep?.(2) }, { label: 'Category', ok: hasCategory, onClick: () => onGoToStep?.(2) }, { label: 'Rights confirmed', ok: hasRights, onClick: () => onGoToStep?.(2) }, ...( isArchiveRequiresScreenshot ? [{ label: 'Screenshot (required for pack)', ok: hasScreenshot, onClick: () => onGoToStep?.(1) }] : [] ), { label: 'At least 1 tag', ok: hasTag, onClick: () => onGoToStep?.(2) }, ] const publishLabel = useCallback(() => { if (isPublishing) return 'Publishing…' if (publishMode === 'schedule') return 'Schedule publish' return 'Publish now' }, [isPublishing, publishMode]) const canSchedulePublish = publishMode === 'schedule' ? Boolean(scheduledAt) && canPublish : canPublish const rightsError = uploadReady && !hasRights ? 'Rights confirmation is required.' : null return (
{/* Preview + title */}
{/* Thumbnail */}
{previewSrc ? ( Artwork preview ) : ( )}
{/* Title + status */}

{hasTitle ? title : Untitled artwork}

{pill && ( {['uploading', 'initializing', 'finishing', 'processing', 'publishing'].includes(machineState) && (
{/* Divider */}
{/* Readiness checklist */} {/* Visibility */}
{/* Schedule picker – only shows when upload is ready */} {uploadReady && machineState !== 'complete' && ( )} {/* Rights confirmation (required before publish) */}
onToggleRights?.(event.target.checked)} variant="emerald" size={18} label={I confirm I own the rights to this content.} hint={Required before publishing.} error={rightsError} required />
{/* Primary action button */} {/* Cancel link */} {onCancel && machineState !== 'idle' && machineState !== 'complete' && ( )}
) }