//
//  StartViewController.swift
//  Em-call
//
//  Created by Alex Sh on 20.02.2022.
//

import UIKit

class StartViewController: UIViewController {
    var net:network = network()
    var showAlert:ShowAlert=ShowAlert()
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
    @IBOutlet weak var teleNumber: UITextField!
    @IBOutlet weak var password: UITextField!
    
    @IBAction func pressEnter(_ sender: Any) {
      if  let number = teleNumber.text,
          let psw = password.text  {
        if number == "" || psw == ""{
            DispatchQueue.main.async {
                    let alert = UIAlertController(title: "Warning", message: "<Phone> or <Password> is empty", preferredStyle: .alert)
                 alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                    self.present(alert, animated: true)
                 }
            return
        } else {
        //debug
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
                var vc:UINavigationController
          //  let tabBar = storyboard.instantiateViewController(withIdentifier: "TabBar")
          vc = storyboard.instantiateViewController(withIdentifier: "StartNavigationVC") as! UINavigationController
          //  vc = UINavigationController.init(rootViewController: tabBar)
           // vc.pushViewController(tabBar, animated: true)
            self.present(vc, animated: true)
           // self.present(tabBar, animated: true)
        }
        /*
        let status = net.reqPostEnter(phone: number,code: psw)
        if (status > 299) //|| (status == 0)
        {
          //  showAlert.showAlertSample(title: "Warning", message: "Error!")
            DispatchQueue.main.async {
                    let alert = UIAlertController(title: "Warning", message: "<Phone> is empty", preferredStyle: .alert)
                 alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                    self.present(alert, animated: true)
                 }

        } else {
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
                    var vc:UIViewController
                    vc = storyboard.instantiateViewController(withIdentifier: "TabBar")
                     navigationController?.pushViewController(vc, animated: true)
        }
        */
      }
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
