//
//  AppDelegate.swift
//  galaxy
//
//  Created by davidhuangA on 2023/12/19.
//

import UIKit
import ESTabBarController_swift
import IQKeyboardManagerSwift
import SmartCodable

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        //1.设置主窗口
        setupRootVC()
        
        //2.通用UI设置
        setupWholeUI()
        return true
    }
}


extension AppDelegate {
    
    //2.通用全局UI设置相关
    private func setupWholeUI() -> Void {
        
        DispatchQueue.global().async {
            //异步延迟设置
            DispatchQueue.main.asyncAfter(wallDeadline: .now() + 0.25) { [self] in
                //1、系统控件属性设置
                //1.1
                UITextField.appearance().tintColor = .mainColor
                UITextView.appearance().tintColor = .mainColor
                
                //1.2设置UINavigationBar title的字体和颜色
                let titleTextAttributes = [NSAttributedString.Key.font : UIFont.PFSCM(ofSize: 16) , NSAttributedString.Key.foregroundColor : UIColor.commonColor100]
                UINavigationBar.appearance().titleTextAttributes = titleTextAttributes
                UINavigationBar.appearance().tintColor = .white
                
                //1.3UITabBar bar 的选中颜色
                UITabBar.appearance().tintColor = UIColor.commonColor100
                //1.4tabbar默认的背景色
                UITabBar.appearance().barTintColor = UIColor.white
                
                
                //2、一键登录初始化
                //                TXCommonHandler.sharedInstance().setAuthSDKInfo(BsConstant.kAliOnePressPhoneLoginKey)
                
                //3.微信登录初始化
                //                BsWxLoginManager.shared.doWxInit()
                
                //4.
                IQKeyboardManager.shared.enable = true
                IQKeyboardManager.shared.enableAutoToolbar = false
                IQKeyboardManager.shared.shouldResignOnTouchOutside = true // 控制点击背景是否收起键盘
                
                //webView 预加载
                //                BsWebViewPreloadManager.share.addPreloadingView()
                
                //
                customAppearance()
            }
        }
        
        YHNetworkStatusManager.shared.listenNetWorkStatus()
        
    }
    
    //1.设置主窗口
    private func setupRootVC() {
        let tabBarController = YHTabBarViewController()
        let v1 = YHNavigationController(rootViewController: YHIntelligentServiceViewController())
        let v2 = YHNavigationController(rootViewController:YHMyViewController())
        
        v1.tabBarItem = ESTabBarItem.init(YHBasicContentView(),title: "智慧服务", image: UIImage(named: "home"), selectedImage: UIImage(named: "home_1"))
        v2.tabBarItem = ESTabBarItem.init(YHBasicContentView(),title: "我的", image: UIImage(named: "find"), selectedImage: UIImage(named: "find_1"))
        
        tabBarController.viewControllers = [v1, v2]
        tabBarController.tabBar.backgroundColor = .white
        
        
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = tabBarController
        window?.makeKeyAndVisible()
        window?.backgroundColor = .white
        
        //处理数据解析
#if DEBUG
        SmartConfig.debugMode = .verbose
#else
        SmartConfig.debugMode = .none
#endif
    }
}


