package com.example.exvesta.Screans

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldDefaults
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.draw.clip
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color

import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController

import com.example.exvesta.R
import com.example.exvesta.Screans.Responses.Auth

@Composable
fun Registration(navHost: NavHostController) {
    val viewModel = Auth()
    val email = remember { mutableStateOf("") }
    val login = remember { mutableStateOf("") }
    val password = remember { mutableStateOf("")}
    val gradientButton = Brush.linearGradient(
        colors = listOf(
            Color(0xFF6F4A48),
            Color(0xFFC09F9C)
        ),

        start =  Offset(30.0f, 50.0f),
        end =  Offset(200.0f, 50.0f)
    );



    Column(
        modifier = Modifier
            .fillMaxSize()
            .background(Color.White),
//        verticalArrangement = Arrangement.Center,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {

        Spacer(modifier = Modifier.height(100.dp))
        Image(
            painter = painterResource(id = R.drawable.back),
            contentDescription = "Background Image",
            modifier = Modifier
                .fillMaxWidth()
                .height(350.dp)
                .clip(RoundedCornerShape(16.dp))
        )
        Text(
            text = "Добро пожаловать в  ваш личный гардероб exvesta",
            fontSize = 12.sp,
            color = Color(0xFF92A2B0)
        )
        Spacer(modifier = Modifier.height(16.dp))
        OutlinedTextField(
            value = login.value,
            onValueChange = { login.value = it },
            label = { Text("Логин", color = Color(0xFFB9A791)) },
            modifier = Modifier
                .width(350.dp)
                .height(50.dp)
            ,
            colors = TextFieldDefaults.colors(
                unfocusedContainerColor =  Color(0xFFFEFAF3),
                focusedContainerColor = Color(0xFFFFFFFF),
                unfocusedIndicatorColor = Color(0xFFB9A791),
                focusedIndicatorColor = Color(0xFFA18B72),

                ),
            shape = RoundedCornerShape(30.dp)

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

        OutlinedTextField(
            value = password.value,
            onValueChange = { password.value = it },
            label = { Text("Пароль", color = Color(0xFFB9A791)) },
            modifier = Modifier

                .width(350.dp)
                .height(50.dp)


            ,
            colors = TextFieldDefaults.colors(
                unfocusedContainerColor =  Color(0xFFFEFAF3),
                focusedContainerColor = Color(0xFFFFFFFF),
                unfocusedIndicatorColor = Color(0xFFB9A791),
                focusedIndicatorColor = Color(0xFFA18B72),
            ),
            shape = RoundedCornerShape(30.dp)

        )
        Spacer(modifier = Modifier.height(16.dp))
        OutlinedTextField(
            value = email.value,
            onValueChange = { email.value = it },
            label = { Text("почта@mail.com", color = Color(0xFFB9A791)) },
            modifier = Modifier

                .width(350.dp)
                .height(50.dp)


            ,
            colors = TextFieldDefaults.colors(
                unfocusedContainerColor =  Color(0xFFFEFAF3),
                focusedContainerColor = Color(0xFFFFFFFF),
                unfocusedIndicatorColor = Color(0xFFB9A791),
                focusedIndicatorColor = Color(0xFFA18B72),
            ),
            shape = RoundedCornerShape(30.dp)

        )
        Spacer(modifier = Modifier.height(30.dp))
        Button(
            onClick = { viewModel.onSignUpEmail(email.value, password.value, login.value, navHost) },
            modifier = Modifier
                .width(370.dp)
                .height(60.dp)
                .padding(horizontal = 20.dp)
                .background(
                    brush = Brush.horizontalGradient(
                        colors = listOf(
                            Color(0xFF6F4A48),
                            Color(0xFFE7D2A9),
                        )
                    ), shape = ButtonDefaults.shape
                )
                .height(ButtonDefaults.MinHeight),

            colors = ButtonDefaults.buttonColors(containerColor = Color.Transparent)
        ) {
            Text(
                text = "зарегистрироваться",
                fontSize = 16.sp,
                fontWeight = FontWeight.Medium
            )
        }
        Spacer(modifier = Modifier.height(16.dp))


    }
}