package com.fastest.pass.account.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.material.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.account.presentation.ui.components.AccountScreen
import com.fastest.pass.account.presentation.ui.components.ClickType
import com.fastest.pass.account.presentation.viewmodels.AccountViewModel
import com.fastest.pass.account.utils.AccountNavigation
import com.fastest.pass.account.utils.AccountRoute
import com.fastest.pass.ui.theme.FastestPassTheme
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class AccountFragment : BaseFragment() {

    val viewmodel: AccountViewModel by viewModels()

    @Inject
    lateinit var navigation: AccountNavigation

    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 {
                    Scaffold(
                        modifier = Modifier.fillMaxSize()
                    ) { paddingValues ->
                        Box(
                            modifier = Modifier
                                .fillMaxSize()
                                .background(colorResource(id = R.color.home_background_color))
                                .padding(paddingValues.calculateBottomPadding())
                        ) {
                            AccountScreen { clickType ->
                                when (clickType) {
                                    ClickType.OPEN_LOGIN_SCREEN -> {
                                        viewmodel.navigateTo(AccountRoute.OpenLoginScreen)
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}