package com.syaroful.agrilinkvocpro.core.components

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextFieldDefaults
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.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.syaroful.agrilinkvocpro.R
import com.syaroful.agrilinkvocpro.ui.theme.DarkGrey
import com.syaroful.agrilinkvocpro.ui.theme.LightGrey
import com.syaroful.agrilinkvocpro.ui.theme.MainGreen


@Composable
fun AppPasswordField(
//    modifier: Modifier = Modifier,
    hint: String,
    keyboardType: KeyboardType
) {
    var text by remember { mutableStateOf("") }
    OutlinedTextField(
        value = text,
        onValueChange = { text = it },
        modifier = Modifier
            .fillMaxWidth()
            .padding(16.dp),
        leadingIcon = {
            Icon(
                painter = painterResource(R.drawable.ic_lock),
                tint = LightGrey,
                contentDescription = "Password Icon"
            )
        },
        trailingIcon = {
            Icon(
                painter = painterResource(R.drawable.ic_visible),
                contentDescription = "Visible Icon",
                tint = DarkGrey
            )
        },
        keyboardOptions = KeyboardOptions(
            keyboardType = keyboardType,
            imeAction = ImeAction.Done
        ),
        shape = RoundedCornerShape(8.dp),
        colors = TextFieldDefaults.colors(
            focusedContainerColor = Color.Transparent,
            unfocusedContainerColor = Color.Transparent,
            focusedIndicatorColor = MainGreen,
            unfocusedIndicatorColor = LightGrey
        ),
        singleLine = true,
        placeholder = {
            Text(
                hint,
                style = TextStyle(
                    color = LightGrey,
                    fontSize = 14.sp,
                )
            )
        }
    )
}

@Preview
@Composable

fun AppPasswordPreview() {
    AppPasswordField(
        hint = "Enter your password",
        keyboardType = KeyboardType.Password
    )
}