package com.cooleshow.teacher.ui.comment;

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

import com.alibaba.android.arouter.facade.annotation.Route;
import com.cooleshow.base.router.RouterPath;
import com.cooleshow.base.ui.activity.BaseActivity;
import com.cooleshow.base.ui.activity.BaseMVPActivity;
import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
import com.cooleshow.teacher.R;
import com.cooleshow.teacher.adapter.CourseCommentNotReplyAdapter;
import com.cooleshow.teacher.adapter.MineCoursePageAdapter;
import com.cooleshow.teacher.contract.CourseCommentContract;
import com.cooleshow.teacher.databinding.ActivityCourseCommentLayoutBinding;
import com.cooleshow.teacher.presenter.comment.CourseCommentPresenter;
import com.cooleshow.teacher.ui.course.LiveCourseFragment;
import com.cooleshow.teacher.ui.course.SparringCourseFragment;
import com.cooleshow.teacher.ui.course.VideoCourseFragment;

import java.util.ArrayList;

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

/**
 * Author by pq, Date on 2022/5/5.
 */
@Route(path = RouterPath.CommentCenter.TEACHER_COURSE_COMMENT)
public class CourseCommentActivity extends BaseActivity<ActivityCourseCommentLayoutBinding> {
    private ArrayList<Fragment> mFragments = new ArrayList<>();

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

    @Override
    protected void initView() {
        initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "陪练课评价");
        viewBinding.radioGroup.setOnCheckedChangeListener((radioGroup, i) -> {
            if (i == R.id.rb_not_reply) {
                viewBinding.viewPager.setCurrentItem(0);
            }
            if (i == R.id.rb_completed) {
                viewBinding.viewPager.setCurrentItem(1);
            }
        });
        viewBinding.viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                changeTableLayoutBar(position);
            }
        });
    }

    @Override
    protected void initData() {
        super.initData();
        CourseCommentNoReplyFragment noReplyFragment = new CourseCommentNoReplyFragment();
        CourseCommentHasReplyFragment hasReplyFragment = new CourseCommentHasReplyFragment();
        mFragments.add(noReplyFragment);
        mFragments.add(hasReplyFragment);
        MineCoursePageAdapter mineCoursePageAdapter = new MineCoursePageAdapter(this);
        mineCoursePageAdapter.setFragments(mFragments);
        viewBinding.viewPager.setAdapter(mineCoursePageAdapter);
    }

    private void changeTableLayoutBar(int position) {
        if (position == 0) {
            viewBinding.rbNotReply.setChecked(true);
            viewBinding.rbNotReply.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
            viewBinding.rbCompleted.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
        }
        if (position == 1) {
            viewBinding.rbCompleted.setChecked(true);
            viewBinding.rbCompleted.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
            viewBinding.rbNotReply.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        }
    }

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