package com.genlot.ninglottery.module.report;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.CompoundButton;
import android.widget.RadioButton;

import com.genlot.ninglottery.R;
import com.genlot.ninglottery.base.BaseDialogActivity;
import com.genlot.ninglottery.module.report.fragments.ReportIssueFragment;
import com.genlot.ninglottery.module.report.fragments.ReportBankFragment;
import com.genlot.ninglottery.module.report.fragments.ReportDetailFragment;
import com.genlot.ninglottery.module.report.fragments.ReportTimeFragment;

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

import butterknife.BindView;
import butterknife.OnCheckedChanged;

/**
 * @author ZhuYongKang
 * @description 报表界面
 * @date 2019/8/20
 */
public class ReportActivity extends BaseDialogActivity {


    private List<Fragment> mFragments;

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

    @Override
    public void initViews(Bundle savedInstanceState) {
        initFragment();
        onCheckedChanged(mRbtDay, true);
    }

    private void initFragment() {
        mFragments = new ArrayList<>();
        mFragments.add(new ReportDetailFragment());
        mFragments.add(new ReportTimeFragment());
        mFragments.add(new ReportIssueFragment());
        mFragments.add(new ReportBankFragment());
    }

    @OnCheckedChanged({R.id.rbt_day, R.id.rbt_time, R.id.rbt_issue,R.id.rbt_bank})
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (isChecked) {
            switch (buttonView.getId()) {
                case R.id.rbt_day:
                    replaceFragment(mFragments.get(0));
                    setTitle("日报表");
                    break;
                case R.id.rbt_time:
                    replaceFragment(mFragments.get(1));
                    setTitle("时段报表");
                    break;
                case R.id.rbt_issue:
                    replaceFragment(mFragments.get(2));
                    setTitle("期报表");
                    break;
                case R.id.rbt_bank:
                    replaceFragment(mFragments.get(3));
                    setTitle("银行缴款报表");
                    break;
                default:
                    break;
            }
        }
    }

    public void goReportDetailFragment(int gameId, String sTime, String eTime) {
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.frame_layout, ReportDetailFragment.newInstance(gameId, sTime, eTime))
                .addToBackStack(null)
                .commit();
    }

    @BindView(R.id.rbt_day)
    RadioButton mRbtDay;
}
