//
//  TSRTLManage.swift
//  Pods
//
//  Created by 100Years on 2025/6/17.
//

public class TSRTLManage {
    
    public static let appLanguage: String = {
        let systemLanguages = UserDefaults.standard.value(forKey: "AppleLanguages")
        var currentLanguage: String?
        if let arr = systemLanguages as? [String] {
            currentLanguage = arr.first
        }
        else if let str = systemLanguages as? String {
            currentLanguage = str
        }
        return currentLanguage ?? ""
    }()
    
    static func isArabicSupported() -> Bool {
        // 获取项目支持的所有本地化语言,检查是否包含阿拉伯语（"ar"）
        return Bundle.main.localizations.contains("ar")
    }
    
    public static func setUpInit () {
        if kIsRTL {
            UIView.appearance().semanticContentAttribute = UISemanticContentAttribute.forceRightToLeft
        }
    }
    
    public static func isRTL () -> Bool {
        return appLanguage.hasPrefix("ar") && isArabicSupported()
    }
}

public var kIsRTL: Bool {
    return TSRTLManage.isRTL()
}

public extension UIImage {
    public var mirrored: UIImage {
        guard kIsRTL else {
            return self
        }
        return imageFlippedForRightToLeftLayoutDirection()
    }
}
