package com.fastest.pass.signup.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.signup.presentation.ui.components.ClickType
import com.fastest.pass.signup.presentation.ui.components.SignUpScreen
import com.fastest.pass.signup.presentation.viewmodels.SignUpViewModel
import com.fastest.pass.signup.utils.SignUpNavigation
import com.fastest.pass.signup.utils.SignUpRoute
import com.fastest.pass.ui.theme.FastestPassTheme
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class SignUpFragment : BaseFragment() {

    val viewmodel: SignUpViewModel by viewModels()

    @Inject
    lateinit var navigation: SignUpNavigation

    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 {
                    SignUpScreen { clickType ->
                        when (clickType) {
                            ClickType.GO_BACK -> {
                                viewmodel.navigateTo(SignUpRoute.GoBack)
                            }
                            ClickType.GO_TO_MASTER_SIGNUP -> {
                                viewmodel.navigateTo(SignUpRoute.OpenMasterSignupScreen)
                            }
                            ClickType.GO_TO_LOGIN -> {
                                viewmodel.navigateTo(SignUpRoute.OpenLoginScreen)
                            }
                        }
                    }
                }
            }
        }
    }
}