import { useState, useEffect } from "react"; interface ScreenSourcePickerProps { title?: string; confirmLabel?: string; getSources: () => Promise; onSelect: (sourceId: string) => void; onCancel: () => void; } export function ScreenSourcePicker({ title = "Select a screen", confirmLabel = "Select", getSources, onSelect, onCancel, }: ScreenSourcePickerProps) { const [sources, setSources] = useState([]); const [selectedId, setSelectedId] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { getSources().then((result) => { setSources(result); setLoading(false); }); }, [getSources]); // Auto-select if there's only one source useEffect(() => { if (!loading && sources.length === 1) { setSelectedId(sources[0].id); } }, [loading, sources]); const screens = sources.filter((s) => s.id.startsWith("screen:")); const windows = sources.filter((s) => s.id.startsWith("window:")); return (

{title}

{loading ? (

Loading sources...

) : ( <> {screens.length > 0 && ( )} {windows.length > 0 && ( )} )}
); } function SourceSection({ title, sources, selectedId, onSelect, }: { title: string; sources: ScreenSource[]; selectedId: string | null; onSelect: (id: string) => void; }) { return (

{title}

{sources.map((source) => ( ))}
); }