//
//  SQTextModifiers.swift
//  Allovoisins
//
//  Created by Claude on 22/10/2025.
//  Copyright © 2025 AlloVoisins. All rights reserved.
//

import SwiftUI

// MARK: - Font Modifier

private struct SQFontModifier: ViewModifier {
    let font: SQTextFont
    @Environment(\.sqTextConfiguration) var config

    func body(content: Content) -> some View {
        var newConfig = config
        newConfig.font = font
        return content.environment(\.sqTextConfiguration, newConfig)
    }
}

extension View {
    /// Sets the font weight for the text.
    ///
    /// - Parameter font: The font weight to apply (.regular, .medium, .semiBold, .bold)
    /// - Returns: A view with the font configuration applied
    func sqFont(_ font: SQTextFont) -> some View {
        modifier(SQFontModifier(font: font))
    }
}

// MARK: - Size Modifier

private struct SQSizeModifier: ViewModifier {
    let size: CGFloat
    @Environment(\.sqTextConfiguration) var config

    func body(content: Content) -> some View {
        var newConfig = config
        newConfig.size = size
        return content.environment(\.sqTextConfiguration, newConfig)
    }
}

extension View {
    /// Sets the font size for the text.
    ///
    /// - Parameter size: The font size in points
    /// - Returns: A view with the size configuration applied
    func sqSize(_ size: CGFloat) -> some View {
        modifier(SQSizeModifier(size: size))
    }
}

// MARK: - Color Modifier

private struct SQColorModifier: ViewModifier {
    let textColor: Color
    @Environment(\.sqTextConfiguration) var config

    func body(content: Content) -> some View {
        var newConfig = config
        newConfig.textColor = textColor
        return content.environment(\.sqTextConfiguration, newConfig)
    }
}

extension View {
    /// Sets the text color.
    ///
    /// - Parameter textColor: The color to apply to the text
    /// - Returns: A view with the color configuration applied
    func sqColor(_ textColor: Color) -> some View {
        modifier(SQColorModifier(textColor: textColor))
    }
}
