package com.example.what_the_fantasy.ui.screens

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.what_the_fantasy.R
import com.example.what_the_fantasy.data.services.IServices
import com.example.what_the_fantasy.ui.components.NavBar
import com.example.what_the_fantasy.ui.components.QuoteLittle
import com.example.what_the_fantasy.ui.states.CurrentUserState
import com.example.what_the_fantasy.ui.theme.colorBackground
import com.example.what_the_fantasy.ui.viewModels.CurrentUserViewModel

@Composable
fun FavoritePage(
    navAccueil: () -> Unit,
    navQuiz: () -> Unit,
    navProfil: () -> Unit,
    navQuote: (Int) -> Unit,
    navSearch: () -> Unit,
    services: IServices,
    currentUserVM : CurrentUserViewModel,
    currentUserState : CurrentUserState,
) {
    val user = services.getUserById(currentUserState.id) ?: return

    val quotes = services.getFavorite(user)

    val titlePage = stringResource(R.string.TitleFavorite)
    NavBar(onFavorite = true,
        currentUserVM = currentUserVM,
        currentUserState = currentUserState,
        navControllerFavorite = {  },
        navControllerAccueil = navAccueil,
        navControllerProfil = navProfil,
        navControllerQuiz = navQuiz,
        navControllerSearch = navSearch
    ) {
        Box(
            modifier = Modifier
                .fillMaxSize()
                .background(MaterialTheme.colorScheme.background),
            contentAlignment = Alignment.TopCenter
        ) {
            LazyColumn {
                item {
                    Text(
                        text = titlePage,
                        color = MaterialTheme.colorScheme.onBackground,
                        fontSize = 24.sp,
                        modifier = Modifier
                            .fillMaxWidth()
                            .padding(16.dp),
                        textAlign = TextAlign.Center
                    )
                }
                items(quotes) { quote ->
                    Column(Modifier.clickable { navQuote(quote.id) }) {
                        QuoteLittle(quote)
                        Spacer(modifier = Modifier.height(16.dp))
                    }
                }
            }
        }
    }
}