package com.tt.honeyDue.ui.theme

import androidx.compose.ui.graphics.Color

/**
 * Data class representing a complete theme's color palette.
 *
 * Ground truth for every color below is the iOS app — captured in
 * `docs/ios-parity/colors.json` and asserted by
 * `composeApp/src/commonTest/kotlin/com/tt/honeyDue/ui/theme/ThemeColorsTest.kt`.
 *
 * When a value needs to change, update iOS first, refresh `colors.json`,
 * then mirror it here so the parity test stays green.
 */
data class ThemeColors(
    val id: String,
    val displayName: String,
    val description: String,

    // Light mode colors
    val lightPrimary: Color,
    val lightSecondary: Color,
    val lightAccent: Color,
    val lightError: Color,
    val lightBackgroundPrimary: Color,
    val lightBackgroundSecondary: Color,
    val lightTextPrimary: Color,
    val lightTextSecondary: Color,
    val lightTextOnPrimary: Color,

    // Dark mode colors
    val darkPrimary: Color,
    val darkSecondary: Color,
    val darkAccent: Color,
    val darkError: Color,
    val darkBackgroundPrimary: Color,
    val darkBackgroundSecondary: Color,
    val darkTextPrimary: Color,
    val darkTextSecondary: Color,
    val darkTextOnPrimary: Color
)

/**
 * All available themes matching iOS implementation.
 *
 * Color hex literals here use the `0xAARRGGBB` packed form — so 6-digit
 * iOS values (#RRGGBB) become `0xFFRRGGBB` (fully opaque), while 8-digit
 * iOS values (#RRGGBBAA, used by Default TextSecondary) have their alpha
 * byte re-ordered to leading position: `#RRGGBBAA` → `0xAARRGGBB`.
 */
object AppThemes {
    val Default = ThemeColors(
        id = "default",
        displayName = "Default",
        description = "Vibrant iOS system colors",

        // Light mode — iOS Default
        lightPrimary = Color(0xFF007AFF),
        lightSecondary = Color(0xFF5AC8FA),
        lightAccent = Color(0xFFFF9500),
        lightError = Color(0xFFFF3B30),
        lightBackgroundPrimary = Color(0xFFFFFFFF),
        lightBackgroundSecondary = Color(0xFFF2F7F7),
        lightTextPrimary = Color(0xFF111111),
        // iOS "#3D3D3D99" — 0x99 alpha, 0x3D3D3D RGB
        lightTextSecondary = Color(0x993D3D3D),
        lightTextOnPrimary = Color(0xFFFFFFFF),

        // Dark mode — iOS Default
        darkPrimary = Color(0xFF0A84FF),
        darkSecondary = Color(0xFF64D2FF),
        darkAccent = Color(0xFFFF9F0A),
        darkError = Color(0xFFFF453A),
        darkBackgroundPrimary = Color(0xFF1C1C1C),
        darkBackgroundSecondary = Color(0xFF2C2C2C),
        darkTextPrimary = Color(0xFFFFFFFF),
        // iOS "#EBEBEB99"
        darkTextSecondary = Color(0x99EBEBEB),
        darkTextOnPrimary = Color(0xFFFFFFFF)
    )

    val Teal = ThemeColors(
        id = "teal",
        displayName = "Teal",
        description = "Blue-green with warm accents",

        lightPrimary = Color(0xFF07A0C3),
        lightSecondary = Color(0xFF0055A5),
        lightAccent = Color(0xFFF0C808),
        lightError = Color(0xFFDD1C1A),
        lightBackgroundPrimary = Color(0xFFFFF1D0),
        lightBackgroundSecondary = Color(0xFFFFFFFF),
        lightTextPrimary = Color(0xFF111111),
        lightTextSecondary = Color(0xFF444444),
        lightTextOnPrimary = Color(0xFFFFFFFF),

        darkPrimary = Color(0xFF61CCE3),
        darkSecondary = Color(0xFF61A6D9),
        darkAccent = Color(0xFFF0C808),
        darkError = Color(0xFFFF5344),
        darkBackgroundPrimary = Color(0xFF0A1929),
        darkBackgroundSecondary = Color(0xFF1A2F3F),
        darkTextPrimary = Color(0xFFF5F5F5),
        darkTextSecondary = Color(0xFFC7C7C7),
        darkTextOnPrimary = Color(0xFFFFFFFF)
    )

    val Ocean = ThemeColors(
        id = "ocean",
        displayName = "Ocean",
        description = "Deep blues and coral tones",

        lightPrimary = Color(0xFF006B8F),
        lightSecondary = Color(0xFF008B8B),
        lightAccent = Color(0xFFFF7F50),
        lightError = Color(0xFFDD1C1A),
        lightBackgroundPrimary = Color(0xFFE5ECF2),
        lightBackgroundSecondary = Color(0xFFBDCBD6),
        lightTextPrimary = Color(0xFF111111),
        lightTextSecondary = Color(0xFF444444),
        lightTextOnPrimary = Color(0xFFFFFFFF),

        darkPrimary = Color(0xFF4AB5D1),
        darkSecondary = Color(0xFF61D1C7),
        darkAccent = Color(0xFFFF7F50),
        darkError = Color(0xFFFF5344),
        darkBackgroundPrimary = Color(0xFF171B23),
        darkBackgroundSecondary = Color(0xFF323B4C),
        darkTextPrimary = Color(0xFFF5F5F5),
        darkTextSecondary = Color(0xFFC7C7C7),
        darkTextOnPrimary = Color(0xFFFFFFFF)
    )

    val Forest = ThemeColors(
        id = "forest",
        displayName = "Forest",
        description = "Earth greens and golden hues",

        lightPrimary = Color(0xFF2D5016),
        lightSecondary = Color(0xFF6B8E23),
        lightAccent = Color(0xFFFFD700),
        lightError = Color(0xFFDD1C1A),
        lightBackgroundPrimary = Color(0xFFECEFE3),
        lightBackgroundSecondary = Color(0xFFC1C9AE),
        lightTextPrimary = Color(0xFF111111),
        lightTextSecondary = Color(0xFF444444),
        lightTextOnPrimary = Color(0xFFFFFFFF),

        darkPrimary = Color(0xFF94C76B),
        darkSecondary = Color(0xFFB0D182),
        darkAccent = Color(0xFFFFD700),
        darkError = Color(0xFFFF5344),
        darkBackgroundPrimary = Color(0xFF191E18),
        darkBackgroundSecondary = Color(0xFF384436),
        darkTextPrimary = Color(0xFFF5F5F5),
        darkTextSecondary = Color(0xFFC7C7C7),
        darkTextOnPrimary = Color(0xFFFFFFFF)
    )

    val Sunset = ThemeColors(
        id = "sunset",
        displayName = "Sunset",
        description = "Warm oranges and reds",

        lightPrimary = Color(0xFFFF4500),
        lightSecondary = Color(0xFFFF6347),
        lightAccent = Color(0xFFFFD700),
        lightError = Color(0xFFDD1C1A),
        lightBackgroundPrimary = Color(0xFFF7F1E8),
        lightBackgroundSecondary = Color(0xFFDCD0BB),
        lightTextPrimary = Color(0xFF111111),
        lightTextSecondary = Color(0xFF444444),
        lightTextOnPrimary = Color(0xFFFFFFFF),

        darkPrimary = Color(0xFFFF9E61),
        darkSecondary = Color(0xFFFFAD7D),
        darkAccent = Color(0xFFFFD700),
        darkError = Color(0xFFFF5344),
        darkBackgroundPrimary = Color(0xFF211914),
        darkBackgroundSecondary = Color(0xFF433329),
        darkTextPrimary = Color(0xFFF5F5F5),
        darkTextSecondary = Color(0xFFC7C7C7),
        darkTextOnPrimary = Color(0xFFFFFFFF)
    )

    val Monochrome = ThemeColors(
        id = "monochrome",
        displayName = "Monochrome",
        description = "Elegant grayscale",

        lightPrimary = Color(0xFF333333),
        lightSecondary = Color(0xFF666666),
        lightAccent = Color(0xFF999999),
        lightError = Color(0xFFDD1C1A),
        lightBackgroundPrimary = Color(0xFFF1F1F1),
        lightBackgroundSecondary = Color(0xFFD5D5D5),
        lightTextPrimary = Color(0xFF111111),
        lightTextSecondary = Color(0xFF444444),
        lightTextOnPrimary = Color(0xFFFFFFFF),

        darkPrimary = Color(0xFFE6E6E6),
        darkSecondary = Color(0xFFBFBFBF),
        darkAccent = Color(0xFFD1D1D1),
        darkError = Color(0xFFFF5344),
        darkBackgroundPrimary = Color(0xFF171717),
        darkBackgroundSecondary = Color(0xFF3C3C3C),
        darkTextPrimary = Color(0xFFF5F5F5),
        darkTextSecondary = Color(0xFFC7C7C7),
        darkTextOnPrimary = Color(0xFFFFFFFF)
    )

    val Lavender = ThemeColors(
        id = "lavender",
        displayName = "Lavender",
        description = "Soft purple with pink accents",

        lightPrimary = Color(0xFF6B418B),
        lightSecondary = Color(0xFF8B61B0),
        lightAccent = Color(0xFFE34A82),
        lightError = Color(0xFFDD1C1A),
        lightBackgroundPrimary = Color(0xFFF2F0F5),
        lightBackgroundSecondary = Color(0xFFD9D1E0),
        lightTextPrimary = Color(0xFF111111),
        lightTextSecondary = Color(0xFF444444),
        lightTextOnPrimary = Color(0xFFFFFFFF),

        darkPrimary = Color(0xFFD1B0E3),
        darkSecondary = Color(0xFFDEBFEB),
        darkAccent = Color(0xFFFF9EC7),
        darkError = Color(0xFFFF5344),
        darkBackgroundPrimary = Color(0xFF18141E),
        darkBackgroundSecondary = Color(0xFF393142),
        darkTextPrimary = Color(0xFFF5F5F5),
        darkTextSecondary = Color(0xFFC7C7C7),
        darkTextOnPrimary = Color(0xFFFFFFFF)
    )

    val Crimson = ThemeColors(
        id = "crimson",
        displayName = "Crimson",
        description = "Bold red with warm highlights",

        lightPrimary = Color(0xFFB51E28),
        lightSecondary = Color(0xFF992E38),
        lightAccent = Color(0xFFE36100),
        lightError = Color(0xFFDD1C1A),
        lightBackgroundPrimary = Color(0xFFF6EEEC),
        lightBackgroundSecondary = Color(0xFFDECFCC),
        lightTextPrimary = Color(0xFF111111),
        lightTextSecondary = Color(0xFF444444),
        lightTextOnPrimary = Color(0xFFFFFFFF),

        darkPrimary = Color(0xFFFF827D),
        darkSecondary = Color(0xFFFA9994),
        darkAccent = Color(0xFFFFB56B),
        darkError = Color(0xFFFF5344),
        darkBackgroundPrimary = Color(0xFF1B1216),
        darkBackgroundSecondary = Color(0xFF412F39),
        darkTextPrimary = Color(0xFFF5F5F5),
        darkTextSecondary = Color(0xFFC7C7C7),
        darkTextOnPrimary = Color(0xFFFFFFFF)
    )

    val Midnight = ThemeColors(
        id = "midnight",
        displayName = "Midnight",
        description = "Deep navy with sky blue",

        lightPrimary = Color(0xFF1E4A94),
        lightSecondary = Color(0xFF2E61B0),
        lightAccent = Color(0xFF4A94E3),
        lightError = Color(0xFFDD1C1A),
        lightBackgroundPrimary = Color(0xFFEEF1F7),
        lightBackgroundSecondary = Color(0xFFCCD6E3),
        lightTextPrimary = Color(0xFF111111),
        lightTextSecondary = Color(0xFF444444),
        lightTextOnPrimary = Color(0xFFFFFFFF),

        darkPrimary = Color(0xFF82B5EB),
        darkSecondary = Color(0xFF94C7F2),
        darkAccent = Color(0xFF9ED9FF),
        darkError = Color(0xFFFF5344),
        darkBackgroundPrimary = Color(0xFF121720),
        darkBackgroundSecondary = Color(0xFF303849),
        darkTextPrimary = Color(0xFFF5F5F5),
        darkTextSecondary = Color(0xFFC7C7C7),
        darkTextOnPrimary = Color(0xFFFFFFFF)
    )

    val Desert = ThemeColors(
        id = "desert",
        displayName = "Desert",
        description = "Warm terracotta and sand tones",

        lightPrimary = Color(0xFFB0614A),
        lightSecondary = Color(0xFF9E7D61),
        lightAccent = Color(0xFFD1942E),
        lightError = Color(0xFFDD1C1A),
        lightBackgroundPrimary = Color(0xFFF6F1EB),
        lightBackgroundSecondary = Color(0xFFE6D9C7),
        lightTextPrimary = Color(0xFF111111),
        lightTextSecondary = Color(0xFF444444),
        lightTextOnPrimary = Color(0xFFFFFFFF),

        darkPrimary = Color(0xFFF2B594),
        darkSecondary = Color(0xFFEBD1B0),
        darkAccent = Color(0xFFFFD96B),
        darkError = Color(0xFFFF5344),
        darkBackgroundPrimary = Color(0xFF201C17),
        darkBackgroundSecondary = Color(0xFF4A4138),
        darkTextPrimary = Color(0xFFF5F5F5),
        darkTextSecondary = Color(0xFFC7C7C7),
        darkTextOnPrimary = Color(0xFFFFFFFF)
    )

    val Mint = ThemeColors(
        id = "mint",
        displayName = "Mint",
        description = "Fresh green with turquoise",

        lightPrimary = Color(0xFF38B094),
        lightSecondary = Color(0xFF61C7B0),
        lightAccent = Color(0xFF2E9EB0),
        lightError = Color(0xFFDD1C1A),
        lightBackgroundPrimary = Color(0xFFEEF6F1),
        lightBackgroundSecondary = Color(0xFFD1E3D9),
        lightTextPrimary = Color(0xFF111111),
        lightTextSecondary = Color(0xFF444444),
        lightTextOnPrimary = Color(0xFFFFFFFF),

        darkPrimary = Color(0xFF94F2D9),
        darkSecondary = Color(0xFFBFFAEB),
        darkAccent = Color(0xFF6BEBF2),
        darkError = Color(0xFFFF5344),
        darkBackgroundPrimary = Color(0xFF172020),
        darkBackgroundSecondary = Color(0xFF384A4A),
        darkTextPrimary = Color(0xFFF5F5F5),
        darkTextSecondary = Color(0xFFC7C7C7),
        darkTextOnPrimary = Color(0xFFFFFFFF)
    )

    /**
     * List of all available themes
     */
    val allThemes = listOf(
        Default, Teal, Ocean, Forest, Sunset, Monochrome,
        Lavender, Crimson, Midnight, Desert, Mint
    )

    /**
     * Get theme by ID
     */
    fun getThemeById(id: String): ThemeColors {
        return allThemes.find { it.id == id } ?: Default
    }
}
