package com.genlot.ninglottery.module.function;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RadioGroup;

import com.genlot.ninglottery.R;
import com.genlot.ninglottery.base.BaseDialogActivity;
import com.genlot.ninglottery.module.function.help.HelpFragment;
import com.genlot.ninglottery.module.function.log.LogUploadFragment;
import com.genlot.ninglottery.module.function.settings.SystemParamsFragment;
import com.genlot.ninglottery.module.function.upgrade.UpGradeFragment;
import com.genlot.ninglottery.module.function.user.ChangePasswordFragment;
import com.genlot.ninglottery.module.function.user.ChangeUserFragment;
import com.genlot.ninglottery.module.function.user.QueryUserFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnCheckedChanged;
import butterknife.OnClick;

/**
 * @author ZhuYongKang
 * @description 类描述
 * @date 2019/8/19
 */
public class FunctionActivity extends BaseDialogActivity {

    private List<RadioGroup> mRadioMenus;

    @OnCheckedChanged({R.id.radio_system_setting,R.id.radio_log_upload,R.id.radio_user_manager, R.id.radio_upgrade,R.id.radio_help,
            R.id.radio_user_add, R.id.radio_user_delete,R.id.radio_user_change_password,R.id.radio_user_query,
            R.id.radio_help_law,R.id.radio_help_game, R.id.radio_help_about_company,R.id.radio_help_about_copyright})
    public void checkChanged(CompoundButton buttonView, boolean isChecked){
        if (isChecked) {
            switch (buttonView.getId()) {
                case R.id.radio_system_setting:
                    replaceFragment(new SystemParamsFragment());
                    break;
                case R.id.radio_log_upload:
                    replaceFragment(new LogUploadFragment());
                    break;
                case R.id.radio_user_manager:
                    showRadioGroup(rgUserManager);
                    hideFragment();
                    break;
                case R.id.radio_upgrade:
                    replaceFragment(new UpGradeFragment());
                    break;
                case R.id.radio_help:
                    showRadioGroup(rgHelp);
                    hideFragment();
                    break;
                case R.id.radio_user_add:
                    replaceFragment(ChangeUserFragment.newInstance(ChangeUserFragment.TYPE_ADD));
                    break;
                case R.id.radio_user_delete:
                    replaceFragment(ChangeUserFragment.newInstance(ChangeUserFragment.TYPE_DEL));
                    break;
                case R.id.radio_user_change_password:
                    replaceFragment(new ChangePasswordFragment());
                    break;
                case R.id.radio_user_query:
                    replaceFragment(new QueryUserFragment());
                    break;
                case R.id.radio_help_law:
                    replaceFragment(HelpFragment.newInstance(HelpFragment.TYPE_LAW));
                    break;
                case R.id.radio_help_game:
                    replaceFragment(HelpFragment.newInstance(HelpFragment.TYPE_GAME_RULE));
                    break;
                case R.id.radio_help_about_company:
                    replaceFragment(HelpFragment.newInstance(HelpFragment.TYPE_ABOUT_COMPANY));
                    break;
                case R.id.radio_help_about_copyright:
                    replaceFragment(HelpFragment.newInstance(HelpFragment.TYPE_ABOUT_RIGHT));
                    break;
                default:
                    break;
            }
        }
    }

    @OnClick(R.id.icon_back)
    public void goBack() {
        showRadioGroup(rgFunction);
        hideFragment();
        rgFunction.clearCheck();
    }

    @Override
    public int getLayoutID() {
        return R.layout.activity_function;
    }

    @Override
    public void initViews(Bundle savedInstanceState) {
        mRadioMenus = new ArrayList<>();
        mRadioMenus.add(rgFunction);
        mRadioMenus.add(rgUserManager);
        mRadioMenus.add(rgHelp);
    }

    private void showRadioGroup(RadioGroup radioGroup) {
        for (RadioGroup group : mRadioMenus) {
            if (radioGroup == group) {
                radioGroup.setVisibility(View.VISIBLE);
            } else {
                group.setVisibility(View.GONE);
            }
        }
        if (radioGroup == rgFunction) {
            btClose.setVisibility(View.VISIBLE);
            btBack.setVisibility(View.GONE);
        } else {
            btClose.setVisibility(View.GONE);
            btBack.setVisibility(View.VISIBLE);
        }
    }

    @BindView(R.id.rg_function)
    RadioGroup rgFunction;
    @BindView(R.id.rg_user_manager)
    RadioGroup rgUserManager;
    @BindView(R.id.rg_help)
    RadioGroup rgHelp;
    @BindView(R.id.icon_back)
    public Button btBack;
}
