package org.deke.risk.riskahead.adapter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

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

public class ProfilePagerAdapter extends FragmentStatePagerAdapter {
    int mNumOfTabs;
    String userID;

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

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

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


        return returnFragment;
    }

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

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

        return myFragment;
    }

    public 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;
    }
}