package com.syaroful.agrilinkvocpro.ui.pages

import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Arrangement
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.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
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.tooling.preview.Preview
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.ui.theme.AgrilinkVocproTheme
import com.syaroful.agrilinkvocpro.ui.theme.DarkGrey
import com.syaroful.agrilinkvocpro.ui.theme.MainGreen


@Composable
fun LoginScreen() {
    Scaffold(modifier = Modifier.fillMaxSize()) { paddingValues ->

        Column(
            modifier = Modifier
                .fillMaxWidth()
                .padding(paddingValues)
        ) {
            Image(
                painter = painterResource(id = R.drawable.greenhouse_banner),
                contentDescription = "Banner",
                modifier = Modifier
                    .height(180.dp)
                    .align(Alignment.CenterHorizontally),
                contentScale = ContentScale.Crop
            )
            Spacer(modifier = Modifier.height(16.dp))
            Text(
                modifier = Modifier.fillMaxWidth(),
                text = "Login", style = textTheme.titleMedium, textAlign = TextAlign.Center
            )
            Spacer(modifier = Modifier.height(16.dp))
            Text(
                modifier = Modifier.fillMaxWidth(),
                text = "Halo! yuk masuk ke dalam akunmu",
                style = textTheme.titleSmall.copy(color = DarkGrey),
                textAlign = TextAlign.Center
            )
            Spacer(modifier = Modifier.height(16.dp))
            AppTextField(
                hint = "Username", keyboardType = KeyboardType.Email, leadingIcon = painterResource(
                    R.drawable.icon_email
                )
            )
            AppPasswordField(
                hint = "Password",
                keyboardType = KeyboardType.Password
            )
            AppButton(
                label = "Login"
            ) { }
            Spacer(modifier = Modifier.height(16.dp))
            Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
                Text(
                    text = "Belum punya akun? ",
                    style = textTheme.titleSmall.copy(color = DarkGrey),
                    textAlign = TextAlign.Center
                )
                Text(
                    text = "Daftar disini",
                    style = textTheme.titleSmall.copy(color = MainGreen),
                    textAlign = TextAlign.Center
                )
            }
        }

    }
}

@Preview(showBackground = true, name = "Light Mode")
@Preview(showBackground = true, name = "Dark Mode", uiMode = UI_MODE_NIGHT_YES)
@Composable
fun LoginScreenPreview() {
    AgrilinkVocproTheme {
        LoginScreen()
    }
}
