package com.amazon.ads.apidemo.adapters;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.amazon.ads.apidemo.fragments.DeviceInfoFragment;
import com.amazon.ads.apidemo.fragments.DisplayFragment;
import com.amazon.ads.apidemo.fragments.NetworkFragment;
import com.amazon.ads.apidemo.fragments.SystemControlFragment;
import com.amazon.ads.apidemo.fragments.OtaUpdateFragment;
import com.amazon.ads.apidemo.fragments.TimezoneFragment;

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

/**
 * Adapter for managing tabs in the ViewPager2
 */
public class TabAdapter extends FragmentStateAdapter {
    private final List<Fragment> fragments = new ArrayList<>();
    private final List<String> titles = new ArrayList<>();

    public TabAdapter(@NonNull FragmentActivity fragmentActivity) {
        super(fragmentActivity);

        // Add all fragments in order
        fragments.add(new DeviceInfoFragment());
        titles.add("Device info");

        fragments.add(new DisplayFragment());
        titles.add("Display");

        fragments.add(new SystemControlFragment());
        titles.add("System control");

        fragments.add(new NetworkFragment());
        titles.add("Network");

        fragments.add(new TimezoneFragment());
        titles.add("Timezone");

        fragments.add(new OtaUpdateFragment());
        titles.add("OTA Update");
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        return fragments.get(position);
    }

    @Override
    public int getItemCount() {
        return fragments.size();
    }

    public String getTabTitle(int position) {
        return titles.get(position);
    }
}
