//
//  SignUpVC.swift
//  Garmentoo
//
//  Created by ANGEL FS on 25/03/22.
//

import UIKit
import MJSnackBar

class SignUpVC: UIViewController {

    @IBOutlet weak var nameText: UITextField!
    @IBOutlet weak var mailText: UITextField!
    @IBOutlet weak var mobileText: UITextField!
    @IBOutlet weak var maleRadioImage: UIImageView!
    @IBOutlet weak var femaleRadioImage: UIImageView!
    
    var snackBar: MJSnackBar!
    let validation = Validation()
    var genderIndex = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.viewLoadingProperties()
    }
    

    //Button actions
    @IBAction func backBtnTapped(_ sender: Any) {
        self.navigationController?.popViewController(animated: true)
    }
    
    @IBAction func signupTapped(_ sender: Any) {
        
        let mob : String = (self.mobileText.text?.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines))!
        let validMobile = self.validation.validPhoneNumber(phoneNumber: mob)
        let validMail = self.validation.validateEmailId(emailID: self.mailText.text ?? "")
//        if nameText.text == "" || mailText.text == "" || mobileText.text == ""
//        {
//            self.showSnackBar(Message: "All fields are mandatory", snackbar: self.snackBar)
//            return
//
//        }
//        else if (validMail == false)
//        {
//            self.showSnackBar(Message:"Invalid email id" , snackbar: self.snackBar)
//            return
//        }
//        else if (validMobile == false)
//        {
//            self.showSnackBar(Message:"Invalid mobile number" , snackbar: self.snackBar)
//            return
//        }
//        else if self.genderIndex == 0
//        {
//            self.showSnackBar(Message:"Please select your gender" , snackbar: self.snackBar)
//            return
//        }
        let sb = UIStoryboard(name: "Onboarding", bundle: nil)
        let nextVc = sb.instantiateViewController(withIdentifier: "verificationVC")as! VerificationVC
        self.navigationController?.pushViewController(nextVc, animated: true)
    }
    
    @IBAction func genderBtnTapped(_ sender: UIButton) {
        if sender.tag == 1
        {
            self.genderIndex = 1
            self.maleRadioImage.isHighlighted = true
            self.femaleRadioImage.isHighlighted = false
        }
        else
        {
            self.genderIndex = 1
            self.maleRadioImage.isHighlighted = false
            self.femaleRadioImage.isHighlighted = true
        }
    }
    
}


extension SignUpVC
{
    func viewLoadingProperties()
    {
        self.snackBar =  MJSnackBar(onView: self.view)

    }
}


extension SignUpVC : UITextFieldDelegate
{
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        if textField == self.nameText
        {
            self.nameText.resignFirstResponder()
            self.mailText.becomeFirstResponder()
        }
        else if textField == self.mailText
        {
            self.mailText.resignFirstResponder()
            self.mobileText.becomeFirstResponder()
        }
        else if textField == self.mobileText
        {
            self.mobileText.resignFirstResponder()
        }
        return true
    }
}
