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 HEADLINE = 2;
    public static int SPACE = 3;

    private ArrayList<ListItem> objects;


    @Override
    public int getViewTypeCount()
    {
        return 4;

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

        String[] s = listViewItem.getStrings();
        if (convertView == null) {

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

                Button bRun = convertView.findViewById(R.id.singleButton_button);
                Button text = convertView.findViewById(R.id.singleButton_text);

                bRun.setText(s[2]);
                text.setText(s[0]);
                //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.doubleButton_bLeft);
                Button bRight = (Button) convertView.findViewById(R.id.doubleButton_bRight);
                Button text = (Button) convertView.findViewById(R.id.doubleButton_text);

                bLeft.setText(s[3]);
                bRight.setText(s[4]);
                text.setText(s[0]);


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

                //convertView.setTag(viewHolder);

            } else if (listViewItemType == SPACE) {
                convertView = LayoutInflater.from(getContext()).inflate(R.layout.space, null);

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

            return convertView;
        }
        return convertView;

    }}
