//
//  VKBookingViewController.swift
//  Em-call
//
//  Created by Alex Sh on 14.02.2022.
//

import UIKit

class VKBookingViewController: UIViewController {
 
    @IBOutlet weak var emergency: UILabel!
    @IBOutlet weak var worker: UILabel!
    @IBOutlet weak var workLocation: UILabel!
    @IBOutlet weak var date_time: UILabel!
    @IBOutlet weak var cost: UILabel!
    @IBOutlet weak var costType: UILabel!
    @IBOutlet weak var viewBut: UIView!
    
    @IBOutlet weak var butCost: UILabel!
    @IBOutlet weak var butPrice: UILabel!
    @IBOutlet weak var viewTop: UIView!
    @IBOutlet weak var buttonTop: UIButton!
    
    @IBAction func pressButtonTop(_ sender: Any) {
        guard let vc = storyboard?.instantiateViewController(withIdentifier: "Call_Prof")
        else { return  }
      //  (vc as! MainViewController).showWorkerMap = 1
          navigationController?.pushViewController(vc, animated: true)
    }
    
    @IBOutlet weak var segmentControl: UISegmentedControl!
    let cellReuseIdentifier = "cell"
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationItem.title = "BOOKING"
        segmentControl.addTarget(self, action: #selector(segmentAction(_:)), for: .valueChanged)
        viewBut.isHidden = true
        butCost.isHidden = true
        butPrice.isHidden = true
        viewTop.isHidden = false
        hideKeyboardWhenTappedAround()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        self.navigationController?.setNavigationBarHidden(false, animated: animated)
        self.navigationController?.navigationItem.hidesBackButton = true
        //navigationItem.hidesBackButton = true
        self.navigationController?.navigationBar.topItem?.title = "BOOKING"
        self.navigationController?.navigationItem.title = "BOOKING"
        self.navigationController?.navigationBar.titleTextAttributes = [.foregroundColor : UIColor.black]
        self.navigationController?.navigationBar.barTintColor = UIColor.white
        let item1 = setBarButtom(str: "akar-icons_arrow-left")
        self.navigationItem.setLeftBarButtonItems([item1], animated: true)

       let item2 = setBarButtom(str: "gg_close")
       self.navigationItem.setRightBarButtonItems([item2], animated: true)
        
    }
    
    func setBarButtom(str:String)->UIBarButtonItem {
        let btn1 = UIButton(type: .custom)
         btn1.setImage(UIImage(named: str), for: .normal)
         btn1.frame = CGRect(x: 0, y: 0, width: 60, height: 60)
         btn1.addTarget(self, action: #selector(self.back), for: .touchUpInside)
         let item1 = UIBarButtonItem(customView: btn1)
        return item1
    }
    @objc
    func back() {
        navigationController?.popViewController( animated: true)
    }
    
    @objc func segmentAction(_ segmentedControl: UISegmentedControl) {
            switch (segmentedControl.selectedSegmentIndex) {
            case 0:
              //tableViewWork.isHidden = true
                workLocation.text = "22 Dorlan ave, Manchester"
                date_time.text = "As soon as possible"
                cost.text = "$100"
                costType.text = "Approximate price"
                viewBut.isHidden = true
                butCost.isHidden = true
                butPrice.isHidden = true
                break // Uno
            case 1:
                viewBut.isHidden = false
                workLocation.text = "22 Dorlan ave"
                date_time.text = "18 feb, 18:00"
                cost.text = "$200"
                costType.text = "Total price"
                butCost.isHidden = false
                butPrice.isHidden = false
                break // Dos
 
            default:
                break
            }
        }


}
