import { t } from "i18next"; import React, { useCallback, useState } from "react"; import { ScrollView, View } from "react-native"; import { Button } from "@/components/Button"; import { Text } from "@/components/common/Text"; import { useScaledTVTypography } from "@/constants/TVTypography"; import { useTVBackPress } from "@/hooks/useTVBackPress"; import { TVInput } from "./TVInput"; import { TVSaveAccountToggle } from "./TVSaveAccountToggle"; interface TVAddUserFormProps { serverName: string; serverAddress: string; onLogin: ( username: string, password: string, saveAccount: boolean, ) => Promise; onQuickConnect: () => Promise; onBack: () => void; loading?: boolean; disabled?: boolean; } export const TVAddUserForm: React.FC = ({ serverName, serverAddress, onLogin, onQuickConnect, onBack, loading = false, disabled = false, }) => { const typography = useScaledTVTypography(); const [credentials, setCredentials] = useState({ username: "", password: "", }); const [saveAccount, setSaveAccount] = useState(false); const handleLogin = async () => { if (credentials.username.trim()) { await onLogin(credentials.username, credentials.password, saveAccount); } }; const isDisabled = disabled || loading; const handleBack = useCallback(() => { if (isDisabled) return false; onBack(); return true; }, [isDisabled, onBack]); useTVBackPress(() => handleBack(), [handleBack]); return ( {/* Title */} {serverName ? ( <> {`${t("login.login_to_title")} `} {serverName} ) : ( t("login.login_title") )} {serverAddress} {/* Username Input */} setCredentials((prev) => ({ ...prev, username: text })) } autoCapitalize='none' autoCorrect={false} textContentType='username' returnKeyType='next' hasTVPreferredFocus disabled={isDisabled} /> {/* Password Input */} setCredentials((prev) => ({ ...prev, password: text })) } secureTextEntry autoCapitalize='none' textContentType='password' returnKeyType='done' disabled={isDisabled} /> {/* Save Account Toggle */} {/* Login Button */} {/* Quick Connect Button */} ); };