//
//  BsConstant.swift
//  BaiSiSMApp
//
//  Created by davidhuang on 2022/10/19.
//  Copyright © 2022 www.davidhuang.com. All rights reserved.
//

import UIKit

// MARK: - 工程中的 常量定义

let APP_NAME = Bundle.main.infoDictionary!["CFBundleName"] as! String

/// 打印
///
/// - Parameters:
///   - message: 打印内容
///   - file: 所在文件
///   - method: 所在方法
///   - line: 所在行
public func printLog<T>(_ message: T, file: String = #file, method: String = #function, line: Int = #line) {
#if DEBUG
    print("\n开始一段日志输出=========>\n[文件]:\((file as NSString).lastPathComponent)\n[所在行]:\(line)\n[方法名称]:\(method)\n[打印信息]:\(message)\n结束该段日志输出<=========")
#endif
}

//边距
let kMargin : CGFloat = 16.0

//圆角
let kCornerRadius6 : CGFloat = 6.0
let kCornerRadius8 : CGFloat = 8.0




///屏幕宽度
let KScreenWidth = UIScreen.main.bounds.size.width
///屏幕高度
let KScreenHeight = UIScreen.main.bounds.size.height
///导航栏高度
let k_Height_NavContentBar :CGFloat = 44.0
/** 状态栏高度 */
let k_Height_StatusBar :CGFloat = k_Height_statusBar()
/** 状态栏+导航栏的高度 */
let k_Height_NavigationtBarAndStatuBar: CGFloat = k_Height_NavContentBar + k_Height_StatusBar
/** 底部tabBar栏高度（不包含安全区，即：在 iphoneX 之前的手机） */
let k_TabBar_Height :CGFloat = 49.0
/** 底部导航栏高度（包括安全区），一般使用这个值 */
let k_Height_TabBar :CGFloat = k_Height_safeAreaInsetsBottom() + k_TabBar_Height

// MARK: - 尺寸信息： -
/* 状态栏高度  20 或 44 */
// 然而从iOS 14开始，全面屏iPhone的状态栏高度不一定是 44 或 20 了，比如下面就是这些设备在iOS 14.1上的状态栏高度。（还可能时47、48）
/// ①、顶部状态栏高度（包括安全区）
func k_Height_statusBar() -> CGFloat {
    var statusBarHeight: CGFloat = 0;
    if #available(iOS 13.0, *) {
        let scene = UIApplication.shared.connectedScenes.first
        guard let windowScene = scene as? UIWindowScene else {return 0};
        guard let statusBarManager = windowScene.statusBarManager else {return 0}
        statusBarHeight = statusBarManager.statusBarFrame.height
    } else {
        statusBarHeight = UIApplication.shared.statusBarFrame.height
    }
    return statusBarHeight;
}

/// ②、顶部安全区高度 k_Height_safeAreaInsetsTop
func k_Height_safeAreaInsetsTop() -> CGFloat {
    if #available(iOS 13.0, *) {
        let scene = UIApplication.shared.connectedScenes.first
        guard let windowScene = scene as? UIWindowScene else {return 0} // guard：如果 expression 值计算为false，则执行代码块内的 guard 语句。(必须包含一个控制语句: return、 break、 continue 或 throw。)。as?：类型转换，(还有这两种：as、as!)
        guard let window = windowScene.windows.first else {return 0};
        return window.safeAreaInsets.top;
    }
    return 0
}

/// ③、底部安全区高度
func k_Height_safeAreaInsetsBottom() -> CGFloat {
    if #available(iOS 13.0, *) {
        let scene = UIApplication.shared.connectedScenes.first;
        guard let windowScene = scene as? UIWindowScene else {return 0};
        guard let window = windowScene.windows.first else {return 0};
        return window.safeAreaInsets.bottom;
    }
    return 0;
}

///获取系统版本号
func IOSVersion() -> Double {
    return (UIDevice.current.systemVersion as NSString).doubleValue
}
///组件化用类名创建控制器
func ClassFromString(className: String) -> UIViewController? {
    let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleName")
    
    let name = "\(appName!).\(className)"
    if let tmpClass = NSClassFromString(name) as? UIViewController.Type {
        return tmpClass.init()
    } else {
        return nil
    }
}

/** 判断字符串是否为空 */
func kIsEmpty(string: String) -> Bool {
    if string.isEmpty || string == "" {
        return true
    }else {
        return false
    }
}

/**  文字大小设置
 *  parameter name 字体名字 (为空时默认字体)
 *  parameter size 字体大小
 */
func kFont(name: String = "", size: CGFloat) -> UIFont {
    if !kIsEmpty(string: name) {
        return UIFont.init(name: name, size: size)!
    }else {
        return UIFont.systemFont(ofSize: size)
    }
}

func kBoldFont(name: String = "", size: CGFloat) -> UIFont {
    if !kIsEmpty(string: name) {
        return UIFont.init(name: name, size: size)!
    }else {
        return UIFont.boldSystemFont(ofSize: size)
    }
}

/// 版本号相同：
func systemVersionEqual(version:String) -> Bool {
    return UIDevice.current.systemVersion == version
}

/// 系统版本高于等于该version  测试发现只能传入带一位小数点的版本号  不然会报错    具体原因待探究
func systemVersionGreaterThan(version:String) -> Bool {
    return UIDevice.current.systemVersion.compare(version, options: .numeric, range: version.startIndex..<version.endIndex, locale: Locale(identifier:version)) != ComparisonResult.orderedAscending
}

//判断是否是 x、及x以上 系列
func isIphoneX() -> Bool {
    return k_Height_safeAreaInsetsBottom() > 0.0 // 底部安全区 > 0 时，
}

class YhConstant {
    // MARK: -  URL 相关
    struct URL {
        
        // MARK: - 帮助与反馈
        static let userQAUrl = YHBaseUrlManager.shared.h5URL() + "landing/index.html#/pages/my/index"
        
        // MARK: - 优眠用户注销条款
        static let userUnregisterURL = "https://www.baidu.com"
        
        // MARK: - 隐私政策
        static let privacyURL = YHBaseUrlManager.shared.h5URL() + "landing/index.html#/subpages/personal/pages/protocol/index?classify=privacy"
        
        // MARK: - 用户协议
        static let userProtocalURL = YHBaseUrlManager.shared.h5URL() + "landing/index.html#/subpages/personal/pages/protocol/index?classify=agreement"
    }
    
    
    
    
    
    
    // MARK: - 登录信息
    static let KLoginedInfoKey = "KLoginedInfoKey"
    
    
}

extension YhConstant {
    // MARK: - 友盟相关
    struct Wechat {
        static let appKey = "wx57b2a7469d15ff8f"
        static let AppSecret = "e0a351290c66c05f85c54a31b213c1aa"
    }
    
    struct UM {
        static let appKey = "5a77b807a40fa30f0300008b"
    }
    
    // MARK: - 支付宝
    struct Alipay {
        // MARK: - 阿里云 手机号一键登录 秘钥信息
        static let kAliOnePressPhoneLoginKey = "MuKKbWPm4DRHmZpgASqjI3L1HtiOlxyKWmocGnJhbiibdfaKlwYUj8ISgOexPHLAUAhdo6NNIGOi8oCAeqA1PO9b4ea3YwHXKnIa2u7BCTkd5L4IswsGgljfBeGIyRhoFCnCibix7RwQEqhrkdZ2KMsE/NtPrXfi+EU3oAnO9tXIztzvpAe75Pna2mUKMvO1qt4SSmPe4VnEOX5LCdbn7sGAvOLN8/l/fcCdEU7FA+AGLTY+547jlwan3wyJYJn0Sc8qnEW9LBxRwTDpEZPqyg=="
    }
    
    // MARK: -  通知相关 名称
    class YhNotification {
        //登录成功
        public static let didLoginSuccessNotifiction = Notification.Name(rawValue: "com.usleep.health.login.success")
        
        //退出成功
        public static let didLoginoutSuccessNotifiction = Notification.Name(rawValue: "com.usleep.health.loginout.success")
        
        
        //token 过期
        public static let tokenInvalidateNotifiction = Notification.Name(rawValue: "com.usleep.health.token.invalidate")
    }
}
