import { useEffect, useState } from 'react'; import { motion } from 'motion/react'; import { ArrowRight, KeyRound, Sparkles } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { ToggleSwitch } from '@/components/ui/toggle-switch'; import { PasswordVisibilityIcon } from '@/components/ui/password-visibility-icon'; import { ThemeToggle } from '@/components/theme-toggle'; import { LoginWaves } from '@/components/login-waves'; import { useTheme } from '@/contexts/ThemeContext'; import { cn } from '@/lib/utils'; import { APP_NAME, APP_VERSION } from '@/types'; interface LoginPageProps { onLogin: (password: string) => Promise<{ success: boolean; error?: string }>; } // Device-local preference for the (heavy) animated login background. Kept out // of the server-synced appearance on purpose: it's a "this device feels laggy" // choice, and it must work pre-auth (where settings can't persist to the // server). Independent of the system 减弱动效 / 关闭全部动效 settings. const LOGIN_FX_KEY = 'snowluma_login_fx'; function readLoginFx(): boolean { try { const v = localStorage.getItem(LOGIN_FX_KEY); if (v === '0') return false; if (v === '1') return true; } catch { /* ignore */ } // No explicit choice yet → on by default, unless the OS asks for reduced // motion (an accessibility default; still fully overridable via the toggle). try { return !window.matchMedia('(prefers-reduced-motion: reduce)').matches; } catch { return true; } } export function LoginPage({ onLogin }: LoginPageProps) { const { appearance } = useTheme(); const customBg = appearance.background.type !== 'none'; const reduce = appearance.reduceMotion || appearance.disableMotion; // The login page must never carry operator custom CSS. applyAppearance gates // it on a token, but an in-session logout / 401 expiry won't re-run it, so // clear any lingering custom-CSS