"use client"; import React, { useState } from 'react'; import { Sparkles, Upload } from 'lucide-react'; import { AIGeneratedBadge } from '../ui/ai-generated-badge'; import { Label } from '../ui/label'; import { Button } from '../ui/button'; import { Badge } from '../ui/badge'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select'; import { AIEnrichSection } from './ai-enrich/AIEnrichSection'; import type { AIRequiredField } from './ai-enrich/AIEnrichSection'; import { Video } from './video'; export interface HighlightVideoSectionProps { /** Current highlight video URL */ highlightVideoUrl?: string | null; /** Highlight video thumbnail URL */ highlightVideoThumbnail?: string | null; /** Highlight video duration in milliseconds */ highlightVideoDurationMs?: number | null; /** Highlight video source type */ highlightVideoSource?: 'manual' | 'ai_generated' | null; /** Target duration in seconds for AI generation */ targetDurationSeconds: number; /** Callback when target duration changes */ onTargetDurationChange: (seconds: number) => void; /** Callback to trigger highlight generation */ onGenerateHighlight: () => void; /** Whether highlight generation is in progress */ isGenerating?: boolean; /** Progress percentage for generation (0-100) */ generationProgress?: number; /** Status message during generation */ generationStatusMessage?: string; /** Generation status (cancelled maps to error) */ generationStatus?: 'idle' | 'loading' | 'success' | 'error'; /** Whether highlight can be generated */ canGenerateHighlight?: boolean; /** Required fields for generation */ requiredFields?: AIRequiredField[]; /** Message when generation is disabled */ disabledMessage?: string; /** Whether a previous highlight exists */ hasExistingHighlight?: boolean; /** Callback to cancel generation */ onCancelGeneration?: () => void; /** Whether cancellation is in progress */ isCancelling?: boolean; /** Callback to upload highlight video manually */ onUploadHighlight: (file: File) => Promise; /** Whether upload is in progress */ isUploading?: boolean; /** Callback when highlight video is deleted */ onDeleteHighlight?: () => void; /** Custom video preview component */ VideoPreviewComponent?: React.ComponentType<{ videoUrl: string; thumbnailUrl?: string; onDelete?: () => void; }>; /** Whether section is disabled (e.g., YouTube selected) */ disabled?: boolean; /** Additional class name */ className?: string; } /** * HighlightVideoSection - Unified component for highlight video generation and management * * This component provides a consistent UI for both CustomerInterview and ProductRelease entities, * including duration configuration, AI generation trigger, manual upload, and video preview. */ export function HighlightVideoSection({ highlightVideoUrl, highlightVideoThumbnail, highlightVideoDurationMs, highlightVideoSource, targetDurationSeconds, onTargetDurationChange, onGenerateHighlight, isGenerating = false, generationProgress, generationStatusMessage, generationStatus, canGenerateHighlight = true, requiredFields = [], disabledMessage = 'Upload a video and run transcription first', hasExistingHighlight = false, onCancelGeneration, isCancelling = false, onUploadHighlight, isUploading = false, onDeleteHighlight, VideoPreviewComponent, disabled = false, className = '', }: HighlightVideoSectionProps) { const [uploadError, setUploadError] = useState(null); const handleUploadClick = () => { const input = document.createElement('input'); input.type = 'file'; input.accept = 'video/*'; input.onchange = async (e: Event) => { const target = e.target as HTMLInputElement; const file = target.files?.[0]; if (!file) return; setUploadError(null); try { await onUploadHighlight(file); } catch (err) { setUploadError(err instanceof Error ? err.message : 'Failed to upload video'); } }; input.click(); }; const formatDuration = (ms: number) => { const minutes = Math.floor(ms / 60000); const seconds = Math.floor((ms % 60000) / 1000); return `${minutes}:${String(seconds).padStart(2, '0')}`; }; return (
{/* Highlight Video Configuration */}
{/* AI Generation Section */} } buttonLabel={hasExistingHighlight ? "Regenerate Highlight" : "Generate Highlight"} loadingLabel="Generating highlight..." onEnrich={onGenerateHighlight} loading={isGenerating} canEnrich={canGenerateHighlight && !disabled} requiredFields={requiredFields} status={generationStatus} statusMessage={ generationStatusMessage ? (generationProgress && generationProgress > 0 ? `${generationStatusMessage} (${generationProgress}%)` : generationStatusMessage) : undefined } disabledMessage={disabled ? "Switch to 'Upload Video' to enable AI processing" : disabledMessage} showCancel={!!onCancelGeneration} onCancel={onCancelGeneration} isCancelling={isCancelling} /> {/* Highlight Video Preview + Manual Upload */}
{highlightVideoSource === 'ai_generated' && ( )} {highlightVideoDurationMs && ( {formatDuration(highlightVideoDurationMs)} )}
{uploadError && (

{uploadError}

)} {highlightVideoUrl ? ( VideoPreviewComponent ? ( ) : ( // Default simple preview — the
); } export default HighlightVideoSection;