package it.integry.integrywmsnative.view.dialogs.ask_position_of_lu;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;


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

public class DialogAskPositionOfLUAdapter extends PagerAdapter {
    private Context mContext;

    private List<Integer> mDatasetLayout;
    private List<View> mDatasetViews;

    public DialogAskPositionOfLUAdapter(Context context, List<Integer> datasetView) {
        this.mContext = context;
        this.mDatasetLayout = datasetView;

        this.mDatasetViews = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return mDatasetLayout.size();
    }

    @Override
    public View instantiateItem(ViewGroup container, int position) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(mDatasetLayout.get(position), container, false);

        container.addView(view);
        this.mDatasetViews.add(view);

        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((LinearLayout)object);
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view == o;
    }


    public View getPage(int index) {
        return this.mDatasetViews.get(index);
    }

}