"use client"; import { useState } from "react"; import MediaPlayer from "../MediaPlayer"; import FileUpload from "../FileUpload"; import { getImageUrl } from "@/lib/api"; interface MediaBlockProps { id: string; title?: string; url: string; type: 'video' | 'audio'; config: { maxPlays?: number; currentPlays?: number; show_transcript?: boolean; }; editMode: boolean; onChange: (updates: { title?: string; url?: string; config?: { maxPlays?: number; currentPlays?: number; show_transcript?: boolean } }) => void; transcription?: { en?: string; es?: string; cues?: { start: number; end: number; text: string }[]; } | null; } export default function MediaBlock({ title, url, type, config, editMode, onChange, transcription }: MediaBlockProps) { const [localPlays, setLocalPlays] = useState(config.currentPlays || 0); const [sourceType, setSourceType] = useState<"url" | "upload">(url.startsWith("/assets/") ? "upload" : "url"); const maxPlays = config.maxPlays || 0; const isLocked = maxPlays > 0 && localPlays >= maxPlays; const handleEnded = () => { if (maxPlays > 0) { const nextPlays = localPlays + 1; setLocalPlays(nextPlays); onChange({ config: { ...config, currentPlays: nextPlays } }); } }; // Full URL for display (handles relative paths from server) const displayUrl = getImageUrl(url); return (
{/* Block Header */}
{editMode ? (
onChange({ title: e.target.value })} placeholder="e.g. Explainer Video, Audio Guide..." className="w-full bg-white/5 border border-white/10 rounded-lg px-4 py-2 text-sm font-bold focus:border-blue-500/50 focus:outline-none" />
) : ( title &&

{title}

)}
{editMode && (
{sourceType === "url" ? (
onChange({ url: e.target.value })} placeholder="YouTube, Vimeo or static link" className="w-full bg-white/5 border border-white/10 rounded-lg px-4 py-2 text-sm focus:border-blue-500/50 focus:outline-none" />
) : (
onChange({ url: newUrl })} />
)}
onChange({ config: { ...config, maxPlays: parseInt(e.target.value) || 0 } })} className="w-full bg-white/5 border border-white/10 rounded-lg px-4 py-2 text-sm focus:border-blue-500/50 focus:outline-none h-11" />

Prevent content fatigue by limiting how many times a student can watch/listen.

onChange({ config: { ...config, show_transcript: e.target.checked } })} className="w-4 h-4 rounded border-gray-600 text-blue-600 focus:ring-blue-500 bg-gray-700" />

Uncheck to hide transcription text (e.g. for listening tests).

)}
{!editMode && maxPlays > 0 && (
Plays Remaining {Math.max(0, maxPlays - localPlays)} / {maxPlays}
)}
); }