package com.example.wabi.view.screeens.profile

import android.os.Build
import androidx.annotation.RequiresApi
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import com.example.wabi.view.screeens.profile.items.ProfileCurrentUser
import com.example.wabi.view.screeens.profile.items.ProfileStateDestinations
import com.example.wabi.view.screeens.profile.items.UpdateProfile

@RequiresApi(Build.VERSION_CODES.O)
@Composable
fun Profile(navHostController: NavHostController, vm: ProfileViewModel = hiltViewModel()) {
    val profileState = remember { mutableIntStateOf(ProfileStateDestinations.profile) }

    vm.getUser()

    Column(
        modifier = Modifier
            .fillMaxSize()
            .verticalScroll(rememberScrollState()),
    ) {
        when (profileState.intValue) {
            ProfileStateDestinations.profile -> {
                ProfileCurrentUser(
                    navHostController = navHostController,
                    vm = vm,
                    stateChanger = profileState,
                    modifier = Modifier.weight(1f)
                )
            }

            ProfileStateDestinations.update -> {
                UpdateProfile(
                    navHostController = navHostController,
                    vm = vm,
                    stateChanger = profileState,
                    modifier = Modifier.weight(1f)
                )
            }
        }
    }
}