package com.pixelized.desktop.lwa.ui.screen.campaign.toolbar

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.pixelized.desktop.lwa.repository.campaign.CampaignRepository
import com.pixelized.desktop.lwa.repository.characterSheet.CharacterSheetRepository
import com.pixelized.desktop.lwa.repository.network.NetworkRepository
import com.pixelized.desktop.lwa.repository.settings.SettingsRepository
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn

class CampaignToolbarViewModel(
    private val characterRepository: CharacterSheetRepository,
    private val campaignRepository: CampaignRepository,
    networkRepository: NetworkRepository,
    settingsRepository: SettingsRepository,
) : ViewModel() {

    val status = networkRepository.status

    val title = campaignRepository.campaignFlow()
        .map { it.scene.name }
        .stateIn(
            scope = viewModelScope,
            started = SharingStarted.Lazily,
            initialValue = "",
        )

    val isAdmin = settingsRepository.settingsFlow()
        .map { it.isAdmin ?: false }
        .stateIn(
            scope = viewModelScope,
            started = SharingStarted.Lazily,
            initialValue = false,
        )
}