package com.applemand.zmanim.core.ui

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.applemand.zmanim.core.design.HolidayColors

enum class HolidayTier { YOM_TOV, FAST, MINOR, ROSH_CHODESH, SHABBAT }

@Composable
fun HolidayBadge(
    label: String,
    tier: HolidayTier,
    modifier: Modifier = Modifier,
) {
    val dark = isSystemInDarkTheme()
    val (bg, text, border) = when (tier) {
        HolidayTier.YOM_TOV -> Triple(
            if (dark) HolidayColors.YomTovBgDark else HolidayColors.YomTovBg,
            HolidayColors.YomTovText,
            HolidayColors.YomTovBorder,
        )
        HolidayTier.FAST -> Triple(
            if (dark) HolidayColors.FastBgDark else HolidayColors.FastBg,
            HolidayColors.FastText,
            HolidayColors.FastBorder,
        )
        HolidayTier.MINOR -> Triple(
            if (dark) HolidayColors.MinorBgDark else HolidayColors.MinorBg,
            HolidayColors.MinorText,
            HolidayColors.MinorBorder,
        )
        HolidayTier.ROSH_CHODESH -> Triple(
            if (dark) HolidayColors.RoshChodeshBgDark else HolidayColors.RoshChodeshBg,
            HolidayColors.RoshChodeshText,
            HolidayColors.RoshChodeshBorder,
        )
        HolidayTier.SHABBAT -> Triple(
            if (dark) HolidayColors.ShabbatDark else HolidayColors.Shabbat,
            MaterialTheme.colorScheme.onSecondaryContainer,
            Color.Transparent,
        )
    }

    val shape = RoundedCornerShape(999.dp)
    val m = modifier
        .clip(shape)
        .background(bg)
        .let { if (border != Color.Transparent) it.border(BorderStroke(1.dp, border), shape) else it }
        .padding(horizontal = 8.dp, vertical = 2.dp)

    Text(
        text = label,
        modifier = m,
        color = text,
        style = MaterialTheme.typography.labelSmall.copy(fontWeight = FontWeight.SemiBold),
    )
}
