package com.yutou.jianr_mg.Fragments;

import android.content.Context;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.yutou.jianr_mg.Adapters.ViewPagerAdapter;
import com.yutou.jianr_mg.Fragments.GameDataFragments.DropFragment;
import com.yutou.jianr_mg.Fragments.GameDataFragments.WarFragment;
import com.yutou.jianr_mg.R;

import java.util.ArrayList;
import java.util.List;

import me.majiajie.pagerbottomtabstrip.NavigationController;
import me.majiajie.pagerbottomtabstrip.PageNavigationView;
import me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectedListener;


public class GameData extends Fragment {
    private Context context;
    private static GameData gameData;

    private PageNavigationView tab;
    private ViewPager viewPager;
    private NavigationController navigationController;
    private   List<Fragment> list;

    public static GameData init(){
        if(gameData==null){
            gameData=new GameData();
        }
        return gameData;
    }
   private View view;
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if(view!=null)
            return view;
        view=inflater.inflate(R.layout.fragment_game_data,null);
        tab = view.findViewById(R.id.tab);
        viewPager = view.findViewById(R.id.pager);


        list=new ArrayList<>();
        list.add(DropFragment.init());
        list.add(WarFragment.init());

        ViewPagerAdapter adapter=new ViewPagerAdapter(getChildFragmentManager(),list);
        viewPager.setAdapter(adapter);
        viewPager.setCurrentItem(0);

        navigationController = tab.material()
                .addItem(R.drawable.icon_drop, R.drawable.icon_drop_select, "掉落日志")
                .addItem(R.drawable.icon_war,R.drawable.icon_war_select,"战斗日志")
                .build();
        navigationController.addTabItemSelectedListener(new OnTabItemSelectedListener() {
            @Override
            public void onSelected(int index, int old) {
                switch (index) {
                }
                viewPager.setCurrentItem(index);
            }

            @Override
            public void onRepeat(int index) {

            }
        });
        navigationController.setupWithViewPager(viewPager);
        navigationController.setSelect(0);
        return view;
    }
}
