package com.cooleshow.teacher.ui.course;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.cooleshow.base.common.WebConstants;
import com.cooleshow.base.router.RouterPath;
import com.cooleshow.base.ui.activity.BaseMVPActivity;
import com.cooleshow.base.utils.ToastUtil;
import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
import com.cooleshow.teacher.R;
import com.cooleshow.teacher.adapter.MineLiveCoursePagerAdapter;
import com.cooleshow.teacher.databinding.ActivityMineLiveCourseBinding;
import com.cooleshow.teacher.presenter.course.MineLiveCoursePresenter;
import com.cooleshow.usercenter.helper.UserHelper;
import com.google.android.material.tabs.TabLayout;

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

import io.rong.imkit.utils.StatusBarUtil;

/**
 * 创建日期：2022/5/19 15:12
 *
 * @author Ryan
 * 类说明：
 */
@Route(path = RouterPath.CourseCenter.TEACHER_MINE_LIVE_COURSE)
public class MineLiveCourseActivity extends BaseMVPActivity<ActivityMineLiveCourseBinding, MineLiveCoursePresenter> implements View.OnClickListener {
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_right_text:
                int teacherLiveFlag = UserHelper.getTeacherLiveFlag();
                if (teacherLiveFlag == 0) {
                    ToastUtil.getInstance().showShort("您还未开通直播权限,开通后才可创建\n直播课哦");
                    return;
                }
                ARouter.getInstance()
                        .build(RouterPath.WebCenter.ACTIVITY_HTML)
                        .withString(WebConstants.WEB_URL, WebConstants.TEACHER_LIVE_CREATE)
                        .navigation();
                break;
        }
    }

    private TabLayout tabLayout;
    private ViewPager viewPager;

    @Override
    protected void initView() {
        initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "直播课");
        viewBinding.toolbarInclude.tvRightText.setTextColor(getResources().getColor(com.cooleshow.base.R.color.common_black));
        viewBinding.toolbarInclude.tvRightText.setVisibility(View.VISIBLE);
        viewBinding.toolbarInclude.tvRightText.setText("创建课程");
        viewBinding.toolbarInclude.tvRightText.setOnClickListener(this);
        tabLayout = viewBinding.tablayout;
        viewPager = viewBinding.viewpager;
        viewPager.setCurrentItem(0);

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        QMUIStatusBarHelper.setStatusBarLightMode(this);
    }

    @Override
    public void initData() {
        super.initData();
        initTabLayoutAndViewPager();
    }

    private List<String> titles = new ArrayList<String>(Arrays.asList("进行中", "未上架", "销售中", "已完成", "已取消"));
    private List<String> types = new ArrayList<String>(Arrays.asList("ING", "NOT_SALE", "APPLY", "COMPLETE", "CANCEL"));
    private List<Fragment> fragments = new ArrayList<>();

    private void initTabLayoutAndViewPager() {
        tabLayout.removeAllTabs();
        fragments.clear();
        for (int i = 0; i < titles.size(); i++) {
            tabLayout.addTab(tabLayout.newTab().setText(titles.get(i)));
            Fragment adFragment = MineLiveCourseFragment.newInstance(types.get(i));
            fragments.add(adFragment);
        }
        viewPager.setAdapter(new MineLiveCoursePagerAdapter(getSupportFragmentManager(), fragments, titles));
        viewPager.setOffscreenPageLimit(fragments.size());
        tabLayout.setupWithViewPager(viewPager);
    }


    @Override
    protected ActivityMineLiveCourseBinding getLayoutView() {
        return ActivityMineLiveCourseBinding.inflate(getLayoutInflater());
    }

    @Override
    protected MineLiveCoursePresenter createPresenter() {
        return new MineLiveCoursePresenter();
    }
}
