package com.utopiaindustries.qualitychecker.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

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

import com.utopiaindustries.qualitychecker.R;
import com.utopiaindustries.qualitychecker.ui.activities.fragments.DraftFragment;
import com.utopiaindustries.qualitychecker.ui.activities.fragments.ReportsFragment;

@SuppressWarnings("deprecation")
public class PagerAdapter extends FragmentStatePagerAdapter {

    String tabTitles[] = new String[]{"Reports", "Draft"};
    Context context;

    public PagerAdapter(FragmentManager fm, Context context) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        this.context = context;
    }

    @Override
    public int getCount() {
        return tabTitles.length;
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {

        switch (position) {
            case 0:
                return new ReportsFragment();
            case 1:
                return new DraftFragment();
        }
        return null;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        // Generate title based on item position
        // return tabTitles[position];
        return null;
    }

    public View getTabView(int position) {
        View tab = LayoutInflater.from(context).inflate(R.layout.custom_tab, null);

        TextView tv = (TextView) tab.findViewById(R.id.txt_name);
        tv.setText(tabTitles[position]);
       // tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, context.getResources().getDimension(R.dimen.tab_text_size));

        return tab;
    }
}
