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(() => {}); }, []); // A link pasted in the landing hero: preload it here so the user picks up // where they left off. Not auto-submitted — the rights attestation below // has to be ticked by the user. useEffect(() => { let pending = null; try { pending = localStorage.getItem('os_pending_url'); if (pending) localStorage.removeItem('os_pending_url'); } catch { /* ignore */ } if (pending) { setMode('url'); setUrl(pending); } }, []); 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 (
{youtubeUrlEnabled && ( )}
{mode === 'url' ? (
setUrl(e.target.value)} placeholder="https://... paste a video link" className="input-field pr-11" required />
{showInfo && (

Paste a link from

{SUPPORTED_PLATFORMS.map((p) => ( {p} ))}

…and 1,000+ more sites. If a link has a public video, we can usually fetch it.

)}
) : (
e.preventDefault()} onDrop={handleDrop} > {file ? (
{file.name}
) : ( )}
)} {/* Output format selector */}

Output format

{[ { value: 'vertical', label: '9:16', hint: 'Shorts · Reels · TikTok', w: 18, h: 32 }, { value: 'square', label: '1:1', hint: 'Feed posts', w: 28, h: 28 }, { value: 'horizontal', label: '16:9', hint: 'Keep landscape · YouTube', w: 36, h: 20 }, ].map((f) => { const active = outputFormat === f.value; return ( ); })}
); }