import UIKit

enum Theme {

    // MARK: - Colors

    enum Color {
        static let primary      = UIColor(hex: "#7AD4D1")
        static let secondary    = UIColor(hex: "#5D7D7B")
        static let success      = UIColor(hex: "#34C759")
        static let background   = UIColor(hex: "#F3F3F8")
        static let card         = UIColor.white
        static let textPrimary  = UIColor(hex: "#1A1A2E")
        static let textSecondary = UIColor(hex: "#8E8E93")
    }

    // MARK: - Font Sizes

    enum FontSize {
        static let title: CGFloat    = 24
        static let subtitle: CGFloat = 18
        static let body: CGFloat     = 16
        static let caption: CGFloat  = 12
    }

    // MARK: - Fonts

    enum Font {
        static func title(weight: UIFont.Weight = .bold) -> UIFont {
            .systemFont(ofSize: FontSize.title, weight: weight)
        }
        static func subtitle(weight: UIFont.Weight = .semibold) -> UIFont {
            .systemFont(ofSize: FontSize.subtitle, weight: weight)
        }
        static func body(weight: UIFont.Weight = .regular) -> UIFont {
            .systemFont(ofSize: FontSize.body, weight: weight)
        }
        static func caption(weight: UIFont.Weight = .regular) -> UIFont {
            .systemFont(ofSize: FontSize.caption, weight: weight)
        }
    }
}

// MARK: - UIColor hex initializer

private extension UIColor {
    convenience init(hex: String) {
        var sanitized = hex.trimmingCharacters(in: .whitespacesAndNewlines)
        if sanitized.hasPrefix("#") { sanitized.removeFirst() }

        var rgb: UInt64 = 0
        Scanner(string: sanitized).scanHexInt64(&rgb)

        let r = CGFloat((rgb >> 16) & 0xFF) / 255
        let g = CGFloat((rgb >>  8) & 0xFF) / 255
        let b = CGFloat( rgb        & 0xFF) / 255
        self.init(red: r, green: g, blue: b, alpha: 1)
    }
}
