"use client"; import { useState, useEffect } from "react"; import Link from "next/link"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; import { Header } from "@/components/ui/header"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Trash2, Plus, Folder, HardDrive } from "lucide-react"; interface Library { id: number; path: string; } const SettingsPage = () => { const [libraries, setLibraries] = useState([]); const [newLibraryPath, setNewLibraryPath] = useState(""); const [error, setError] = useState(null); const [scanStatus, setScanStatus] = useState(""); useEffect(() => { fetchLibraries(); }, []); const fetchLibraries = async () => { try { const res = await fetch("/api/libraries"); const data = await res.json(); setLibraries(data); } catch (error) { console.error('Error fetching libraries:', error); } }; const addLibrary = async () => { if (!newLibraryPath.trim()) { setError("Please enter a valid path"); return; } try { const res = await fetch("/api/libraries", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ path: newLibraryPath.trim() }), }); if (res.ok) { setNewLibraryPath(""); setError(null); fetchLibraries(); } else { const data = await res.json(); setError(data.error || "Failed to add library"); } } catch (error) { setError("Network error occurred"); } }; const deleteLibrary = async (id: number) => { if (!confirm("Are you sure you want to delete this library? This will not delete the actual files.")) { return; } try { const res = await fetch(`/api/libraries/${id}`, { method: "DELETE", }); if (res.ok) { fetchLibraries(); } } catch (error) { console.error('Error deleting library:', error); } }; const [isScanning, setIsScanning] = useState(false); const scanLibraries = async () => { setIsScanning(true); setScanStatus("Scanning libraries..."); try { const res = await fetch("/api/scan", { method: "POST", }); if (res.ok) { setScanStatus("Scan completed successfully!"); setTimeout(() => setScanStatus(""), 3000); } else { setScanStatus("Scan failed. Please try again."); } } catch (error) { setScanStatus("Network error during scan"); } finally { setIsScanning(false); } }; const getTotalStorage = () => { return libraries.reduce((total, lib) => { // Rough estimation based on path length return total + (lib.path.length * 100); // Placeholder calculation }, 0); }; return (

Settings

Configure your media libraries and system preferences

Media Libraries

Manage your media source directories

{ setNewLibraryPath(e.target.value); setError(null); }} onKeyPress={(e) => e.key === 'Enter' && addLibrary()} className="flex-1 px-4 py-3 bg-zinc-800 border border-zinc-700 rounded-lg text-sm text-white focus:outline-none focus:ring-2 focus:ring-red-500 focus:border-transparent transition-all placeholder-zinc-500" />
{error && (

{error}

)} {libraries.length > 0 && (

{libraries.length} {libraries.length === 1 ? 'Library' : 'Libraries'}

{libraries.map((lib) => (

{lib.path}

Ready to scan

))}
)} {libraries.length === 0 && (

No libraries configured

Add your first library to get started

)}

Media Scanner

Discover new media files

{scanStatus && (

{scanStatus}

)}

{libraries.length === 0 ? "Add at least one library to enable scanning" : "Scan will discover new videos and photos"}

System Status

Libraries {libraries.length}
Database SQLite
Status Active

Quick Actions

View Videos View Photos Browse Files
); }; export default SettingsPage;