package com.ponzischeme89.memby.ui

import androidx.compose.ui.unit.dp
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test

class ResponsiveRowSizingTest {
    @Test
    fun metadataPanelKeepsReadableLineLengthsAcrossTvWidths() {
        assertEquals(537.6f, metadataPanelContentWidth(640.dp, compact = true).value, 0.01f)
        assertEquals(720f, metadataPanelContentWidth(1920.dp, compact = false).value, 0.01f)
    }

    @Test
    fun standardPosterRowFitsSevenCompleteCards() {
        val width = responsiveRowCardWidth(
            availableWidth = 1280.dp,
            preferredCardsAcross = 7,
            minWidth = 102.dp,
            maxWidth = 218.dp,
        )

        val occupiedWidth = width * 7 + 16.dp * 6 + 36.dp * 2
        assertEquals(1280f, occupiedWidth.value, 0.01f)
    }

    @Test
    fun narrowRowReducesCardCountInsteadOfClippingCards() {
        val width = responsiveRowCardWidth(
            availableWidth = 640.dp,
            preferredCardsAcross = 7,
            minWidth = 102.dp,
            maxWidth = 218.dp,
        )

        // Four 130dp cards, three gaps and both insets fill this viewport exactly.
        assertEquals(130f, width.value, 0.01f)
        assertEquals(640f, (width * 4 + 16.dp * 3 + 36.dp * 2).value, 0.01f)
    }

    @Test
    fun wideRowAddsCardsRatherThanExceedingMaximumWidth() {
        val width = responsiveRowCardWidth(
            availableWidth = 2560.dp,
            preferredCardsAcross = 4,
            minWidth = 164.dp,
            maxWidth = 360.dp,
        )

        assertTrue(width <= 360.dp)
        assertEquals(341.71f, width.value, 0.01f)
    }
}
