package com.applemand.zmanim.core.ui

import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import kotlinx.coroutines.delay
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant

/**
 * Emits the current Instant on the desired cadence without per-frame recomposition.
 * Used to drive live midnight rollover + "upcoming zman in X min" labels.
 */
@Composable
fun rememberNowTicker(periodMillis: Long = 30_000L): State<Instant> {
    val state = remember { mutableStateOf(Clock.System.now()) }
    LaunchedEffect(periodMillis) {
        while (true) {
            state.value = Clock.System.now()
            delay(periodMillis)
        }
    }
    return state
}
