using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Register : MonoBehaviour
{
    public ADokManager adok;

    public InputField txtUserName;
    public InputField txtPhoneNo;
    public InputField txtPass;
    public InputField txtAnswer;
    public InputField txtCodeTaied;

    public Text txtResult;
    public Text txtSecurityQuestion;
    

    // Use this for initialization
    void Start()
    {
        adok.OnRegisterChange += Adok_OnRegisterChange;
        adok.OnResendCodeTaiedChange += Adok_OnResendCodeTaiedChange;
        adok.OnCodeTaiedChange += Adok_OnCodeTaiedChange;
        
    }



    // Update is called once per frame
    void Update()
    {

    }

    public void RegisterPlayer()
    {
        adok.RegisterPlayer(txtPhoneNo.text);
    }

    public void RegisterPlayerWithuserPass()
    {
        adok.RegisterPlayer(txtUserName.text, txtPass.text, txtPass.text, txtAnswer.text);
    }
    public void ResendCodeTaied()
    {
        adok.ResendCodeTaied();
    }

    public void CheckCodeTaied()
    {
        adok.CheckCodeTaied(txtCodeTaied.text.Trim());
    }

    public void GetSecurityQuestion()
    {
        txtSecurityQuestion.text = FarsiSaz.MakeMePersian(adok.getSecurityQuestion());
    }

    private void Adok_OnRegisterChange(ADokManager.RegisterResult resgisterResult)
    {
        txtResult.text = "RegisterResult:" + resgisterResult.ToString();
    }

    private void Adok_OnResendCodeTaiedChange(ADokManager.CodeTaiedResult CodeTaiedResult)
    {
        int mustWaitTime = (int)(60 - adok.delayNeeded);
        if (mustWaitTime < 0)
        {
            mustWaitTime = 0;
        }
        txtResult.text = "CodeTaiedResult:" + CodeTaiedResult.ToString()+ " --- mustWaitTime:" + mustWaitTime;
    }

    private void Adok_OnCodeTaiedChange(ADokManager.CodeTaiedResult CodeTaiedResult)
    {
        txtResult.text = "CodeTaiedResult:" + CodeTaiedResult.ToString();
    }


}
