package com.example.shawarma.screens.authorization

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Card
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex
import androidx.navigation.NavHostController
import com.example.shawarma.ui.theme.JejuFamily
import com.example.shawarma.ui.theme.MyLightRed
import com.example.shawarma.utils.ScreenPaths
import com.example.shawarma.widgets.MyTextField
import com.example.shawarma.widgets.ShawarmaLogo1

@Composable
fun AuthorizationScreen(navHostController: NavHostController) {
    Box(contentAlignment = Alignment.TopCenter){
        ShawarmaLogo1()
        AuthorizationCard(navHostController)
    }
}

@Composable
fun AuthorizationCard(navHostController: NavHostController) {
    val login = remember { mutableStateOf(TextFieldValue("")) }
    val password = remember { mutableStateOf(TextFieldValue("")) }

    Column(
        horizontalAlignment = Alignment.CenterHorizontally,
        modifier = Modifier
            .zIndex(2f)
            .verticalScroll(rememberScrollState())
            .imePadding()
            .padding(10.dp)
            .fillMaxHeight()
    ) {
        Card(
            shape = RoundedCornerShape(20.dp),
            modifier = Modifier
                .size(275.dp, 290.dp + 72.dp)
                .padding(top = 72.dp)
        ) {
            Column(
                horizontalAlignment = Alignment.CenterHorizontally
            ) {
                Text(
                    text = "Авторизация",
                    fontSize = 20.sp,
                    modifier = Modifier.padding(
                        top = 20.dp
                    ),
                    style = TextStyle(
                        fontFamily = JejuFamily
                    )
                )
                MyTextField(
                    text = login,
                    onTextChanged = {login.value = it},
                    modifier = Modifier
                        .padding(
                            top = (20).dp
                        )
                        .size(208.dp, (50).dp),
                    placeholder = "Логин",
                    singleLine = true
                )
                MyTextField(
                    text = password,
                    onTextChanged = {password.value = it},
                    modifier = Modifier
                        .padding(
                            top = (20).dp
                        )
                        .size(208.dp, (50).dp),
                    placeholder = "Пароль",
                    singleLine = true
                )
                Button(
                    onClick = {
                        navHostController.navigate(ScreenPaths.home.name) {
                            popUpTo(ScreenPaths.authorization.name) {
                                inclusive = true
                            }
                        } },
                    colors = ButtonDefaults.buttonColors(MyLightRed, Color.White),
                    shape = RoundedCornerShape(20.dp),
                    modifier = Modifier
                        .padding(
                            top = (20).dp
                        )
                        .size(208.dp, (50).dp)
                ) {
                    Text(
                        text = "Войти",
                        style = TextStyle(
                            fontFamily = JejuFamily,
                            fontSize = 16.sp
                        )
                    )
                }
                Button(
                    onClick = {
                              navHostController.navigate(ScreenPaths.registration.name) {
                                  popUpTo(ScreenPaths.registration.name) {
                                      inclusive = true
                                  }
                              }
                    },
                    colors = ButtonDefaults.buttonColors(Color.White),
                    elevation = ButtonDefaults.elevation(0.dp)
                ) {
                    Text(
                        text = "У меня нет аккаунта!",
                        textDecoration = TextDecoration.Underline,
                        style = TextStyle(
                            fontFamily = JejuFamily,
                            fontSize = 12.sp
                        )
                    )
                }
            }
        }
    }
}