package com.example.petstoremobile.adapters;

import android.content.Context;
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 changes based on theme
public class BlackTextArrayAdapter<T> extends ArrayAdapter<T> {
    public BlackTextArrayAdapter(@NonNull Context context, int resource, @NonNull T[] objects) {
        super(context, resource, objects);
    }

    public BlackTextArrayAdapter(@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(ContextCompat.getColor(getContext(), R.color.white));
        if (view instanceof TextView) {
            ((TextView) view).setTextColor(ContextCompat.getColor(getContext(), R.color.spinner_text));
        }
        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.white));
        if (view instanceof TextView) {
            ((TextView) view).setTextColor(ContextCompat.getColor(getContext(), R.color.spinner_text));
        }
        return view;
    }
}