//
//  WP_TabbarCommon.swift
//  WallpaperHD_Live


import UIKit
import CYLTabBarController

class WP_TabbarCommon: NSObject {
    /// MARK: 切换跳转主界面
    class func tabBarSelectIndex(_ selectIndex: Int) {
//        WP_TabButton.register()
        let tabBarController = WP_TabBarVC(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() {
//        WP_TabButton.register()
        let appDelegate = UIApplication.shared.delegate
        appDelegate?.window??.rootViewController = WP_TabBarVC(viewControllers: viewControllers(), tabBarItemsAttributes: tabBarItemsAttributesForController())
        let tabBarController = WP_TabBarVC()
        tabBarController.cyl_tabBarController.tabBar.backgroundColor = .white
        tabBarController.tabBar.shadowImage = UIImage()
        tabBarController.tabBar.backgroundImage = UIImage()
    }
    
    
    class  func viewControllers() -> [WP_RootNAV]{
        
            //首页
        let home = WP_RootNAV(rootViewController: WP_HomeVC())
        home.tabBarItem.imageInsets = UIEdgeInsets.init(top: 20, left: 0, bottom: 20, right: 0)
        
        home.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.hexSting(color: "#2c2c2c", alpha: 1)], for: .selected)
        
        let rank = WP_RootNAV(rootViewController: WP_RankingVC())
        rank.tabBarItem.imageInsets = UIEdgeInsets.init(top: 20, left: 0, bottom: 20, right: 0)
        
        rank.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.hexSting(color: "#2c2c2c", alpha: 1)], for: .selected)
        
        
        
        let mine = WP_RootNAV(rootViewController: WP_MineVC())
        mine.tabBarItem.imageInsets = UIEdgeInsets.init(top: 20, left: 0, bottom: 20, right: 0)
        mine.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.hexSting(color: "#2c2c2c", 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:"Ranking",
                             CYLTabBarItemImage:"rank_n",
                             CYLTabBarItemSelectedImage:"rank_s"]
        
   
        
        let tabBarItemtwo = [CYLTabBarItemTitle:"Setting",
                             CYLTabBarItemImage:"mine_n",
                             CYLTabBarItemSelectedImage:"mine_s"]
        

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

}
