package com.example.petstoremobile.adapters;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import com.example.petstoremobile.R;
import java.util.List;

/**
 * A class that overrides the arrayAdapter so the text color is white and background is transparent.
 */
public class WhiteTextArrayAdapter<T> extends ArrayAdapter<T> {
    public WhiteTextArrayAdapter(@NonNull Context context, int resource, @NonNull T[] objects) {
        super(context, resource, objects);
    }

    public WhiteTextArrayAdapter(@NonNull Context context, int resource, @NonNull List<T> objects) {
        super(context, resource, objects);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view = super.getView(position, convertView, parent);
        view.setBackgroundColor(Color.TRANSPARENT);
        if (view instanceof TextView) {
            ((TextView) view).setTextColor(Color.WHITE);
        }
        return view;
    }
    
    @Override
    public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view = super.getDropDownView(position, convertView, parent);
        view.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.primary_dark));
        if (view instanceof TextView) {
            ((TextView) view).setTextColor(Color.WHITE);
        }
        return view;
    }
}
