package com.pixelized.headache.ui.page.summary.monthly.item

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.pixelized.headache.ui.theme.HeadacheTheme
import com.pixelized.headache.ui.theme.color.HeadacheColorPalette

@Stable
data class MonthSummaryPillItemUio(
    val label: String,
    val amount: Int,
    val color: Color,
)

@Stable
data object MonthSummaryPillItemDefault {
    @Stable
    val padding: PaddingValues = PaddingValues(0.dp)

    @Stable
    val colorBoxSize: Dp = 8.dp

    @Stable
    val spacing: Dp = 4.dp
}

@Composable
fun MonthSummaryPillItem(
    modifier: Modifier = Modifier,
    padding: PaddingValues = MonthSummaryPillItemDefault.padding,
    spacing: Dp = MonthSummaryPillItemDefault.spacing,
    colorBoxSize: Dp = MonthSummaryPillItemDefault.colorBoxSize,
    item: MonthSummaryPillItemUio,
) {
    Row(
        modifier = Modifier
            .padding(paddingValues = padding)
            .then(other = modifier),
        horizontalArrangement = Arrangement.spacedBy(space = spacing),
    ) {
        Text(
            style = MaterialTheme.typography.bodyMedium,
            text = "-",
        )
        Box(
            modifier = Modifier
                .align(alignment = Alignment.CenterVertically)
                .size(size = colorBoxSize)
                .background(color = item.color)
        )
        Text(
            style = MaterialTheme.typography.bodyMedium,
            text = "${item.label} : ${item.amount}",
        )
    }
}

@Composable
@Preview
private fun MonthSummaryPillItemPreview() {
    HeadacheTheme {
        Surface {
            MonthSummaryPillItem(
                item = MonthSummaryPillItemUio(
                    label = "Élétriptan 40",
                    amount = 1,
                    color = HeadacheColorPalette.Pill.Eletriptan40,
                )
            )
        }
    }
}