import React, { useState, useEffect, useRef } from 'react'; import { Link2, Upload, FileVideo, X, Info, Loader2 } from 'lucide-react'; import { getApiUrl } from '../config'; const SUPPORTED_PLATFORMS = [ 'YouTube', 'Vimeo', 'TikTok', 'X / Twitter', 'Twitch', 'Facebook', 'Instagram', 'Dailymotion', 'Reddit', 'Streamable', ]; export default function MediaInput({ onProcess, isProcessing }) { const [youtubeUrlEnabled, setYoutubeUrlEnabled] = useState(true); // File upload is the primary path; the link is secondary. const [mode, setMode] = useState('file'); // 'file' | 'url' const [url, setUrl] = useState(''); const [file, setFile] = useState(null); const [acknowledged, setAcknowledged] = useState(false); const [outputFormat, setOutputFormat] = useState('vertical'); // vertical | horizontal | square const [showInfo, setShowInfo] = useState(false); const infoRef = useRef(null); // Close the compatibility popover on any outside click. useEffect(() => { if (!showInfo) return; const onClick = (e) => { if (infoRef.current && !infoRef.current.contains(e.target)) setShowInfo(false); }; document.addEventListener('mousedown', onClick); return () => document.removeEventListener('mousedown', onClick); }, [showInfo]); useEffect(() => { fetch(getApiUrl('/api/config')) .then((r) => r.ok ? r.json() : null) .then((cfg) => { if (cfg && cfg.youtubeUrlEnabled === false) { setYoutubeUrlEnabled(false); setMode('file'); } }) .catch(() => {}); }, []); const handleSubmit = (e) => { e.preventDefault(); if (!acknowledged) return; if (mode === 'url' && url) { onProcess({ type: 'url', payload: url, acknowledged: true, outputFormat }); } else if (mode === 'file' && file) { onProcess({ type: 'file', payload: file, acknowledged: true, outputFormat }); } }; const handleDrop = (e) => { e.preventDefault(); if (e.dataTransfer.files && e.dataTransfer.files[0]) { setFile(e.dataTransfer.files[0]); setMode('file'); } }; return (