package com.syaroful.agrilinkvocpro.presentation.screen.register

import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.syaroful.agrilinkvocpro.R
import com.syaroful.agrilinkvocpro.core.components.AppButton
import com.syaroful.agrilinkvocpro.core.components.AppPasswordField
import com.syaroful.agrilinkvocpro.core.components.AppTextField
import com.syaroful.agrilinkvocpro.core.components.textTheme
import com.syaroful.agrilinkvocpro.presentation.theme.DarkGrey
import com.syaroful.agrilinkvocpro.presentation.theme.MainGreen

@Composable
fun RegisterScreen(
    onLoginSuccess: () -> Unit,
    onNavigateToLogin: () -> Unit,
) {

    var name by remember { mutableStateOf("") }
    var email by remember { mutableStateOf("") }
    var username by remember { mutableStateOf("") }
    var password by remember { mutableStateOf("") }
    var phone by remember { mutableStateOf("") }

    Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
        Column(
            modifier = Modifier
                .verticalScroll(rememberScrollState())
                .fillMaxWidth()
                .padding(innerPadding)
                .imePadding(),
            verticalArrangement = Arrangement.spacedBy(16.dp)
        ) {
            Image(
                painter = painterResource(id = R.drawable.greenhouse_banner),
                contentDescription = "Banner",
                modifier = Modifier
                    .height(180.dp)
                    .align(Alignment.CenterHorizontally),
                contentScale = ContentScale.Crop
            )
            Text(
                modifier = Modifier.fillMaxWidth(),
                text = "Login", style = textTheme.titleMedium, textAlign = TextAlign.Center
            )
            Text(
                modifier = Modifier.fillMaxWidth(),
                text = "Halo! yuk masuk ke dalam akunmu",
                style = textTheme.titleSmall.copy(color = DarkGrey),
                textAlign = TextAlign.Center
            )
            AppTextField(
                hint = "Name",
                keyboardType = KeyboardType.Email,
                leadingIcon = painterResource(
                    R.drawable.solar_user_circle
                ),
                value = name,
                onValueChange = { name = it }
            )
            AppTextField(
                hint = "Username",
                keyboardType = KeyboardType.Email,
                leadingIcon = painterResource(
                    R.drawable.solar_user
                ),
                value = username,
                onValueChange = { username = it }
            )
            AppTextField(
                hint = "Email",
                keyboardType = KeyboardType.Email,
                leadingIcon = painterResource(
                    R.drawable.icon_email
                ),
                value = email,
                onValueChange = { email = it }
            )
            AppPasswordField(
                hint = "Password",
                keyboardType = KeyboardType.Password,
                value = password,
                onValueChange = { password = it }
            )

            AppButton(
                label = "Daftar",
            ) {
            }

            Row(
                modifier = Modifier.fillMaxWidth(),
                horizontalArrangement = Arrangement.Center
            ) {
                Text(
                    text = "Sudah punya akun? ",
                    style = textTheme.titleSmall.copy(color = DarkGrey),
                    textAlign = TextAlign.Center
                )
                Text(
                    modifier = Modifier.clickable { onNavigateToLogin() },
                    text = "Masuk",
                    style = textTheme.titleSmall.copy(color = MainGreen),
                    textAlign = TextAlign.Center
                )
            }
        }
    }
}