package com.fastest.pass.masterlogin.presentation.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.fastest.pass.BaseFragment
import com.fastest.pass.masterlogin.presentation.ui.components.ClickType
import com.fastest.pass.masterlogin.presentation.ui.components.MasterLoginScreen
import com.fastest.pass.masterlogin.presentation.viewmodels.MasterLoginViewModel
import com.fastest.pass.masterlogin.utils.MasterLoginNavigation
import com.fastest.pass.masterlogin.utils.MasterLoginRoute
import com.fastest.pass.ui.theme.FastestPassTheme
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class MasterLoginFragment : BaseFragment() {

    val viewmodel: MasterLoginViewModel by viewModels()

    @Inject
    lateinit var navigation: MasterLoginNavigation

    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 {
                    MasterLoginScreen { clickType ->
                        when (clickType) {
                            ClickType.GO_BACK -> {
                                viewmodel.navigateTo(MasterLoginRoute.GoBackToLoginScreen)
                            }
                            ClickType.HOME_SCREEN -> {
                                viewmodel.navigateTo(MasterLoginRoute.OpenDashBoardScreen)
                            }
                        }
                    }
                }
            }
        }
    }
}