'use client'; import React, { useState } from 'react'; import { cn } from "@/lib/utils" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Select, SelectTrigger, SelectContent, SelectItem, SelectValue } from '@/components/ui/select'; import { useNavidromeConfig } from '@/app/components/NavidromeConfigContext'; import { useTheme } from '@/app/components/ThemeProvider'; import { useToast } from '@/hooks/use-toast'; import { FaServer, FaUser, FaLock, FaCheck, FaTimes, FaPalette, FaLastfm } from 'react-icons/fa'; export function LoginForm({ className, ...props }: React.ComponentProps<"div">) { const [step, setStep] = useState<'login' | 'settings'>('login'); const { config, updateConfig, testConnection } = useNavidromeConfig(); const { theme, setTheme } = useTheme(); const { toast } = useToast(); const [formData, setFormData] = useState({ serverUrl: config.serverUrl || '', username: config.username || '', password: config.password || '' }); const [isTesting, setIsTesting] = useState(false); // Settings for step 2 const [scrobblingEnabled, setScrobblingEnabled] = useState(() => { if (typeof window !== 'undefined') { return localStorage.getItem('lastfm-scrobbling-enabled') === 'true'; } return true; }); const handleInputChange = (field: string, value: string) => { setFormData(prev => ({ ...prev, [field]: value })); }; const handleTestAndNext = async (e: React.FormEvent) => { e.preventDefault(); if (!formData.serverUrl || !formData.username || !formData.password) { toast({ title: "Missing Information", description: "Please fill in all fields before proceeding.", variant: "destructive" }); return; } setIsTesting(true); try { // Strip trailing slash from server URL before testing const cleanServerUrl = formData.serverUrl.replace(/\/+$/, ''); const success = await testConnection({ serverUrl: cleanServerUrl, username: formData.username, password: formData.password }); if (success) { // Save the config updateConfig({ serverUrl: cleanServerUrl, username: formData.username, password: formData.password }); toast({ title: "Connection Successful", description: "Connected to Navidrome! Let's configure your preferences.", }); // Move to settings step setStep('settings'); } else { toast({ title: "Connection Failed", description: "Could not connect to the server. Please check your settings.", variant: "destructive" }); } } catch (error) { toast({ title: "Connection Error", description: "An error occurred while testing the connection.", variant: "destructive" }); } finally { setIsTesting(false); } }; const handleFinishSetup = () => { // Save scrobbling preference localStorage.setItem('lastfm-scrobbling-enabled', scrobblingEnabled.toString()); toast({ title: "Setup Complete", description: "Welcome to mice! Your music streaming experience is ready.", }); // Reload the page to start the main app window.location.reload(); }; const handleScrobblingToggle = (enabled: boolean) => { setScrobblingEnabled(enabled); }; if (step === 'settings') { return (
Customize Your Experience Configure your preferences to get started
{/* Theme Selection */}
{/* Last.fm Scrobbling */}

{scrobblingEnabled ? "Tracks will be scrobbled to Last.fm via Navidrome" : "Last.fm scrobbling will be disabled"}

); } return (
Connect to Navidrome Enter your Navidrome server details to get started
handleInputChange('serverUrl', e.target.value)} required />
handleInputChange('username', e.target.value)} required />
handleInputChange('password', e.target.value)} required />
) }