//
//  AppTypography.swift
//  lichunWebsocket
//
//  Consistent text styles for the app - Cozy Game UI
//

import SwiftUI

// NOTE: Font styles are defined in the Font extension below
// This allows usage like: .font(.appTitle)
struct AppTypography {
    // This struct is kept for potential future non-font typography utilities
}

// MARK: - Text Style Extensions

extension Text {
    /// Cozy title with soft shadow
    func cozyTitle() -> some View {
        self.font(.appTitle)
            .foregroundColor(AppColors.primaryText)
            .shadow(color: AppColors.accent.opacity(0.2), radius: 8, x: 0, y: 4)
    }

    /// Stat number style with color and glow
    func statNumberStyle(color: Color) -> some View {
        self.font(.system(size: 20, weight: .bold, design: .rounded))
            .foregroundColor(color)
            .shadow(color: color.opacity(0.3), radius: 4, x: 0, y: 2)
    }

    /// Warm body text with comfortable line spacing
    func cozyBody() -> some View {
        self.font(.appBody)
            .foregroundColor(AppColors.primaryText)
            .lineSpacing(4)
    }

    /// Secondary description text
    func cozyCaption() -> some View {
        self.font(.appCaption)
            .foregroundColor(AppColors.secondaryText)
            .lineSpacing(2)
    }

    // MARK: - Legacy Style Modifiers (for backwards compatibility)

    func appTitleStyle() -> Text {
        self.font(.appTitle)
            .foregroundColor(AppColors.primaryText)
    }

    func appLargeTitleStyle() -> Text {
        self.font(.appLargeTitle)
            .foregroundColor(AppColors.primaryText)
    }

    func appHeadlineStyle() -> Text {
        self.font(.appHeadline)
            .foregroundColor(AppColors.primaryText)
    }

    func appBodyStyle() -> Text {
        self.font(.appBody)
            .foregroundColor(AppColors.primaryText)
    }

    func appCaptionStyle() -> Text {
        self.font(.appCaption)
            .foregroundColor(AppColors.secondaryText)
    }

    func appSmallStyle() -> Text {
        self.font(.appSmall)
            .foregroundColor(AppColors.secondaryText)
    }
}

// MARK: - Font Extensions (backwards compatibility)

extension Font {
    /// Display title - 34pt, bold (new, for special moments)
    static let appDisplayTitle = Font.system(size: 34, weight: .bold, design: .rounded)

    /// App title - 28pt, bold
    static let appTitle = Font.system(size: 28, weight: .bold, design: .rounded)

    /// Title 2 - 26pt, semibold
    static let appTitle2 = Font.system(size: 26, weight: .semibold, design: .rounded)

    /// Large title - 24pt, semibold
    static let appLargeTitle = Font.system(size: 24, weight: .semibold, design: .rounded)

    /// Headline - 18pt, semibold (increased from 17pt)
    static let appHeadline = Font.system(size: 18, weight: .semibold, design: .rounded)

    /// Body - 16pt, regular
    static let appBody = Font.system(size: 16, weight: .regular, design: .rounded)

    /// Body bold - 16pt, semibold
    static let appBodyBold = Font.system(size: 16, weight: .semibold, design: .rounded)

    /// Caption - 13pt, regular (increased from 12pt)
    static let appCaption = Font.system(size: 13, weight: .regular, design: .rounded)

    /// Caption bold - 13pt, semibold
    static let appCaptionBold = Font.system(size: 13, weight: .semibold, design: .rounded)

    /// Small - 11pt, regular (increased from 10pt)
    static let appSmall = Font.system(size: 11, weight: .regular, design: .rounded)

    /// Small bold - 11pt, semibold
    static let appSmallBold = Font.system(size: 11, weight: .semibold, design: .rounded)

    /// Micro - 10pt, for badges and very small text
    static let appMicro = Font.system(size: 10, weight: .regular, design: .rounded)

    /// Micro bold - 10pt, bold
    static let appMicroBold = Font.system(size: 10, weight: .bold, design: .rounded)

    /// Emoji size - 12pt, for inline emojis
    static let appEmoji = Font.system(size: 12)

    /// Icon label - 14pt, medium weight
    static let appIconLabel = Font.system(size: 14, weight: .medium, design: .rounded)

    /// Icon label bold - 14pt, bold
    static let appIconLabelBold = Font.system(size: 14, weight: .bold, design: .rounded)
}

// MARK: - View Extensions

extension View {
    /// Apply tracking (letter spacing) to text
    func tracking(_ value: CGFloat) -> some View {
        self.kerning(value)
    }

    /// Apply leading (line height multiplier)
    func leading(_ value: CGFloat) -> some View {
        self.lineSpacing(value * 4) // Approximate conversion
    }
}
