//
//  DesignConstants.swift
//  Baccarat
//
//  Design system constants for consistent styling across the app.
//  Uses CasinoDesign from CasinoKit for shared values, with game-specific overrides.
//

import SwiftUI
import CasinoKit

/// Design constants for the Baccarat app.
/// Shared constants are imported from CasinoDesign; game-specific values are defined here.
enum Design {
    
    /// Set to true to show layout debug borders on views
    static let showDebugBorders = false
    
    // MARK: - Shared Constants (from CasinoKit)
    
    typealias Spacing = CasinoDesign.Spacing
    typealias CornerRadius = CasinoDesign.CornerRadius
    typealias LineWidth = CasinoDesign.LineWidth
    typealias Shadow = CasinoDesign.Shadow
    typealias Opacity = CasinoDesign.Opacity
    typealias Animation = CasinoDesign.Animation
    typealias Scale = CasinoDesign.Scale
    typealias MinScaleFactor = CasinoDesign.MinScaleFactor
    typealias BaseFontSize = CasinoDesign.BaseFontSize
    typealias IconSize = CasinoDesign.IconSize
    
    // MARK: - Baccarat-Specific Component Sizes
    
    enum Size {
        // MARK: - Hand Scaling
        
        /// Hand scaling factor for cards and related elements.
        /// 1.0 = original size, 1.5 = 50% larger, 2.0 = double size.
        /// Adjust this value to change card sizes across the app.
        static let handScale: CGFloat = 1.75
        
        /// Scale multiplier for small screens (iPhone SE, etc).
        /// Applied instead of handScale on screens narrower than smallScreenThreshold.
        static let smallScreenScale: CGFloat = 1.2
        
        /// Screen width threshold for small screen detection (iPhone SE is 375pt)
        static let smallScreenThreshold: CGFloat = 390
        
        /// Additional scale multiplier for large screens (iPad).
        /// Applied on top of handScale when on regular size class.
        static let largeScreenMultiplier: CGFloat = 1.2
        
        // Cards - base values from CasinoDesign
        static let cardWidthSmall: CGFloat = CasinoDesign.Size.cardWidthSmall
        static let cardWidthMedium: CGFloat = CasinoDesign.Size.cardWidthMedium
        static let cardWidthLarge: CGFloat = CasinoDesign.Size.cardWidthLarge
        static let cardAspectRatio: CGFloat = CasinoDesign.Size.cardAspectRatio
        
        /// Base card width before scaling (for reference)
        private static let cardWidthTableBase: CGFloat = 45
        
        /// Base card overlap before scaling.
        /// More negative = more overlap (less card visible).
        /// -15 is default, -20 shows less card, -25 shows even less.
        private static let cardOverlapBase: CGFloat = -25
        
        /// Card overlap scaled with hand size (standard iPhone)
        static let cardOverlap: CGFloat = cardOverlapBase * handScale
        
        /// Card overlap for small screens
        static let cardOverlapSmall: CGFloat = cardOverlapBase * smallScreenScale
        
        // Baccarat table cards - scaled for better visibility (standard iPhone)
        static let cardWidthTable: CGFloat = cardWidthTableBase * handScale
        
        /// Card width for small screens (iPhone SE, etc)
        static let cardWidthTableSmall: CGFloat = cardWidthTableBase * smallScreenScale
        
        /// Card width for large screens (iPad) - applies additional multiplier
        static let cardWidthTableLarge: CGFloat = cardWidthTableBase * handScale * largeScreenMultiplier
        
        /// Card overlap for large screens
        static let cardOverlapLarge: CGFloat = cardOverlapBase * handScale * largeScreenMultiplier
        
        // Chips - use CasinoDesign values
        static let chipSmall: CGFloat = CasinoDesign.Size.chipSmall
        static let chipMedium: CGFloat = CasinoDesign.Size.chipMedium
        static let chipSelector: CGFloat = CasinoDesign.Size.chipMedium
        static let chipBadge: CGFloat = CasinoDesign.Size.chipBadge
        static let chipBadgeInner: CGFloat = CasinoDesign.Size.chipBadgeInner
        
        // Shared values
        static let valueBadge: CGFloat = CasinoDesign.Size.valueBadge
        static let checkmark: CGFloat = CasinoDesign.Size.checkmark
        static let maxContentWidthPortrait: CGFloat = CasinoDesign.Size.maxContentWidthPortrait
        static let maxContentWidthLandscape: CGFloat = CasinoDesign.Size.maxContentWidthLandscape
        static let maxModalWidth: CGFloat = CasinoDesign.Size.maxModalWidth
        
        // Baccarat-specific table layout
        static let tableAspectRatio: CGFloat = 1.6
        static let roadMapCell: CGFloat = 16
        static let diamondIcon: CGFloat = 24
        static let topBetRowHeight: CGFloat = 52
        static let mainBetRowHeight: CGFloat = 65
        static let bonusZoneWidth: CGFloat = 80
    }
}

// MARK: - Baccarat App Colors

extension Color {
    
    // MARK: - Table Colors (use CasinoTable from CasinoKit)
    
    /// Typealias for consistent table colors across all games.
    typealias Table = CasinoTable
    
    // MARK: - Border Colors
    
    enum Border {
        static let goldLight = CasinoTable.goldLight
        static let goldDark = CasinoTable.goldDark
        static let gold = Color(red: 0.7, green: 0.55, blue: 0.25)
        static let silver = Color(red: 0.6, green: 0.6, blue: 0.65)
    }
    
    // MARK: - Betting Zone Colors
    
    enum BettingZone {
        // Player (Blue)
        static let playerLight = Color(red: 0.1, green: 0.25, blue: 0.55)
        static let playerDark = Color(red: 0.05, green: 0.15, blue: 0.4)
        static let playerMaxLight = Color(red: 0.08, green: 0.18, blue: 0.4)
        static let playerMaxDark = Color(red: 0.04, green: 0.1, blue: 0.28)
        
        // Banker (Red)
        static let bankerLight = Color(red: 0.55, green: 0.12, blue: 0.12)
        static let bankerDark = Color(red: 0.4, green: 0.08, blue: 0.08)
        static let bankerMaxLight = Color(red: 0.4, green: 0.1, blue: 0.1)
        static let bankerMaxDark = Color(red: 0.28, green: 0.06, blue: 0.06)
        
        // Tie (Green)
        static let tie = Color(red: 0.1, green: 0.45, blue: 0.25)
        static let tieMax = Color(red: 0.08, green: 0.32, blue: 0.18)
        
        // Dragon Bonus (Purple/Blue gradient)
        static let dragonBonusLight = Color(red: 0.25, green: 0.3, blue: 0.45)
        static let dragonBonusDark = Color(red: 0.15, green: 0.2, blue: 0.35)
    }
    
    // MARK: - Button Colors
    
    enum Button {
        static let goldLight = Color(red: 1.0, green: 0.85, blue: 0.3)
        static let goldDark = Color(red: 0.9, green: 0.7, blue: 0.2)
        static let destructive = Color(red: 0.6, green: 0.2, blue: 0.2)
    }
    
    // MARK: - Chip Colors (for theming)
    
    enum Chip {
        static let gold = Color(red: 0.8, green: 0.65, blue: 0.2)
        
        // Chip base colors by denomination
        static let tenBase = Color(red: 0.2, green: 0.4, blue: 0.8)
        static let tenHighlight = Color(red: 0.3, green: 0.5, blue: 0.9)
        static let twentyFiveBase = Color(red: 0.1, green: 0.6, blue: 0.3)
        static let twentyFiveHighlight = Color(red: 0.2, green: 0.7, blue: 0.4)
        static let fiftyBase = Color(red: 0.8, green: 0.5, blue: 0.1)
        static let fiftyHighlight = Color(red: 0.9, green: 0.6, blue: 0.2)
        static let hundredBase = Color(red: 0.1, green: 0.1, blue: 0.1)
        static let hundredHighlight = Color(red: 0.3, green: 0.3, blue: 0.3)
        static let fiveHundredBase = Color(red: 0.6, green: 0.2, blue: 0.6)
        static let fiveHundredHighlight = Color(red: 0.7, green: 0.3, blue: 0.7)
        static let thousandBase = Color(red: 0.8, green: 0.65, blue: 0.2)
        static let thousandHighlight = Color(red: 0.9, green: 0.75, blue: 0.3)
        static let fiveThousandBase = Color(red: 0.7, green: 0.1, blue: 0.2)
        static let fiveThousandHighlight = Color(red: 0.85, green: 0.2, blue: 0.3)
        static let tenThousandBase = Color(red: 0.2, green: 0.5, blue: 0.5)
        static let tenThousandHighlight = Color(red: 0.3, green: 0.6, blue: 0.6)
        static let twentyFiveThousandBase = Color(red: 0.5, green: 0.3, blue: 0.1)
        static let twentyFiveThousandHighlight = Color(red: 0.65, green: 0.45, blue: 0.2)
        static let fiftyThousandBase = Color(red: 0.75, green: 0.75, blue: 0.8)
        static let fiftyThousandHighlight = Color(red: 0.85, green: 0.85, blue: 0.9)
        static let hundredThousandBase = Color(red: 0.9, green: 0.1, blue: 0.3)
        static let hundredThousandHighlight = Color(red: 1.0, green: 0.2, blue: 0.4)
        
        // Accent stripe colors
        static let goldStripe = Color(red: 0.9, green: 0.75, blue: 0.3)
        static let darkStripe = Color(red: 0.2, green: 0.2, blue: 0.3)
        static let goldRubyStripe = Color(red: 0.9, green: 0.85, blue: 0.3)
    }
    
    // MARK: - Card Colors
    
    enum Card {
        // Card back
        static let backDark = Color(red: 0.6, green: 0.1, blue: 0.15)
        static let backLight = Color(red: 0.4, green: 0.05, blue: 0.1)
        static let patternLight = Color(red: 0.9, green: 0.7, blue: 0.4)
        static let patternDark = Color(red: 0.7, green: 0.5, blue: 0.2)
        static let innerDark = Color(red: 0.5, green: 0.08, blue: 0.12)
        static let innerLight = Color(red: 0.35, green: 0.04, blue: 0.08)
        static let diamondPattern = Color(red: 0.9, green: 0.7, blue: 0.4)
        static let logoText = Color(red: 0.4, green: 0.05, blue: 0.1)
    }
    
    // MARK: - Modal Colors
    
    enum Modal {
        static let backgroundLight = Color(red: 0.12, green: 0.12, blue: 0.14)
        static let backgroundDark = Color(red: 0.08, green: 0.08, blue: 0.1)
    }
    
    // MARK: - Settings Colors
    
    enum Settings {
        static let background = Color(red: 0.08, green: 0.12, blue: 0.08)
    }
}

// MARK: - Localized Strings Helper

extension String {
    
    /// Returns a localized string for the given key.
    static func localized(_ key: String) -> String {
        String(localized: String.LocalizationValue(key))
    }
    
    /// Returns a localized string with format arguments.
    static func localized(_ key: String, _ arguments: CVarArg...) -> String {
        let format = String(localized: String.LocalizationValue(key))
        return String(format: format, arguments: arguments)
    }
}
