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

import android.os.Bundle
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.material3.Scaffold
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.res.colorResource
import androidx.fragment.app.viewModels
import com.fastest.pass.BaseFragment
import com.fastest.pass.R
import com.fastest.pass.ui.theme.FastestPassTheme
import com.fastest.pass.welcome.presentation.ui.component.ClickType.LOGIN_CLICK
import com.fastest.pass.welcome.presentation.ui.component.ClickType.SIGNUP_CLICK
import com.fastest.pass.welcome.presentation.ui.component.WelcomeTutorial
import com.fastest.pass.welcome.presentation.viewmodel.WelcomeViewModel
import com.fastest.pass.welcome.utils.WelcomeNavigation
import com.fastest.pass.welcome.utils.WelcomeNavigationRoute
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class WelcomeFragment : BaseFragment() {

    val viewModel: WelcomeViewModel by viewModels()

    @Inject
    lateinit var navigation: WelcomeNavigation

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

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        return ComposeView(requireActivity()).apply {
            setContent {
                FastestPassTheme {
                    Scaffold(
                        modifier = Modifier.fillMaxSize(),
                        ) { paddingValues ->
                        // Make sure to use paddingValues to ensure content does not overlap with system bottom navigation bar
                        Box(
                            modifier = Modifier
                                .fillMaxSize()
                                .background(color = colorResource(id = R.color.light_gray_login))
                                .padding(bottom = paddingValues.calculateBottomPadding()) // Apply padding to respect system bottom inset
                        ) {
                            // Your main content goes here
                            WelcomeTutorial { clickType ->

                                when (clickType) {
                                    LOGIN_CLICK -> {
                                        viewModel.navigateTo(WelcomeNavigationRoute.OpenLogin)
                                    }

                                    SIGNUP_CLICK -> {
                                        viewModel.navigateTo(WelcomeNavigationRoute.OpenSignup)
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}