package com.applemand.zmanim.feature.zmanim

import androidx.compose.foundation.layout.Column
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.applemand.zmanim.core.design.ZmanimColors
import com.applemand.zmanim.core.ui.PanelCard
import com.applemand.zmanim.core.ui.ZmanRow
import com.applemand.zmanim.core.zmanim.ZmanKey
import com.applemand.zmanim.core.zmanim.ZmanimFormatter
import com.applemand.zmanim.core.zmanim.ZmanimSnapshot

@Composable
fun ZmanimPanel(
    snapshot: ZmanimSnapshot,
    visible: Map<String, Boolean>,
    twelveHour: Boolean,
    showSeconds: Boolean,
    modifier: Modifier = Modifier,
    title: String = "Zmanim",
) {
    PanelCard(title = title, modifier = modifier) {
        val fmt = ZmanimFormatter(
            tzid = snapshot.location.tzid,
            twelveHour = twelveHour,
            showSeconds = showSeconds,
        )
        Column {
            ZmanKey.entries
                .filter { visible[it.keyId] != false }
                .forEach { key ->
                    ZmanRow(
                        label = key.nameEn,
                        time = fmt.format(snapshot[key]),
                        accent = key.accent(),
                    )
                }
        }
    }
}

private fun ZmanKey.accent() = when (this) {
    ZmanKey.ALOT_HASHACHAR -> ZmanimColors.AlotHaShachar
    ZmanKey.ZMAN_TZITZIT -> ZmanimColors.ZmanTzitzit
    ZmanKey.SUNRISE -> ZmanimColors.Sunrise
    ZmanKey.SOF_SHMA_GRA -> ZmanimColors.SofShmaGRA
    ZmanKey.SOF_SHMA_MA -> ZmanimColors.SofShmaMA
    ZmanKey.SOF_TFILA -> ZmanimColors.SofTfila
    ZmanKey.MIDDAY -> ZmanimColors.Midday
    ZmanKey.MINCHA_GEDOLAH -> ZmanimColors.MinchaGedolah
    ZmanKey.PLAG_HAMINCHA -> ZmanimColors.PlagHaMincha
    ZmanKey.SUNSET -> ZmanimColors.Sunset
    ZmanKey.CANDLE_LIGHTING -> ZmanimColors.CandleLighting
    ZmanKey.TZEIT_KOCHAVIM -> ZmanimColors.TzeitKochavim
    ZmanKey.RABBEINU_TAM -> ZmanimColors.RabbeinuTam
}
