//
//  BaseTabbarViewController.swift
//  RainbowPlanet
//
//  Created by 南鑫林 on 2019/3/8.
//  Copyright © 2019 南鑫林. All rights reserved.
//

import UIKit

class BaseTabbarViewController: UITabBarController {
    private static let _sharedInstance = BaseTabbarViewController()

    class func shared() -> BaseTabbarViewController {
        return _sharedInstance
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    //MARK: - lazy
    public lazy var tabBarViewController: BaseTabbarViewController = {

        let tabBarViewController = BaseTabbarViewController()

        let v1 = ShoppingMallViewController()
        let v2 = ShoppingCartViewController()
        let v3 = MineViewController()

        let n1 = BaseNavigationViewController.init(rootViewController: v1)
        let n2 = BaseNavigationViewController.init(rootViewController: v2)
        let n3 = BaseNavigationViewController.init(rootViewController: v3)

        tabBarItemStyle(navc: n1, normalImg: "tab_home_icon_normal", selectorImg: "tab_home_icon_selected", title: "首页")
        tabBarItemStyle(navc: n2, normalImg: "tab_shopping_icon_normal", selectorImg: "tab_shopping_icon_selected", title: "逛街")
        tabBarItemStyle(navc: n3, normalImg: "tab_me_icon_normal", selectorImg: "tab_me_icon_selected", title: "我的")

        tabBarViewController.viewControllers = [n1, n2, n3]

        return tabBarViewController

    }()


    private func tabBarItemStyle(navc : UINavigationController, normalImg : String, selectorImg : String, title : String){
        navc.tabBarItem = UITabBarItem.init(title: title, image: UIImage(named:normalImg), selectedImage: UIImage(named:selectorImg))
        navc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor:UIColor.gray], for: UIControl.State.normal)
        navc.tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor:UIColor.blue], for: UIControl.State.selected)

    }

}
