//
//  FontFamily.swift
//  TheNoiseClock
//
//  Created by Matt Bruce on 9/11/25.
//
import Foundation
import SwiftUI

enum FontFamily: String, CaseIterable {
    case system = "System"
    case helvetica = "Helvetica"
    case arial = "Arial"
    case timesNewRoman = "TimesNewRomanPS"
    case georgia = "Georgia"
    case verdana = "Verdana"
    case courier = "Courier"
    case avenir = "Avenir"

    init?(rawValue: String) {
        switch rawValue {
        case "System": self = .system
        case "Helvetica": self = .helvetica
        case "Arial": self = .arial
        case "Times New Roman": self = .timesNewRoman
        case "Georgia": self = .georgia
        case "Verdana": self = .verdana
        case "Monaco", "Courier": self = .courier
        case "Avenir": self = .avenir
        default: self = .system
        }
    }
    
    var percentageDownsize: CGFloat {
        switch self {
        case .system:
            return 0.95
        case .georgia:
            return 0.90
        default: return 1
        }
    }
    
    var fontWeights: [Font.Weight] {
        guard let weightDict = Self.fontMapWeights[self.rawValue] else {
            return []
        }
        return Array(weightDict.keys)
    }
    
    func fontName(weight: Font.Weight) -> String? {
        guard let weightDict = Self.fontMapWeights[self.rawValue],
              let fontName = weightDict[weight] else {
            return nil
        }
        return fontName
    }
    
    static internal var fontMapWeights: [String: [Font.Weight: String]] = [
        FontFamily.helvetica.rawValue: [
            .regular: "Helvetica",
            .light: "Helvetica-Light",
            .bold: "Helvetica-Bold"
        ],
        FontFamily.arial.rawValue: [
            .regular: "ArialMT",
            .bold: "Arial-BoldMT"
        ],
        FontFamily.timesNewRoman.rawValue: [
            .regular: "TimesNewRomanPSMT",
            .bold: "TimesNewRomanPS-BoldMT"
        ],
        FontFamily.georgia.rawValue: [
            .regular: "Georgia",
            .bold: "Georgia-Bold"
        ],
        FontFamily.verdana.rawValue: [
            .regular: "Verdana",
            .bold: "Verdana-Bold"
        ],
        FontFamily.courier.rawValue: [
            .regular: "Courier",
            .bold: "Courier-Bold"
        ],
        FontFamily.avenir.rawValue: [
            .regular: "Avenir-Roman",
            .bold: "Avenir-Bold"
        ],
    ]

}
