import { Ionicons } from "@expo/vector-icons"; import { t } from "i18next"; import React, { useRef, useState } from "react"; import { Animated, Easing, Pressable, ScrollView, View } from "react-native"; import { Button } from "@/components/Button"; import { Text } from "@/components/common/Text"; import { useScaledTVTypography } from "@/constants/TVTypography"; 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; } const TVBackButton: React.FC<{ onPress: () => void; label: string; disabled?: boolean; }> = ({ onPress, label, disabled = false }) => { const [isFocused, setIsFocused] = useState(false); const scale = useRef(new Animated.Value(1)).current; const animateFocus = (focused: boolean) => { Animated.timing(scale, { toValue: focused ? 1.05 : 1, duration: 150, easing: Easing.out(Easing.quad), useNativeDriver: true, }).start(); }; return ( { setIsFocused(true); animateFocus(true); }} onBlur={() => { setIsFocused(false); animateFocus(false); }} style={{ alignSelf: "flex-start", marginBottom: 40 }} disabled={disabled} focusable={!disabled} > {label} ); }; 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; return ( {/* Back Button */} {/* 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 */} ); };