package com.example.wabi.view.screeens.logIn.items.signUpItems

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.example.wabi.view.components.buttons.MainButton
import com.example.wabi.view.components.textFields.MainTextField
import com.example.wabi.view.components.textFields.PasswordTextField
import com.example.wabi.view.components.texts.Error.ErrorList
import com.example.wabi.view.components.texts.Error.ErrorPrint
import com.example.wabi.view.components.texts.HeaderText
import com.example.wabi.view.components.texts.MainText
import com.example.wabi.view.screeens.logIn.LogInViewModel

@Composable
fun EmailAndPassword(
    station: SingUpDestinations,
    modifier: Modifier = Modifier,
    vm: LogInViewModel,
    stationChanger: MutableState<Int>
) {
    val errorState = remember { mutableIntStateOf(0) }
    val data = vm.signUpData

    HeaderText(text = station.header)

    MainText(
        text = station.description
    )

    ErrorPrint(
        text = when (errorState.intValue) {
            1 -> ErrorList.existAccountWithEmail
            2 -> ErrorList.passwordNoCorrect
            3 -> ErrorList.passDontMatch
            4 -> ErrorList.emptyData
            else -> ""
        }
    )

    Column(
        modifier = Modifier.fillMaxWidth()
    ) {
        MainTextField(
            value = data.email,
            input = { vm.updateDataSignUp(data.copy(email = it)) },
            placeholder = "Почта",
            lable = "Введите почту:",
            trailingText = ""
        )
        Spacer(modifier = Modifier.height(10.dp))
        PasswordTextField(
            value = data.passwordOne,
            input = { vm.updateDataSignUp(data.copy(passwordOne = it)) },
            placeholder = "Пароль",
            lable = "Введите пароль:"
        )
        Spacer(modifier = Modifier.height(10.dp))
        PasswordTextField(
            value = data.passwordTwo,
            input = { vm.updateDataSignUp(data.copy(passwordTwo = it)) },
            placeholder = "Пароль",
            lable = "Повторите пароль:"
        )
    }

    MainButton(
        onClick = {
            vm.switchSignUpStation(printError = errorState, stationChanger = stationChanger)
        }, enabled = data.passwordOne != "" && data.passwordTwo != "" && vm.validateEmail(
            data.email
        ), textContent = station.buttonName, modifier = Modifier.fillMaxWidth(0.82f)
    )
}