package com.cooleshow.teacher.ui.main;

import android.os.Bundle;
import android.view.MenuItem;

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.utils.helper.QMUIStatusBarHelper;
import com.cooleshow.teacher.R;
import com.cooleshow.teacher.adapter.HomePageAdapter;
import com.cooleshow.teacher.databinding.ActivityMainBinding;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.ArrayList;
import java.util.Objects;

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

/**
 * Author by pq, Date on 2022/4/20.
 */
@Route(path = RouterPath.APPCenter.PATH_HOME)
public class MainActivity extends BaseActivity<ActivityMainBinding> {
    private ArrayList<Fragment> mFragments = new ArrayList<>();


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

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

    @Override
    protected void initView() {
        HomePageAdapter homePageAdapter = new HomePageAdapter(this);
        HomeFragment homeFragment = new HomeFragment();
        CourseTableFragment courseTableFragment = new CourseTableFragment();
        HomeFragment homeFragment2 = new HomeFragment();
        HomeFragment homeFragment3 = new HomeFragment();
        HomeFragment homeFragment4 = new HomeFragment();
        mFragments.add(homeFragment);
        mFragments.add(courseTableFragment);
        mFragments.add(homeFragment2);
        mFragments.add(homeFragment3);
        mFragments.add(homeFragment4);
        homePageAdapter.setFragments(mFragments);
        getViewBinding().viewPager.setAdapter(homePageAdapter);
        getViewBinding().viewPager.setOffscreenPageLimit(mFragments.size());
        getViewBinding().viewPager.setUserInputEnabled(false);
        getViewBinding().navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                return onTabClick(item.getItemId());
            }
        });

    }

    private boolean onTabClick(int viewId) {
        if (viewId == R.id.menu_home) {
            getViewBinding().viewPager.setCurrentItem(0);
            return true;
        }
        if (viewId == R.id.menu_coursetable) {
            getViewBinding().viewPager.setCurrentItem(1);
            return true;
        }
        if (viewId == R.id.menu_chat) {
            getViewBinding().viewPager.setCurrentItem(2);
            return true;
        }
        if (viewId == R.id.menu_mall) {
            getViewBinding().viewPager.setCurrentItem(3);
            return true;
        }
        if (viewId == R.id.menu_mine) {
            getViewBinding().viewPager.setCurrentItem(4);
        }
        return true;
    }

}
