package com.tenlionsoft.oamodule.activity.meeting;

import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.gyf.immersionbar.ImmersionBar;
import com.tenlionsoft.baselib.constant.PathConfig;
import com.tenlionsoft.baselib.core.beans.OperateBean;
import com.tenlionsoft.baselib.core.widget.base.BaseActivity;
import com.tenlionsoft.baselib.core.widget.base.BaseFragment;
import com.tenlionsoft.baselib.core.widget.base.BaseViewPage2Adapter;
import com.tenlionsoft.baselib.core.widget.base.FragmentUtils;
import com.tenlionsoft.baselib.core.widget.views.OperatePopup;
import com.tenlionsoft.oamodule.R;
import com.tenlionsoft.oamodule.R2;

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

import androidx.viewpager2.widget.ViewPager2;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者: Adam
 * 日期: 2022年04月14日11:03:58
 * 邮箱: itgaojian@163.com
 * 描述: 会议管理
 */
@Route(path = PathConfig.PATH_MODULE_OA_ACTIVITY_MEETING)
public class MeetingCenterActivity extends BaseActivity {


    @BindView(R2.id.iv_back)
    ImageView mIvBack;
    @BindView(R2.id.rb_join)
    RadioButton mRbJoin;
    @BindView(R2.id.rb_emcee)
    RadioButton mRbEmcee;
    @BindView(R2.id.vp_content)
    ViewPager2 mVpContent;
    @BindView(R2.id.rg_type)
    RadioGroup mRgType;
    @BindView(R2.id.rl_content_title)
    RelativeLayout mRlContentTitle;
    @BindView(R2.id.iv_control)
    ImageView mIvControl;

    private List<BaseFragment> mFragments;
    private List<OperateBean> mControls;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_meeting_center;
    }

    @Override
    public void initData() {
        ButterKnife.bind(this);
        mRlTitleBar.setVisibility(View.GONE);
        ImmersionBar.with(this)
            .statusBarDarkFont(true)
            .statusBarColor(R.color.gray_bg)
            .titleBar(mRlContentTitle)
            .init();
        refreshView(STATE_LOAD_SUCCESS);
        initViews();
    }

    private void initViews() {
        mIvBack.setOnClickListener(v -> finish());
        mIvControl.setOnClickListener(v -> onShowOperatePopup());

        mRgType.setOnCheckedChangeListener((group, checkedId) -> {
            if (checkedId == R.id.rb_join) {
                mVpContent.setCurrentItem(0, false);
            } else if (checkedId == R.id.rb_emcee) {
                mVpContent.setCurrentItem(1, false);
            }
        });
        mFragments = new ArrayList<>();
        //BaseFragment mineApplyFragment = FragmentUtils.getFragment(PathConfig.PATH_MODULE_OA_FRAGMENT_MINE_APPLY_MEETING);
        BaseFragment joinFragment = FragmentUtils.getFragment(PathConfig.PATH_MODULE_OA_FRAGMENT_JOIN_MEETING);
        BaseFragment emceeFragment = FragmentUtils.getFragment(PathConfig.PATH_MODULE_OA_FRAGMENT_EMCEE_MEETING);

        mFragments.add(joinFragment);
        mFragments.add(emceeFragment);

        mVpContent.setAdapter(new BaseViewPage2Adapter(mActivity, mFragments));
        mVpContent.setUserInputEnabled(false);
        mControls = new ArrayList<>();
        OperateBean addBean = new OperateBean();
        addBean.setId("ADD");
        addBean.setName("会议申请");
        OperateBean listBean = new OperateBean();
        listBean.setId("LIST");
        listBean.setName("我的会议");

        mControls.add(addBean);
        mControls.add(listBean);

    }

    /**
     * 显示操作
     */
    private void onShowOperatePopup() {
        OperatePopup popup = new OperatePopup(this, mControls);
        popup.addOnCheckChange((bean) -> {
            popup.dismiss();
            switch (bean.getId()) {
                case "ADD":
                    ARouter.getInstance()
                        .build(PathConfig.PATH_MODULE_OA_ACTIVITY_MEETING_APPLY)
                        .navigation(mActivity, 12);
                    break;
                case "LIST":
                    ARouter.getInstance()
                        .build(PathConfig.PATH_MODULE_OA_ACTIVITY_MEETING_MINE_APPLY)
                        .navigation();
                    break;
            }
        });
        popup.showPopupWindow(mIvControl);
    }

    @Override
    protected void doSearchByTitle() {

    }

    @Override
    protected void clearSearch() {

    }

}