//
//  TabVC.swift
//  Garmentoo
//
//  Created by Vijith on 31/05/22.
//

import UIKit

class TabVC: UITabBarController {
    
//    let arrayOfImageNameForUnselectedState = ["home","fav","cart","setting","searchinactive"]
//
    let arrayOfImageNameForUnselectedState = ["lightHome","lightFav","lightCart","lightSettings","lightSearch"]
 
// let arrayOfImageNameForUnselectedStateDark = ["homedark","favdark","cartdark","settingdark","searchdark"]

    let arrayOfImageNameForUnselectedStateDark = ["darkHome","darkFav","darkCart","darkSettings","darkSearch"]
    
//    let arrayOfImageNameForSelectedState = ["activeHome","activeFav","cart3","activeSetting","searchactive"]
    let arrayOfImageNameForSelectedState = ["activeHome_","activeFav_","activeCart_","activeSettings_","activeSearch_"]

    override func viewDidLoad() {
           super.viewDidLoad()

        setTabBar()

         //  let titlesArray = ["Home","About Us"]

           // Do any additional setup after loading the view.

    }
   
        
        
    
    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
        setTabBar()
    }
    
    func setTabBar()
    {
        
        if let count = self.tabBar.items?.count {
            for i in 0...(count-1) {
             
             // for light mode
                let imageNameForSelectedState   = arrayOfImageNameForSelectedState[i]
             
             // for dark mode
             let imageNameForUnselectedStateDark   = arrayOfImageNameForUnselectedStateDark[i]
             
                let imageNameForUnselectedState = arrayOfImageNameForUnselectedState[i]


                //self.tabBar.items?[i].title = titlesArray[i]
             

                self.tabBar.items?[i].selectedImage = UIImage(named: imageNameForSelectedState )?.withRenderingMode(.alwaysOriginal)

             
             if #available(iOS 13, *) {
             switch traitCollection.userInterfaceStyle {
             case .dark:
                 self.tabBar.items?[i].image = UIImage(named: imageNameForUnselectedStateDark )?.withRenderingMode(.alwaysOriginal)
             default:
                 self.tabBar.items?[i].image = UIImage(named: imageNameForUnselectedState )?.withRenderingMode(.alwaysOriginal)
             }
            }
             else{
                 self.tabBar.items?[i].image = UIImage(named: imageNameForUnselectedState )?.withRenderingMode(.alwaysOriginal)
                 
             }
        }
 

        }
    }
}
