//
//  MainTabBarController.swift
//  OrderScheduling
//
//  Created by 中道 on 2023/8/4.
//

import Foundation
import DDCategoryKit_Private
import ESTabBarController_swift
import DDColorKit_Private
import DDFontKit_Private
import DDControlsKit_Private

open class MainTabBarController : ESTabBarController {
    
    open override func viewDidLoad() {
        super.viewDidLoad()
        let v1 = DDNavigationController(rootViewController: RescueController.init())
        let v2 = DDNavigationController(rootViewController: ReviewFailedController.init())
        let v3 = DDNavigationController(rootViewController: HistoryController.init())
        let v4 = DDNavigationController(rootViewController: VehicleMonitoringController.init())
        let v5 = DDNavigationController(rootViewController: MineController.init())

        v1.tabBarItem = ESTabBarItem.init(MainTabBarItemContentView(), title: "救援中", image: UIImage(named: "tabBar_jiuyuanzhong_unselected"), selectedImage: UIImage(named: "tabBar_jiuyuanzhong_selected"))
        v2.tabBarItem = ESTabBarItem.init(MainTabBarItemContentView(), title: "审核失败", image: UIImage(named: "tabBar_shenhe_unselected"), selectedImage: UIImage(named: "tabBar_shenhe_selected"))
        v3.tabBarItem = ESTabBarItem.init(MainTabBarItemContentView(), title: "历史", image: UIImage(named: "tabBar_lishi_unselected"), selectedImage: UIImage(named: "tabBar_lishi_selected"))
        v4.tabBarItem = ESTabBarItem.init(MainTabBarItemContentView(), title: "车辆监控", image: UIImage(named: "tabBar_cheliangjiankong_unselected"), selectedImage: UIImage(named: "tabBar_cheliangjiankong_selected"))
        v5.tabBarItem = ESTabBarItem.init(MainTabBarItemContentView(), title: "我的", image: UIImage(named: "tabBar_wode_unselected"), selectedImage: UIImage(named: "tabBar_wode_selected"))
        self.viewControllers = [v1, v2, v3, v4, v5]
        
        if let tabBar = tabBar as? ESTabBar {
            tabBar.itemCustomPositioning = .centered
            tabBar.backgroundColor = .white
            
            tabBar.shadowImage = UIImage()
            tabBar.backgroundImage = UIImage()
        }
    }

    open override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

    }
}

class MainTabBarItemContentView : ESTabBarItemContentView{
    override init(frame: CGRect) {
        super.init(frame: frame)
        renderingMode = .alwaysOriginal
        itemContentMode = .alwaysOriginal

        textColor = .hex("000000").alpha(0.55)
        highlightTextColor = .hex("545F7D")
        backdropColor = .white
        highlightBackdropColor = .white
        titleLabel.font = .mediumFont(13)
        
    }

    override func updateLayout() {
        super.updateLayout()
    }

    public required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

