package com.cooleshow.teacher.ui.course;

import android.graphics.Typeface;
import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.cooleshow.base.presenter.BasePresenter;
import com.cooleshow.base.router.RouterPath;
import com.cooleshow.base.ui.activity.BaseMVPActivity;
import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
import com.cooleshow.teacher.R;
import com.cooleshow.teacher.adapter.MineCoursePageAdapter;
import com.cooleshow.teacher.databinding.ActivityMineCourseLayoutBinding;
import com.cooleshow.teacher.presenter.course.MineCoursePresenter;

import java.util.ArrayList;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewbinding.ViewBinding;
import androidx.viewpager2.widget.ViewPager2;

/**
 * Author by pq, Date on 2022/4/25.
 */
@Route(path = RouterPath.CourseCenter.TEACHER_MINE_COURSE)
public class MineCourseActivity extends BaseMVPActivity<ActivityMineCourseLayoutBinding, MineCoursePresenter> {
    private ArrayList<Fragment> mFragments = new ArrayList<>();

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

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

    @Override
    protected void initView() {
        initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "我的课程");
        viewBinding.radioGroup.setOnCheckedChangeListener((radioGroup, i) -> {
            if (i == R.id.rb_sparring) {
                viewBinding.viewPager.setCurrentItem(0);
            }
            if (i == R.id.rb_live_course) {
                viewBinding.viewPager.setCurrentItem(1);
            }
            if (i == R.id.rb_video_course) {
                viewBinding.viewPager.setCurrentItem(2);
            }
        });
        viewBinding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                changeTableLayoutBar(position);
            }
        });
    }

    private void changeTableLayoutBar(int position) {
        if (position == 0) {
            viewBinding.rbSparring.setChecked(true);
            viewBinding.rbSparring.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
            viewBinding.rbLiveCourse.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
            viewBinding.rbVideoCourse.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        }
        if (position == 1) {
            viewBinding.rbLiveCourse.setChecked(true);
            viewBinding.rbSparring.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
            viewBinding.rbLiveCourse.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
            viewBinding.rbVideoCourse.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        }
        if (position == 2) {
            viewBinding.rbVideoCourse.setChecked(true);
            viewBinding.rbSparring.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
            viewBinding.rbLiveCourse.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
            viewBinding.rbVideoCourse.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        }
    }

    @Override
    public void initData() {
        super.initData();
        SparringCourseFragment sparringCourseFragment = new SparringCourseFragment();
        LiveCourseFragment liveCourseFragment = new LiveCourseFragment();
        VideoCourseFragment videoCourseFragment = new VideoCourseFragment();
        mFragments.add(sparringCourseFragment);
        mFragments.add(liveCourseFragment);
        mFragments.add(videoCourseFragment);
        MineCoursePageAdapter mineCoursePageAdapter = new MineCoursePageAdapter(this);
        mineCoursePageAdapter.setFragments(mFragments);
        viewBinding.viewPager.setAdapter(mineCoursePageAdapter);
    }

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