package com.cooleshow.student.ui.work;

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.cooleshow.base.router.RouterPath;

import com.cooleshow.base.ui.activity.BaseMVPActivity;
import com.cooleshow.student.adapter.HomeWorkPagerAdapter;
import com.cooleshow.student.contract.HomeWorkActContract;
import com.cooleshow.student.databinding.ActivityHomeworkBinding;
import com.cooleshow.student.presenter.homework.HomeWorkActPresenter;
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/23 10:47
 *
 * @author Ryan
 * 类说明：
 */
@Route(path = RouterPath.WorkCenter.TEACHER_WORK_HOMEWORK)
public class HomeWorkActivity extends BaseMVPActivity<ActivityHomeworkBinding, HomeWorkActPresenter> implements HomeWorkActContract.HomeWorkActView, View.OnClickListener {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        StatusBarUtil.setStatusBarDarkTheme(this, true);
    }

    private TabLayout tabLayout;
    private ViewPager viewPager;

    @Override
    protected void initView() {
        initMidTitleToolBar(viewBinding.toolbarInclude.toolbar, "课后作业");
        tabLayout = viewBinding.tablayout;
        viewPager = viewBinding.viewpager;
        viewPager.setCurrentItem(0);
    }

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

    @Override
    public void onClick(View view) {

    }

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

    @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("NO", "YES"));
    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 = HomeWorkFragment.newInstance(auditStatusList.get(i));
            fragments.add(adFragment);
        }
        viewPager.setAdapter(new HomeWorkPagerAdapter(getSupportFragmentManager(), fragments, titles));
        tabLayout.setupWithViewPager(viewPager);
    }

}
