//
//  Common.swift
//  SpeakEasyLearnEnglish
//
//  Created by edy on 2025/7/3.
//

import UIKit

struct Dev {
    static let screenW = UIScreen.main.bounds.size.width
    static let screenH = UIScreen.main.bounds.size.height
    static let navHeight:CGFloat = 44
    static let tabHeight = 49
    static let safeAreaInsets:UIEdgeInsets = SpWindow.safeAreaInsets
}

let SpWindow:UIWindow = {
    if #available(iOS 13, *) {
        return UIApplication.shared.connectedScenes
            .compactMap { $0 as? UIWindowScene }
            .first?.windows.first ?? UIWindow()
    } else {
        return UIApplication.shared.keyWindow ?? UIWindow()
    }
}()

public func Print(_ items: Any...,
                  file: String = #file,
                  line: Int = #line,
                  function: String = #function) {
    #if DEBUG
    let fileURL = URL(fileURLWithPath: file).lastPathComponent
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "HH:mm:ss.SSS"
    let timestamp = dateFormatter.string(from: Date())
    let output = items.map { "\($0)" }.joined(separator: " ")
    print("[\(timestamp)] \(fileURL):\(line) \(function) \n\t\(output)\n")
    #else
    #endif
}

/// 状态栏高度
var statusBarHeight: CGFloat {
//        UIApplication.shared.statusBarFrame.height
    UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0.00
    
}
/// 导航栏高度
var naviBarHeight: CGFloat {
    UINavigationController().navigationBar.frame.size.height
}

/// Tabbar高度
var tabbarHeight: CGFloat {
    49.0 + tabbarSpace
}
/// Tabbar安全区域高度
var tabbarSpace: CGFloat {
    isIphoneNotch ? 34 : 0
}

/// 是否刘海屏
var isIphoneNotch: Bool {
    statusBarHeight > 20
}
