//
//  WOGlassesConfiguratorTabBarController.swift
//  iPOS
//
//  Created by Zoran Albu on 1/10/19.
//  Copyright © 2019 BBC. All rights reserved.
//

import Foundation
import UIKit

class WOGlassesConfiguratorTabBarController: UITabBarController, UITabBarControllerDelegate {
    
    var workOrderConfiguratorViewController: WorkOrderConfiguratorViewController!
    var technicalDataViewController: TechnicalDataViewController!
    var technicalDataSecondViewController: TechnicalDataSecondViewController!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.delegate = self
        
        self.title = Util.getString("Configurator")
        self.createTabBarController()
        self.setTabBarItemTitle()
        self.createSaveButton()
        self.createLeftBackButton()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    func createTabBarController(){
        self.viewControllers?[0] = self.workOrderConfiguratorViewController
        self.viewControllers?[1] = self.technicalDataViewController
        self.viewControllers?[2] = self.technicalDataSecondViewController
    }
    
    func setTabBarItemTitle(){
        self.tabBar.items?[0].title = Util.getString("SingleGlasses")
        self.tabBar.items?[1].title = Util.getString("TechnicalData")
        self.tabBar.items?[2].title = Util.getString("Others")
    }
    
    func createLeftBackButton(){
        self.navigationItem.leftBarButtonItem = self.viewControllers?[0].navigationItem.leftBarButtonItem
    }
    
    
    func createSaveButton(){
        self.navigationItem.rightBarButtonItem = self.viewControllers?[0].navigationItem.rightBarButtonItem
    }
    
    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        self.technicalDataViewController.orderDetailGlasses = self.workOrderConfiguratorViewController.orderDetailGlasses
        self.technicalDataViewController.clinicalStatus = self.workOrderConfiguratorViewController.clinicalStatus
        self.technicalDataSecondViewController.orderDetailGlasses = self.workOrderConfiguratorViewController.orderDetailGlasses
        self.technicalDataSecondViewController.clinicalStatus = self.workOrderConfiguratorViewController.clinicalStatus
        
        return true
    }
}
