package com.cooleshow.teacher.ui.course;

import android.os.Bundle;
import android.text.TextUtils;
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.teacher.R;
import com.cooleshow.teacher.adapter.MineVideoCoursePagerAdapter;
import com.cooleshow.teacher.constants.TeacherInfoConstants;
import com.cooleshow.teacher.databinding.ActivityMineVideoCourseBinding;
import com.cooleshow.teacher.presenter.course.MineVideoCoursePresenter;
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/20 13:47
 *
 * @author Ryan
 * 类说明：
 */
@Route(path = RouterPath.CourseCenter.TEACHER_MINE_VIDEO_COURSE)
public class MineVideoCourseActivity extends BaseMVPActivity<ActivityMineVideoCourseBinding, MineVideoCoursePresenter> implements View.OnClickListener {
    private boolean teacherIsCert;

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_right_text:
                if (!teacherIsCert) {
                    ToastUtil.getInstance().showShort("您还没有完成达人认证,认证后才可创建\n视频课哦");
                    return;
                }
                ARouter.getInstance()
                        .build(RouterPath.WebCenter.ACTIVITY_HTML)
                        .withString(WebConstants.WEB_URL, WebConstants.TEACHER_VIDEO_CREATE)
                        .navigation();
                break;
        }
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtil.setStatusBarDarkTheme(this, true);
        String teacherCertificationStatus = UserHelper.getTeacherCertificationStatus();
        teacherIsCert = TextUtils.equals(teacherCertificationStatus, TeacherInfoConstants.ENTRY_STATUS_PASS);
    }

    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
    public void initData() {
        super.initData();
        initTabLayoutAndViewPager();
    }


    private List<String> titles = new ArrayList<String>(Arrays.asList("已上架", "审核中", "审核失败"));
    private List<String> auditStatusList = new ArrayList<String>(Arrays.asList("PASS", "DOING", "UNPASS"));
    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 = MineVideoCourseFragment.newInstance(auditStatusList.get(i));
            fragments.add(adFragment);
        }
        viewPager.setAdapter(new MineVideoCoursePagerAdapter(getSupportFragmentManager(), fragments, titles));
        tabLayout.setupWithViewPager(viewPager);
    }


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

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