package com.example.shawarma.screens.registration

import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.FlingBehavior
import androidx.compose.foundation.gestures.ScrollScope
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.screens.authorization.AuthorizationCard
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 RegistrationScreen(navHostController: NavHostController) {
    Box(contentAlignment = Alignment.TopCenter){
        ShawarmaLogo1()
        RegistrationCard(navHostController)
    }
}

@Composable
fun RegistrationCard(navHostController: NavHostController){
    val login = remember { mutableStateOf(TextFieldValue("")) }
    val password = remember { mutableStateOf(TextFieldValue("")) }
    val passwordRepeat = 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, 380.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
                )
                MyTextField(
                    text = passwordRepeat,
                    onTextChanged = {passwordRepeat.value = it},
                    modifier = Modifier
                        .padding(
                            top = (20).dp
                        )
                        .size(208.dp, (50).dp),
                    placeholder = "Повторите пароль",
                    singleLine = true
                )
                Button(
                    onClick = {
                            // TODO
                    },
                    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.authorization.name) {
                            popUpTo(ScreenPaths.authorization.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
                        )
                    )
                }
            }
        }
    }
}