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 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.material.Text
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.browse.presentation.ui.components.BrowseScreen
import com.fastest.pass.browse.presentation.ui.components.ClickTypeItemBrowse
import com.fastest.pass.browse.presentation.viewmodels.BrowseViewModel
import com.fastest.pass.browse.utils.BrowseNavigation
import com.fastest.pass.browse.utils.BrowseRoute
import com.fastest.pass.ui.theme.FastestPassTheme
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class BrowseFragment : BaseFragment() {

    val viewmodel: BrowseViewModel by activityViewModels()

    @Inject
    lateinit var navigation: BrowseNavigation

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

    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.home_background_color))
                                .padding(paddingValues.calculateBottomPadding())
                        ) {
                            BrowseScreen { clickTypeItemBrowse ->
                                Log.d("screenNameBrowse", "clickTypeItemBrowseBF = ${clickTypeItemBrowse.name} ,,")

                                when (clickTypeItemBrowse) {
                                    ClickTypeItemBrowse.Password -> {
                                        viewmodel.navigateToItemScreen(clickTypeItemBrowse)
                                        viewmodel.navigateTo(BrowseRoute.OpenNewItemBrowseScreen)
                                    }
                                    ClickTypeItemBrowse.Bank -> {
                                        viewmodel.navigateToItemScreen(clickTypeItemBrowse)
                                        viewmodel.navigateTo(BrowseRoute.OpenNewItemBrowseScreen)
                                    }
                                    ClickTypeItemBrowse.Payment -> {
                                        viewmodel.navigateToItemScreen(clickTypeItemBrowse)
                                        viewmodel.navigateTo(BrowseRoute.OpenNewItemBrowseScreen)
                                    }
                                    ClickTypeItemBrowse.Wifi -> {
                                        viewmodel.navigateToItemScreen(clickTypeItemBrowse)
                                        viewmodel.navigateTo(BrowseRoute.OpenNewItemBrowseScreen)
                                    }
                                    ClickTypeItemBrowse.Note -> {
                                        viewmodel.navigateToItemScreen(clickTypeItemBrowse)
                                        viewmodel.navigateTo(BrowseRoute.OpenNewItemBrowseScreen)
                                    }
                                    ClickTypeItemBrowse.Contact -> {
                                        viewmodel.navigateToItemScreen(clickTypeItemBrowse)
                                        viewmodel.navigateTo(BrowseRoute.OpenNewItemBrowseScreen)
                                    }
                                    ClickTypeItemBrowse.Driver -> {
                                        viewmodel.navigateToItemScreen(clickTypeItemBrowse)
                                        viewmodel.navigateTo(BrowseRoute.OpenNewItemBrowseScreen)
                                    }
                                    ClickTypeItemBrowse.Passport -> {
                                        viewmodel.navigateToItemScreen(clickTypeItemBrowse)
                                        viewmodel.navigateTo(BrowseRoute.OpenNewItemBrowseScreen)
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}