import { useState } from 'react' import { Box, TextField, Button, IconButton, Tooltip, Menu, MenuItem, InputAdornment, AppBar, Toolbar, useMediaQuery, } from '@mui/material' import { Done, Visibility, VisibilityOff, Close } from '@mui/icons-material' import { useTheme } from '@mui/material' import { useI18nStore } from '../../stores/i18n.store' import { useAuthStore } from '../../stores/auth.store' import { useThemeStore } from '../../stores/theme.store' export default function LoginPage() { const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [pwVisible, setPwVisible] = useState(false) const [loading, setLoading] = useState(false) const [guiAnchor, setGuiAnchor] = useState(null) const strings = useI18nStore(s => s.strings) const isWide = useMediaQuery('(min-width: 600px)') const { login, loginError } = useAuthStore() const muiTheme = useTheme() const themeKey = useThemeStore(s => s.themeKey) const footerBg = themeKey === 'matrix' ? '#0a2e0d' : muiTheme.p3xr.accordionBg const currentGui = (() => { try { return localStorage.getItem('p3xr-frontend') || 'ng' } catch { return 'ng' } })() const handleLogin = async () => { if (loading || !username || !password) return setLoading(true) const success = await login(username, password) if (success) { location.reload() } setLoading(false) } const switchGui = (gui: string) => { try { localStorage.setItem('p3xr-frontend', gui) } catch {} location.href = gui === 'react' ? '/react/' : '/ng/' } const getErrorMessage = (error: string) => { return strings?.confirm?.invalidCredentials || 'Invalid username or password.' } return ( {/* Header — matches P3xrDialog toolbar */} setGuiAnchor(null)}> switchGui('ng')}> Angular switchGui('react')}> React {/* Content — matches P3xrDialog content */} setUsername(e.target.value)} autoComplete="username" onKeyDown={e => e.key === 'Enter' && handleLogin()} /> setPassword(e.target.value)} autoComplete="current-password" onKeyDown={e => e.key === 'Enter' && handleLogin()} slotProps={{ input: { endAdornment: ( setPwVisible(!pwVisible)} size="small"> {pwVisible ? : } ), }, }} /> {loginError && ( {getErrorMessage(loginError)} )} {/* Footer — matches P3xrDialog actions */} {isWide ? ( ) : ( )} ) }