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

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import dev.ulfrx.recipe.ui.components.calendar.CalendarLocale
import dev.ulfrx.recipe.ui.components.calendar.CalendarPill
import dev.ulfrx.recipe.ui.components.calendar.DayState
import dev.ulfrx.recipe.ui.components.calendar.todayInSystemTz
import dev.ulfrx.recipe.ui.theme.RecipeTheme
import kotlinx.datetime.DatePeriod
import kotlinx.datetime.LocalDate
import kotlinx.datetime.plus

@Composable
fun PlannerCalendarPill(
    selectedDate: LocalDate,
    expanded: Boolean,
    onExpandedChange: (Boolean) -> Unit,
    onSelectDate: (LocalDate) -> Unit,
    modifier: Modifier = Modifier,
) {
    val today = remember { todayInSystemTz() }
    val locale = CalendarLocale.PL
    val plannedDummy =
        remember(today) {
            setOf(today, today.plus(DatePeriod(days = 1)), today.plus(DatePeriod(days = 3)))
        }
    val dayState =
        remember(plannedDummy) {
            { date: LocalDate -> DayState(indicator = date in plannedDummy) }
        }
    val pillTextStyle = RecipeTheme.typography.label.copy(fontWeight = FontWeight.Light, fontSize = 12.sp)

    CalendarPill(
        expanded = expanded,
        onExpandedChange = onExpandedChange,
        selectedDate = selectedDate,
        today = today,
        onSelectDate = onSelectDate,
        collapsedContent = {
            PlannerWeekStrip(
                selectedDate = selectedDate,
                today = today,
                onSelectDate = onSelectDate,
                numberStyle = pillTextStyle,
                dayState = dayState,
                modifier = Modifier.weight(1f),
            )
            BasicText(
                text = locale.monthsShort[selectedDate.monthNumber - 1],
                style = pillTextStyle.copy(color = RecipeTheme.colors.contentMuted),
            )
        },
        dayState = dayState,
        modifier = modifier.fillMaxWidth(),
    )
}
