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

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Scaffold
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.colorResource
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import com.fastest.pass.BaseFragment
import com.fastest.pass.R
import com.fastest.pass.home.presentation.ui.components.AddNewItemsScreen
import com.fastest.pass.home.presentation.ui.components.ClickTypeAddNewItem
import com.fastest.pass.home.presentation.viewmodels.AddNewItemsViewModel
import com.fastest.pass.home.utils.AddNewItemsNavigation
import com.fastest.pass.home.utils.AddNewItemsRoute
import com.fastest.pass.login.presentation.ui.components.LoginScreen
import com.fastest.pass.security.presentation.ui.components.SecurityScreen
import com.fastest.pass.ui.theme.FastestPassTheme
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import javax.inject.Inject

@AndroidEntryPoint
class AddNewItemsFragment : BaseFragment() {

    val viewmodel: AddNewItemsViewModel by activityViewModels()

    @Inject
    lateinit var navigation: AddNewItemsNavigation

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        navigation.navigate(this)
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        return ComposeView(requireActivity()).apply {
            setContent {
                FastestPassTheme {
                    Scaffold(
                        modifier = Modifier.fillMaxSize()
                    ) { paddingValues ->
                        Box(
                            modifier = Modifier
                                .fillMaxSize()
                                .background(colorResource(id = R.color.blue_login))
                                .padding(paddingValues.calculateBottomPadding())
                        ) {
                            AddNewItemsScreen(
                                clickType = { clickTypeAddNewItem ->
                                    when (clickTypeAddNewItem) {
                                        ClickTypeAddNewItem.GOTO_HOME -> {
                                            viewmodel.navigateTo(AddNewItemsRoute.Go_Back_Home)
                                        }
                                        ClickTypeAddNewItem.Password -> {
                                            viewmodel.navigateToItemScreen(clickTypeAddNewItem)
                                            viewmodel.navigateTo(AddNewItemsRoute.OpenNewItemFormScreen)
                                        }
                                        ClickTypeAddNewItem.Bank -> {
                                            viewmodel.navigateToItemScreen(clickTypeAddNewItem)
                                            viewmodel.navigateTo(AddNewItemsRoute.OpenNewItemFormScreen)
                                        }
                                        ClickTypeAddNewItem.Payment -> {
                                            viewmodel.navigateToItemScreen(clickTypeAddNewItem)
                                            viewmodel.navigateTo(AddNewItemsRoute.OpenNewItemFormScreen)
                                        }
                                        ClickTypeAddNewItem.Wifi -> {
                                            viewmodel.navigateToItemScreen(clickTypeAddNewItem)
                                            viewmodel.navigateTo(AddNewItemsRoute.OpenNewItemFormScreen)
                                        }
                                        ClickTypeAddNewItem.Note -> {
                                            viewmodel.navigateToItemScreen(clickTypeAddNewItem)
                                            viewmodel.navigateTo(AddNewItemsRoute.OpenNewItemFormScreen)
                                        }
                                        ClickTypeAddNewItem.Contact -> {
                                            viewmodel.navigateToItemScreen(clickTypeAddNewItem)
                                            viewmodel.navigateTo(AddNewItemsRoute.OpenNewItemFormScreen)
                                        }
                                        ClickTypeAddNewItem.Driver -> {
                                            viewmodel.navigateToItemScreen(clickTypeAddNewItem)
                                            viewmodel.navigateTo(AddNewItemsRoute.OpenNewItemFormScreen)
                                        }
                                        ClickTypeAddNewItem.Passport -> {
                                            viewmodel.navigateToItemScreen(clickTypeAddNewItem)
                                            viewmodel.navigateTo(AddNewItemsRoute.OpenNewItemFormScreen)
                                        }
                                    }
                            }
                            )
                        }
                    }
                }
            }
        }
    }
}