//
//  AppColors.swift
//  lichunWebsocket
//
//  Centralized color definitions for the app - Cozy Game UI
//

import SwiftUI

struct AppColors {

    // MARK: - Adaptive Color Helper

    /// Creates an adaptive color that responds to light/dark mode changes
    private static func adaptive(light: UInt, dark: UInt) -> Color {
        Color(UIColor { traitCollection in
            traitCollection.userInterfaceStyle == .dark
                ? UIColor(hex: dark)
                : UIColor(hex: light)
        })
    }

    // MARK: - Primary Colors (Warm & Inviting)

    /// Soft rose pink - Primary brand color (replaces harsh #007AFF blue)
    static let primary = adaptive(light: 0xF4A5B5, dark: 0xF4A5B5)
    static let primaryDark = Color(hex: 0xE88CA0)

    /// Soft periwinkle blue - Secondary accent
    static let secondary = adaptive(light: 0xB5C9F4, dark: 0x8FA5D6)
    static let secondaryDark = Color(hex: 0x8FA5D6)

    /// Warm peachy-yellow - Accent color
    static let accent = adaptive(light: 0xFFD89B, dark: 0xFFCA6D)
    static let accentDark = Color(hex: 0xFFCA6D)

    // MARK: - Background Hierarchy

    /// Warm cream - Main background (warmer than original beige)
    static let background = adaptive(light: 0xFFF8F3, dark: 0x2A2420)

    /// Peachy cream - Elevated surfaces (cards, modals)
    static let surfaceElevated = adaptive(light: 0xFFF0E6, dark: 0x3A3230)

    /// Subtle layering color
    static let surfaceSubtle = adaptive(light: 0xFDF5EE, dark: 0x322A28)

    /// Modal overlay - softer than before
    static let modalOverlay = Color.black.opacity(0.4)

    // MARK: - Backwards Compatibility
    static let primaryBackground = background
    static let cardBackground = surfaceElevated

    // MARK: - Liquid Glass Effects

    /// Glass tint for light mode
    static let glassTintLight = Color.white.opacity(0.7)

    /// Glass tint for dark mode
    static let glassTintDark = Color.black.opacity(0.3)

    /// Glass border highlight
    static let glassBorderLight = Color.white.opacity(0.5)
    static let glassBorderDark = Color.white.opacity(0.2)

    /// Tab bar selection indicator
    static let tabSelection = primary.opacity(0.12)

    // MARK: - Text Colors (Warm Browns)

    /// Primary text - warm brown (replaces white)
    static let primaryText = adaptive(light: 0x5A4A3A, dark: 0xF5EDE6)

    /// Secondary text - lighter warm brown
    static let secondaryText = adaptive(light: 0x8B7A6A, dark: 0xC4B5A7)

    /// Disabled text - warm gray
    static let disabledText = adaptive(light: 0xC4B5A7, dark: 0x6B5F5A)

    /// Accent text - primary for emphasis
    static let accentText = Color(hex: 0xE88CA0)

    // MARK: - Stat Colors (Soft Pastels)

    /// Energy - soft sage green (was #00D084 neon teal)
    static let energy = Color(hex: 0x9DDFAA)

    /// Money - warm butter yellow (was #4CD964 bright green)
    static let money = Color(hex: 0xFFE07A)

    /// Diamonds - soft sky blue (was #5AC8FA)
    static let diamond = Color(hex: 0xA8D5EA)

    /// Health - soft coral pink (was #FF3B30 harsh red)
    static let health = Color(hex: 0xFFB3BA)

    /// Happiness - warm sunflower (was #FFCC00 bright yellow)
    static let happiness = Color(hex: 0xFFFEA7)

    /// Intelligence - soft lavender (was #5856D6 harsh purple)
    static let intelligence = Color(hex: 0xC9B8F4)

    /// Looks - soft blush pink (was #FF2D55)
    static let looks = Color(hex: 0xFFB6C8)

    /// Prestige - warm apricot (was #FF9500)
    static let prestige = Color(hex: 0xF9D5A7)

    // MARK: - Relationship & Social Colors

    static let loveInterest = Color(hex: 0xFFB6C8)
    static let friend = Color(hex: 0xA8D5EA)
    static let family = Color(hex: 0xFFFEA7)
    static let acquaintance = Color(hex: 0xD4C5E8)

    // MARK: - Messaging Colors

    /// Player bubble - soft rose pink (dark mode: slightly darker for contrast)
    static let playerBubble = adaptive(light: 0xF4A5B5, dark: 0xE88CA0)

    /// NPC bubble - warm cream in light mode, warm dark brown in dark mode
    static let npcBubble = adaptive(light: 0xF5EDE6, dark: 0x3D3530)

    /// Player bubble text - always white/light for contrast on pink
    static let playerBubbleText = Color.white

    /// NPC bubble text - warm brown in light mode, warm cream in dark mode (matches background contrast)
    static let npcBubbleText = adaptive(light: 0x5A4A3A, dark: 0xF5EDE6)

    // MARK: - Semantic Colors

    static let success = Color(hex: 0x9DDFAA)
    static let warning = Color(hex: 0xFFD89B)
    static let error = Color(hex: 0xFFB3BA)
    static let info = Color(hex: 0xA8D5EA)

    // MARK: - Dark Mode (Warm Evening Lighting)

    /// Dark mode background - warm dark brown (not pure black)
    static let backgroundDark = Color(hex: 0x2A2420)

    /// Dark mode elevated surfaces
    static let surfaceElevatedDark = Color(hex: 0x3A3230)

    /// Dark mode primary text - warm white
    static let primaryTextDark = Color(hex: 0xF5EDE6)

    /// Dark mode secondary text
    static let secondaryTextDark = Color(hex: 0xC4B5A7)

    // MARK: - Seasonal Gradients

    static func cozySeasonGradient(_ season: String) -> LinearGradient {
        switch season.lowercased() {
        case "spring":
            return LinearGradient(
                colors: [Color(hex: 0xE8F5E9), Color(hex: 0xFFE0F0)],
                startPoint: .topLeading,
                endPoint: .bottomTrailing
            )
        case "summer":
            return LinearGradient(
                colors: [Color(hex: 0xFFF9E6), Color(hex: 0xFFEDD4)],
                startPoint: .topLeading,
                endPoint: .bottomTrailing
            )
        case "autumn", "fall":
            return LinearGradient(
                colors: [Color(hex: 0xFFE5CC), Color(hex: 0xFFD4B8)],
                startPoint: .topLeading,
                endPoint: .bottomTrailing
            )
        case "winter":
            return LinearGradient(
                colors: [Color(hex: 0xE3F2FD), Color(hex: 0xF0F4FA)],
                startPoint: .topLeading,
                endPoint: .bottomTrailing
            )
        default:
            return LinearGradient(
                colors: [Color(hex: 0xFFF8F3), Color(hex: 0xFFF0E6)],
                startPoint: .topLeading,
                endPoint: .bottomTrailing
            )
        }
    }

    // MARK: - Legacy Support (deprecated, use cozySeasonGradient)
    static func seasonGradient(_ season: String) -> LinearGradient {
        return cozySeasonGradient(season)
    }
}
