package org.deke.risk.riskahead.adapter;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import org.deke.risk.riskahead.fragment.ProfileStatisticsFragment;
import org.deke.risk.riskahead.fragment.ReportListFragment;
import org.deke.risk.riskahead.fragment.Top10Fragment;

/**
 *
 * (C) Copyright 2016 RiskAhead (http://www.riskahead.net)
 * Developer & Contributor: Dennis Thießen (dennis.thiessen@riskahead.net)
 * Date of Release: 10.02.2016
 *
 */
public class ProfilePagerAdapter extends FragmentStatePagerAdapter {
    private int mNumOfTabs;
    private String userID;

    public ProfilePagerAdapter(FragmentManager fm, int NumOfTabs, String userID) {
        super(fm, FragmentStatePagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        this.mNumOfTabs = NumOfTabs;
        this.userID = userID;
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        Fragment returnFragment = new Fragment();

        if(mNumOfTabs == 2){
            switch (position) {
                case 0:
                    returnFragment = newProfileStatisticsInstance(userID);
                    break;
                case 1:
                    returnFragment = newReportListInstance(userID);
                    break;
            }
        }else if(mNumOfTabs == 3){
            switch (position) {
                case 0:
                    returnFragment = newProfileStatisticsInstance(userID);
                    break;
                case 1:
                    returnFragment = new Top10Fragment();
                    break;
                case 2:
                    returnFragment = newReportListInstance(userID);
                    break;
            }
        }

        return returnFragment;
    }

    private static Fragment newProfileStatisticsInstance(String uid) {
        ProfileStatisticsFragment myFragment = new ProfileStatisticsFragment();

        Bundle args = new Bundle();
        args.putString("uid", uid);
        myFragment.setArguments(args);

        return myFragment;
    }

    private static Fragment newReportListInstance(String uid) {
        ReportListFragment myFragment = new ReportListFragment();

        Bundle args = new Bundle();
        args.putString("uid", uid);
        myFragment.setArguments(args);

        return myFragment;
    }

    @Override
    public int getCount() {
        return mNumOfTabs;
    }
}