import React, { FC, useMemo, useState } from 'react' import { Alert, Image, Modal, Text, TouchableOpacity, View } from 'react-native' import { useDebounced } from '../../helpers/Debounced' import { validateEmail, validateMinLength } from '../../helpers/Validators' import R from '../../res' import Button from '../button/Button' import RestorePassword from '../restorePassword/RestorePassword' import ResultDialog from '../restorePassword/ResultDialog' import LoginForm from './components/LoginForm' import s from './styles' import { ILoginViewProps, ILoginViewState } from './types' const initialState: ILoginViewState = { loginEmail: '', loginPassword: '', } const LoginView: FC = ({ showDialog, hideDialog, isDialogVisible, onPressLogin, isLoading, onPressLogout, styles, texts, userFirstName, loginApiError, brandImages, isShowPasswordButtonVisible, content, onPressForgotPassword, restorePasswordProps, resultDialogPropsProps, }) => { const [data, setData] = useState(initialState) const { loginEmail, loginPassword } = data const loginEmailError = useDebounced(loginEmail, validateEmail) const loginPasswordError = useDebounced(loginPassword, (value: string) => validateMinLength(value, 6, 'Password') ) const handleOnPressLogin = () => { onPressLogin({ email: loginEmail, password: loginPassword, }) } const logoutTitle = texts?.logoutDialog?.title ? texts.logoutDialog.title : 'Are you sure that you want to logout?' const logoutMessage = texts?.logoutDialog?.message ? texts.logoutDialog.message : 'You will need to enter your login data again to place the order.' const logoutConfirm = texts?.logoutDialog?.confirm ? texts.logoutDialog.confirm : 'Yes, logout' const logoutCancel = texts?.logoutDialog?.cancel ? texts.logoutDialog.cancel : 'No' const line1 = texts?.line1 || 'Got a TICKETFAIRY account?' const line2 = texts?.line2 || 'Login & skip ahead:' const handleLogout = () => { setData(initialState) if (onPressLogout) { onPressLogout() } } const checkIsLoginDataValid = (): boolean => { if (loginEmailError) { return false } if (loginPasswordError) { return false } return true } const LoggedComponent = () => ( {texts?.loggedIn?.loggedAs || 'Logged in as:'}{' '} {userFirstName} {texts?.loggedIn?.notYou || 'Not you?'}