package dev.privacyllc.period.feature.onboarding

import android.content.res.Configuration
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import dev.privacyllc.period.designsystem.PeriodTheme
import dev.privacyllc.period.designsystem.art.EmptyStateIllustration
import dev.privacyllc.period.designsystem.art.ForecastIllustration
import dev.privacyllc.period.designsystem.art.LastPeriodIllustration
import dev.privacyllc.period.designsystem.art.LearningIllustration
import dev.privacyllc.period.designsystem.art.NotificationPrivacyIllustration
import dev.privacyllc.period.designsystem.art.PeriodEndIllustration
import dev.privacyllc.period.designsystem.art.PrivacyIllustration
import dev.privacyllc.period.designsystem.art.WelcomeIllustration

/**
 * Every illustration, in both themes.
 *
 * **These exist because dark mode was broken and nothing said so.** The theme
 * was not wrapping its content in a `Surface`, so any `Text` without an explicit
 * colour inherited Material's default — black — and the app's background never
 * painted. In light mode that looked right by accident. In dark mode the
 * onboarding headings were near-black on charcoal, and it was found by opening
 * the app rather than by any test.
 *
 * A preview pair is not a test and does not fail a build. What it does is put
 * both themes in front of whoever is editing the screen, which is the cheapest
 * thing that would have caught it.
 *
 * These now carry a second job. The illustrations are drawables with a
 * `drawable-night/` twin, so the theme swap happens in resource resolution
 * rather than in any code here — and a missing or mismatched night asset is
 * invisible until somebody looks at the dark preview. There is one entry per
 * illustration for exactly that reason: a set of eight where seven have a night
 * variant looks completely fine in light mode.
 */
@Preview(name = "Illustrations · light", showBackground = true, heightDp = 1100)
@Preview(
    name = "Illustrations · dark",
    showBackground = true,
    heightDp = 1100,
    uiMode = Configuration.UI_MODE_NIGHT_YES,
)
@Composable
private fun IllustrationPreviews() {
    PeriodTheme {
        Column(
            Modifier.fillMaxWidth(),
            verticalArrangement = Arrangement.spacedBy(8.dp),
            horizontalAlignment = Alignment.CenterHorizontally,
        ) {
            Label("1 · Welcome")
            WelcomeIllustration(size = 150.dp)
            Label("2 · Last period start")
            LastPeriodIllustration(size = 150.dp)
            Label("3 · Period end")
            PeriodEndIllustration(size = 150.dp)
            Label("4 · Learning, and Insights empty")
            LearningIllustration(size = 150.dp)
            Label("5 · Privacy promise")
            PrivacyIllustration(size = 150.dp)
            Label("6 · Reminder privacy")
            NotificationPrivacyIllustration(size = 150.dp)
            Label("7 · First forecast")
            ForecastIllustration(size = 150.dp)
            Label("Today empty state")
            EmptyStateIllustration(size = 150.dp)
        }
    }
}

@Composable
private fun Label(text: String) =
    Text(text, style = MaterialTheme.typography.labelLarge)
