'use client'; import { useState } from 'react'; import type { VideoSource } from '@/lib/types'; interface SourceManagerProps { sources: VideoSource[]; onSourcesChange: (sources: VideoSource[]) => void; } export function SourceManager({ sources, onSourcesChange }: SourceManagerProps) { const [editingId, setEditingId] = useState(null); const handleToggle = (id: string) => { const updated = sources.map(s => s.id === id ? { ...s, enabled: !s.enabled } : s ); onSourcesChange(updated); }; const handleDelete = (id: string) => { const updated = sources.filter(s => s.id !== id); onSourcesChange(updated); }; const handlePriorityChange = (id: string, direction: 'up' | 'down') => { const currentIndex = sources.findIndex(s => s.id === id); if (currentIndex === -1) return; const newIndex = direction === 'up' ? currentIndex - 1 : currentIndex + 1; if (newIndex < 0 || newIndex >= sources.length) return; const updated = [...sources]; [updated[currentIndex], updated[newIndex]] = [updated[newIndex], updated[currentIndex]]; // Update priorities updated.forEach((s, idx) => s.priority = idx + 1); onSourcesChange(updated); }; return (
{sources.map((source, index) => (
{/* Toggle Switch */} {/* Source Info */}
{source.name}
{source.baseUrl}
{/* Controls */}
{/* Priority Controls */} {/* Delete Button */}
))}
); }