//
//  WA_TabbarCommon.swift
//  wallpaper_project
//
//  Created by 忆海16 on 2024/3/11.
//

import UIKit
import CYLTabBarController

class WA_TabbarCommon: NSObject {
    /// MARK: 切换跳转主界面
    class func tabBarSelectIndex(_ selectIndex: Int) {
//        WA_TabButton.register()
        let tabBarController = WA_RootTab(viewControllers: viewControllers(), tabBarItemsAttributes: tabBarItemsAttributesForController())

        
        tabBarController.selectedIndex = selectIndex;
        let appDelegate = UIApplication.shared.delegate
        appDelegate?.window??.rootViewController = tabBarController
    }
    
    /// MARK: 切换跳转主界面 操作其他事件
    class func completionhandler(_ selectIndex: Int, _: () ->())  {
        tabBarSelectIndex(selectIndex)
    }
    
    /// MARK: 进入APP
    class func enterApp(_ : () -> ()) {
        TabBarController()
    }
    
    /// MARK: 创建根视图
    class func TabBarController() {
//        WA_TabButton.register()
        let appDelegate = UIApplication.shared.delegate
        appDelegate?.window??.rootViewController = WA_RootTab(viewControllers: viewControllers(), tabBarItemsAttributes: tabBarItemsAttributesForController())
        let tabBarController = WA_RootTab()
        tabBarController.cyl_tabBarController.tabBar.backgroundColor = .white
        tabBarController.tabBar.shadowImage = UIImage()
        tabBarController.tabBar.backgroundImage = UIImage()
    }
    
    
    class  func viewControllers() -> [WA_RootNAV]{
        
            //首页
        let home = WA_RootNAV(rootViewController: WA_NewHomeVC())
        home.tabBarItem.imageInsets = UIEdgeInsets.init(top: 30, left: 0, bottom: 30, right: 0)
        
        home.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.hexSting(color: "#28D36C", alpha: 1)], for: .selected)
        
        let rank = WA_RootNAV(rootViewController: WA_RankingVC())
        rank.tabBarItem.imageInsets = UIEdgeInsets.init(top: 11, left: 0, bottom: 11, right: 0)
        
        rank.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.hexSting(color: "#28D36C", alpha: 1)], for: .selected)
        
        
        
        let mine = WA_RootNAV(rootViewController: WA_MineVC())
        mine.tabBarItem.imageInsets = UIEdgeInsets.init(top: 30, left: 0, bottom: 30, right: 0)
        mine.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.hexSting(color: "#28D36C", alpha: 1)], for: .selected)
        
        
            let viewControllers = [home,rank,mine]
        
  
            
            
            return viewControllers
        
    }
    
    class  func tabBarItemsAttributesForController() ->  [[String : String]] {
        
        
        let tabBarItemOne = [CYLTabBarItemTitle:"Home",
                             CYLTabBarItemImage:"home_n",
                             CYLTabBarItemSelectedImage:"home_s"]
        
        let tabBarItemrank = [CYLTabBarItemTitle:"Community",
                             CYLTabBarItemImage:"ranking_n",
                             CYLTabBarItemSelectedImage:"ranking_s"]
        
        let tabBarItemtwo = [CYLTabBarItemTitle:"Setting",
                             CYLTabBarItemImage:"mine_n",
                             CYLTabBarItemSelectedImage:"mine_s"]
        

        let tabBarItemsAttributes = [tabBarItemOne,tabBarItemrank,tabBarItemtwo]
//
        
         return tabBarItemsAttributes
    }
    

}
