//
//  ChangePswViewController.swift
//  Em-call
//
//  Created by Alex Sh on 22.02.2022.
//

import UIKit

class ChangePswViewController: UIViewController {

    @IBOutlet weak var newPsw: UITextField!
    @IBOutlet weak var retryNewPsw: UITextField!
    @IBOutlet weak var smsCode: UILabel!
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    
    @IBAction func sendNewPassword(_ sender: Any) {
        if newPsw.text == "" || retryNewPsw.text == "" {
            DispatchQueue.main.async {
                   let alert = UIAlertController(title: "Warning", message: "<New Password> or <Retry new password> is empty", preferredStyle: .alert)
                alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                   self.present(alert, animated: true)
                }
           // _  = self.navigationController?.popViewController( animated: true)
            return
        }
        if newPsw.text == retryNewPsw.text {
           // checkTelephone()
             let passwrd = newPsw.text ?? ""
             if passwrd != "" {
                //  self.delegate?.registrationDelegateClick(text:passwrd,flagData:1)
                DispatchQueue.main.async {
                       let alert = UIAlertController(title: "Success", message: "Wait Confirmation code", preferredStyle: .alert)
                    alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                       self.present(alert, animated: true)
                }
            }
         }
        else {
            DispatchQueue.main.async {
                    let alert = UIAlertController(title: "Warning", message: "<New password> does not match <Retry new password>", preferredStyle: .alert)
                alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                   self.present(alert, animated: true)
                }
        }
    }
    
    @IBAction func butChangePsw(_ sender: Any) {
        if newPsw.text == "" || retryNewPsw.text == "" {
            DispatchQueue.main.async {
                   let alert = UIAlertController(title: "Warning", message: "<New Password> or <Retry new password> is empty", preferredStyle: .alert)
                alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                   self.present(alert, animated: true)
                }
             return
        }
        if newPsw.text == retryNewPsw.text {
           // checkTelephone()
             let passwrd = newPsw.text ?? ""
             if passwrd != "" {
                //  self.delegate?.registrationDelegateClick(text:passwrd,flagData:1)
                DispatchQueue.main.async {
                       let alert = UIAlertController(title: "Success", message: "Wait Confirmation code", preferredStyle: .alert)
                    alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                       self.present(alert, animated: true)
                }
            }
        }
        else {
            DispatchQueue.main.async {
                    let alert = UIAlertController(title: "Warning", message: "<New password> does not match <Retry new password>", preferredStyle: .alert)
                alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
                   self.present(alert, animated: true)
                }
            return
        }
         _  = self.navigationController?.popViewController( animated: true)
    }
    
    func sendPswToServer(psw:String) {
        
    }
    
    
    /*    // 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.
    }    */

}
