package de.jg_cody.Teraplex.ui.rooms;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

import de.jg_cody.Teraplex.R;

public class ListAdapter extends ArrayAdapter {

    public static int SINGLEBUTTON = 0;
    public static int DOUBLEBUTTON = 1;
    public static int OPTION3BUTTON = 2;

    private ArrayList<ListItem> objects;


    @Override
    public int getViewTypeCount()
    {
        return 3;

    }
    public int getItemViewType(int position){
        return objects.get(position).getType();
    }

    public ListAdapter(Context context, int resource, ArrayList<ListItem> objects)
    {
        super(context, resource, objects);
        this.objects = objects;

    }
    @SuppressLint("InflateParams")
    @NotNull
    @Override
    public View getView(int position, View convertView, @NotNull ViewGroup parent) {

        IViewHolder viewHolder= null;
        ListItem listViewItem = objects.get(position);
        int listViewItemType = getItemViewType(position);


        if (convertView == null) {

            if (listViewItemType == SINGLEBUTTON) {
                convertView = LayoutInflater.from(getContext()).inflate(R.layout.singlebutton, null);

                Button bRun = convertView.findViewById(R.id.bRun);
                Button text = convertView.findViewById(R.id.TEXT);
                bRun.setText(listViewItem.getText());
                //text.setText(listViewItemType.get)

                viewHolder = new ViewHolderSingleButton(bRun ,  listViewItem.getText());
                convertView.setTag(viewHolder);

            }
            else if (listViewItemType == DOUBLEBUTTON) {
                convertView = LayoutInflater.from(getContext()).inflate(R.layout.doublebutton, null);
                Button bLeft = (Button) convertView.findViewById(R.id.bLeft);
                Button bRight = (Button) convertView.findViewById(R.id.bRight);

                viewHolder = new ViewHolderDoubleButton(bLeft,bRight,listViewItem.getText());

                convertView.setTag(viewHolder);

            }
        }
        else{
            viewHolder = (IViewHolder) convertView.getTag();
        }

        return convertView;
    }


}
