package com.gh.gamecenter.collection;

import android.os.Bundle;
import android.view.View;

import com.gh.gamecenter.common.base.fragment.BaseFragment_TabLayout;
import com.gh.gamecenter.common.constant.EntranceConsts;
import com.gh.gamecenter.core.utils.MtaHelper;
import com.gh.gamecenter.R;
import com.gh.gamecenter.login.user.UserManager;

import java.util.List;

import androidx.fragment.app.Fragment;

/**
 * Created by khy on 18/07/17.
 * <p>
 * 我的收藏viewpager页面
 */
public class CollectionWrapperFragment extends BaseFragment_TabLayout {

    public static final int INDEX_ANSWER = 0;
    public static final int INDEX_TOOL = 1;
    public static final int INDEX_ARTICLE = 2;

    public static CollectionWrapperFragment newInstance(int checkedIndex) {
        CollectionWrapperFragment fragment = new CollectionWrapperFragment();
        Bundle args = new Bundle(1);
        args.putInt(PAGE_INDEX, checkedIndex);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (mDividerLineView != null) {
            mDividerLineView.setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_no_padding_tablayout_viewpager;
    }

    @Override
    protected void initTabTitleList(List<String> tabTitleList) {
        tabTitleList.add(getString(R.string.answer));
        tabTitleList.add(getString(R.string.collection_article));
        tabTitleList.add(getString(R.string.video));
        tabTitleList.add(getString(R.string.game_collection));
        tabTitleList.add(getString(R.string.collection_toolkit));
        tabTitleList.add(getString(R.string.collection_info));
    }

    @Override
    protected void initFragmentList(List<Fragment> fragments) {
        fragments.add(new AnswerFragment().with(getArguments()));
        fragments.add(new CommunityArticleFragment().with(getArguments()));

        Bundle videoArguments;
        if (getArguments() != null) {
            videoArguments = (Bundle) getArguments().clone();
        } else {
            videoArguments = new Bundle();
        }
        videoArguments.putString("videoStyle", VideoFragment.VideoStyle.COLLECT.getValue());
        fragments.add(new VideoFragment().with(videoArguments));

        Bundle gameCollectionArguments;
        if (getArguments() != null) {
            gameCollectionArguments = (Bundle) getArguments().clone();
        } else {
            gameCollectionArguments = new Bundle();
        }
        gameCollectionArguments.putString(EntranceConsts.KEY_USER_ID, UserManager.getInstance().getUserId());
        gameCollectionArguments.putString(EntranceConsts.KEY_TYPE, GamesCollectionFragment.TYPE_COLLECT);
        fragments.add(new GamesCollectionFragment().with(gameCollectionArguments));

        fragments.add(new ToolsFragment().with(getArguments()));
        fragments.add(new ArticleFragment().with(getArguments()));
    }

    @Override
    public void onPageSelected(int position) {
        super.onPageSelected(position);
        MtaHelper.onEvent("我的光环_新", "我的收藏", mTabTitleList.get(position) + "Tab");
    }

    @Override
    public void onResume() {
        super.onResume();
        setNavigationTitle(R.string.collection_title);
    }
}
