package com.fastest.pass.forgotpassword.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.viewModels
import com.fastest.pass.BaseFragment
import com.fastest.pass.forgotpassword.presentation.ui.components.ClickType
import com.fastest.pass.forgotpassword.presentation.ui.components.ForgotPasswordScreen
import com.fastest.pass.forgotpassword.presentation.viewmodels.ForgotPasswordViewmodel
import com.fastest.pass.forgotpassword.utils.ForgotPasswordNavigation
import com.fastest.pass.forgotpassword.utils.ForgotPasswordRoute
import com.fastest.pass.ui.theme.FastestPassTheme
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class ForgotPasswordFragment : BaseFragment() {

    val viewmodel: ForgotPasswordViewmodel by viewModels()

    @Inject
    lateinit var navigation: ForgotPasswordNavigation

    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 {
                    ForgotPasswordScreen { clickType ->
                        when (clickType) {
                            ClickType.GO_BACK -> {
                                viewmodel.navigateTo(ForgotPasswordRoute.GoBackToLogin)
                            }

                            ClickType.OPEN_FORGOT_VERIFY -> {
                                viewmodel.navigateTo(ForgotPasswordRoute.OpenForgotVerifyScreen)
                            }
                        }
                    }
                }
            }
        }
    }
}