package com.fastest.pass.home.presentation.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
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.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
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.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.fastest.pass.R
import com.fastest.pass.home.domain.model.AddNewItem
import com.fastest.pass.login.presentation.ui.components.ClickType

enum class ClickTypeAddNewItem {
    GOTO_HOME,
    Password,
    Bank,
    Payment,
    Wifi,
    Note,
    Contact,
    Driver,
    Passport
}

@Composable
fun AddNewItemsScreen(clickType: (ClickTypeAddNewItem) -> Unit) {
    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(top = 0.dp)
            .statusBarsPadding()
//            .navigationBarsPadding()
            .background(colorResource(id = R.color.white))
    ) {
        Row(
            modifier = Modifier
                .fillMaxWidth()
                .height(25.dp)
                .background(colorResource(id = R.color.blue_login))
        ) { }

        Spacer(modifier = Modifier.height(20.dp))
        ShowAddNewItemsHeader(text = stringResource(id = R.string.add_new_items)) { clickTypeAddNewItem ->
            clickType(clickTypeAddNewItem)
        }
        Spacer(modifier = Modifier.height(20.dp))
        GapLineANI()
//        Spacer(modifier = Modifier.height(0.dp))
        AddNewItemList() { itemName ->
            clickType(itemName)
        }
    }
}

@Composable
fun ColumnScope.ShowAddNewItemsHeader(text: String, clickType: (ClickTypeAddNewItem) -> Unit) {
    Row(
        modifier = Modifier
            .align(Alignment.Start)
            .fillMaxWidth(),
        verticalAlignment = Alignment.CenterVertically,
    ) {
        IconButton(
            onClick = {
                clickType.invoke(ClickTypeAddNewItem.GOTO_HOME)
            },
            modifier = Modifier
                .padding(start = 30.dp)
                .size(24.dp, 24.dp)
        ) {
            Image(
                painter = painterResource(id = R.drawable.arrow_left),
                contentDescription = "Arrow-Back",
                modifier = Modifier.size(24.dp, 24.dp),
                colorFilter = ColorFilter.tint(
                    color = colorResource(id = R.color.gray_splash)
                )
            )
        }
        Surface(
            modifier = Modifier
                .padding(start = 15.dp),
            color = colorResource(id = R.color.transparent)
        ) {
            Text(
                text = text,
                color = colorResource(id = R.color.gray_splash),
                style = MaterialTheme.typography.displayLarge.copy(
                    fontSize = 24.sp
                ),
            )
        }
    }
}

@Composable
fun GapLineANI() {
    Surface(
        modifier = Modifier
            .height(1.dp)
            .fillMaxWidth()
            .alpha(1F),
        color = colorResource(id = R.color.light_gray_login)
    ) {}
}

@Composable
fun AddNewItemList(clickType: (ClickTypeAddNewItem) -> Unit) {
    val itemList by remember {
        mutableStateOf(
            listOf(
                AddNewItem("Password","Passwords", R.drawable.password_lock),
                AddNewItem("Bank","Bank Account", R.drawable.bank),
                AddNewItem("Payment","Payment Card", R.drawable.cards),
                AddNewItem("Wifi","Wi-Fi Password", R.drawable.wifi),
                AddNewItem("Note","Secure Note", R.drawable.secure_note),
                AddNewItem("Contact","Contact Info", R.drawable.contact_info),
                AddNewItem("Driver","Driver's License", R.drawable.driver_license),
                AddNewItem("Passport","Passport", R.drawable.passport),
            )
        )
    }

    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(horizontal = 30.dp)
            .padding(vertical = 15.dp)
            .background(Color.Transparent)
    ) {
        LazyColumn(
            contentPadding = PaddingValues(top = 0.dp)
        ) {
            items(itemList, itemContent = { item ->
                AddNewItemRow(item = item) {
                    clickType(it)
                }
            })
        }

//        LazyVerticalGrid(
//            columns = GridCells.Fixed(3),
//            modifier = Modifier.weight(1F),
//            contentPadding = PaddingValues(6.dp)
//        ) {
//            items(itemList) { item ->
//                AddNewItemCard(item = item) { itemName ->
//                    clickType(itemName)
//                }
//            }
//        }
    }

}

//                AddNewItem("Email Account", R.drawable.email_account),
//                AddNewItem("Social Security Number", R.drawable.social_security_num),
//                AddNewItem("Address", R.drawable.address),
//                AddNewItem("Database", R.drawable.database),
//                AddNewItem("Server", R.drawable.server),
//                AddNewItem("Software License", R.drawable.software_license),
//                AddNewItem("Membership", R.drawable.membership),
//                AddNewItem("Health Insurance", R.drawable.health_insurance),
//                AddNewItem("Insurance Policy", R.drawable.insurance_policy),
//                AddNewItem("Instant Messenger", R.drawable.messenger),
//                AddNewItem("SSH Key", R.drawable.ssh_key),
//                AddNewItem("Folders", R.drawable.folders),