package com.sheep.gamegroup.module.login.fragments;


import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.sheep.gamegroup.module.login.controller.LoginController;
import com.sheep.gamegroup.util.StringUtils;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.base.BaseFragment;
import com.sheep.jiuyan.samllsheep.utils.G;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * A simple {@link Fragment} subclass.
 */
public class FindAccountFgt extends BaseFragment {

    private LoginController mController;

    @BindView(R.id.phone_number_box)
    EditText phoneNumberBox;
    @BindView(R.id.text_delete_btn)
    ImageView textDeleteBtn;

    public FindAccountFgt() {
        // Required empty public constructor
    }

    public static FindAccountFgt newInstance(LoginController controller) {
        FindAccountFgt fragment = new FindAccountFgt();
        fragment.mController = controller;
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_find_account;
    }

    @Override
    public void onViewCreated() {
        phoneNumberBox.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                textDeleteBtn.setVisibility(TextUtils.isEmpty(s) ? View.GONE : View.VISIBLE);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    @OnClick(R.id.send_captcha_btn)
    public void doSendCaptcha(View v) {
        String phoneNum = phoneNumberBox.getText().toString().trim();
        if (TextUtils.isEmpty(phoneNum)) {
            G.shortToast("请输入手机号");
            return;
        }
        if (!StringUtils.isMobile(phoneNum)) {
            G.shortToast("手机号有误");
            return;
        }
        mController.whenGoValidCaptcha(phoneNumberBox.getText().toString());
    }

    @OnClick(R.id.text_delete_btn)
    public void doDeleteText(View v) {
        phoneNumberBox.setText("");
    }

}
