Загрузка данных


// ==== ВСТАВЬ ЭТОТ БЛОК В САМЫЙ НИЗ ТВОЕГО ФАЙЛА MAINACTION.KT ====

@Composable
fun ProfileScreen(onBackClick: () -> Unit) {
    // Переменные для переключения режимов и хранения текста
    var isLoginMode by remember { mutableStateOf(true) } // true = Вход, false = Регистрация
    var registeredName by remember { mutableStateOf("") }
    var showJokeDialog by remember { mutableStateOf(false) }

    // Поля ввода
    var nameInput by remember { mutableStateOf("") }
    var emailInput by remember { mutableStateOf("") }
    var passwordInput by remember { mutableStateOf("") }
    var confirmPasswordInput by remember { mutableStateOf("") }

    Box(modifier = Modifier.fillMaxSize()) {
        
        // Кнопка НАЗАД в левом верхнем углу
        Button(
            onClick = { onBackClick() },
            modifier = Modifier
                .align(Alignment.TopStart)
                .padding(16.dp)
        ) {
            Text("Назад в чат")
        }

        // Текст переключения в правом верхнем углу
        Column(
            modifier = Modifier
                .align(Alignment.TopEnd)
                .padding(16.dp),
            horizontalAlignment = Alignment.End
        ) {
            if (isLoginMode) {
                Text("Впервые и не имеете аккаунта?")
                TextButton(onClick = { isLoginMode = false }) {
                    Text("Зарегистрируйтесь!")
                }
            } else {
                Text("Уже имеете аккаунт?")
                TextButton(onClick = { isLoginMode = true }) {
                    Text("Войдите!")
                }
            }
        }

        // Центральная часть с приветствием и полями ввода
        Column(
            modifier = Modifier
                .fillMaxSize()
                .padding(top = 120.dp, start = 16.dp, end = 16.dp),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            // Логика приветствия: если зарегистрировался — подставит имя
            val greeting = if (registeredName.isNotEmpty()) {
                "Здравствуйте, $registeredName!"
            } else {
                "Здравствуйте!\nЯ рад Вас снова видеть!"
            }
            
            Text(
                text = greeting,
                style = MaterialTheme.typography.headlineMedium,
                textAlign = TextAlign.Center
            )

            Spacer(modifier = Modifier.height(32.dp))

            if (isLoginMode) {
                // ПОЛЯ ДЛЯ ОKНА ВХОДА
                OutlinedTextField(
                    value = emailInput,
                    onValueChange = { emailInput = it },
                    label = { Text("Почта") },
                    singleLine = true
                )
                Spacer(modifier = Modifier.height(8.dp))
                OutlinedTextField(
                    value = passwordInput,
                    onValueChange = { passwordInput = it },
                    label = { Text("Пароль") },
                    singleLine = true,
                    visualTransformation = PasswordVisualTransformation()
                )
                Spacer(modifier = Modifier.height(16.dp))
                Button(onClick = { 
                    // Здесь в будущем сделаем проверку входа
                }) { 
                    Text("Войти") 
                }
                Spacer(modifier = Modifier.height(8.dp))
                TextButton(onClick = { showJokeDialog = true }) { 
                    Text("Забыли пароль?") 
                }
            } else {
                // ПОЛЯ ДЛЯ ОКНА РЕГИСТРАЦИИ
                OutlinedTextField(
                    value = nameInput,
                    onValueChange = { nameInput = it },
                    label = { Text("Имя") },
                    singleLine = true
                )
                Spacer(modifier = Modifier.height(8.dp))
                OutlinedTextField(
                    value = emailInput,
                    onValueChange = { emailInput = it },
                    label = { Text("Почта") },
                    singleLine = true
                )
                Spacer(modifier = Modifier.height(8.dp))
                OutlinedTextField(
                    value = passwordInput,
                    onValueChange = { passwordInput = it },
                    label = { Text("Пароль") },
                    singleLine = true,
                    visualTransformation = PasswordVisualTransformation()
                )
                Spacer(modifier = Modifier.height(8.dp))
                OutlinedTextField(
                    value = confirmPasswordInput,
                    onValueChange = { confirmPasswordInput = it },
                    label = { Text("Подтвердить пароль") },
                    singleLine = true,
                    visualTransformation = PasswordVisualTransformation()
                )
                Spacer(modifier = Modifier.height(16.dp))
                Button(onClick = {
                    // Сохраняем введенное имя и перекидываем на экран Входа
                    registeredName = nameInput
                    isLoginMode = true 
                }) { 
                    Text("Зарегистрироваться") 
                }
            }
        }

        // Тот самый пранк с забытым паролем
        if (showJokeDialog) {
            AlertDialog(
                onDismissRequest = { showJokeDialog = false },
                title = { Text("Восстановление") },
                text = { Text("Хохохохохохо, ну ты и лох") },
                confirmButton = {
                    Button(onClick = { showJokeDialog = false }) {
                        Text("Понял")
                    }
                }
            )
        }
    }
}