package dev.ulfrx.recipe.ui.screens.planner

import androidx.lifecycle.ViewModel
import dev.ulfrx.recipe.ui.components.calendar.CalendarMode
import dev.ulfrx.recipe.ui.components.calendar.todayInSystemTz
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.datetime.LocalDate

/**
 * UI state for [PlannerScreen]. Phase 2.1 ships only the calendar; Phase 6
 * extends this with day-plan data, meal slot actions, and pantry/shortfall
 * derivations driven by [selectedDate].
 */
data class PlannerState(
    val selectedDate: LocalDate,
    val calendarMode: CalendarMode,
)

class PlannerViewModel : ViewModel() {
    private val _state =
        MutableStateFlow(
            PlannerState(
                selectedDate = todayInSystemTz(),
                calendarMode = CalendarMode.Week,
            ),
        )
    val state: StateFlow<PlannerState> = _state.asStateFlow()

    fun selectDate(date: LocalDate) {
        _state.update { it.copy(selectedDate = date) }
    }

    fun setCalendarMode(mode: CalendarMode) {
        _state.update { it.copy(calendarMode = mode) }
    }
}
