package ib;

import android.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/* loaded from: classes4.dex */
public final class e extends BaseAdapter implements Filterable {

    /* renamed from: p, reason: collision with root package name */
    private final Context f22757p;

    /* renamed from: q, reason: collision with root package name */
    private List f22758q;

    /* renamed from: r, reason: collision with root package name */
    private final LayoutInflater f22759r;

    /* renamed from: s, reason: collision with root package name */
    private final a f22760s;

    /* renamed from: t, reason: collision with root package name */
    private List f22761t;

    /* renamed from: u, reason: collision with root package name */
    private int f22762u;

    /* loaded from: classes4.dex */
    private final class a extends Filter {
        public a() {
        }

        /* JADX WARN: Code restructure failed: missing block: B:17:0x0053, code lost:
        
            r0 = sm.c0.S0(r0);
         */
        /* JADX WARN: Code restructure failed: missing block: B:9:0x001e, code lost:
        
            r0 = sm.c0.S0(r0);
         */
        @Override // android.widget.Filter
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        protected Filter.FilterResults performFiltering(CharSequence charSequence) {
            List arrayList;
            boolean P;
            List I0;
            boolean P2;
            List arrayList2;
            Filter.FilterResults filterResults = new Filter.FilterResults();
            if (charSequence == null || charSequence.length() == 0) {
                List list = e.this.f22761t;
                if (list == null || arrayList2 == null) {
                    arrayList2 = new ArrayList();
                }
                filterResults.values = arrayList2;
                filterResults.count = arrayList2.size();
            } else {
                String obj = charSequence.toString();
                Locale locale = Locale.getDefault();
                kotlin.jvm.internal.t.f(locale, "getDefault(...)");
                String lowerCase = obj.toLowerCase(locale);
                kotlin.jvm.internal.t.f(lowerCase, "toLowerCase(...)");
                List list2 = e.this.f22761t;
                if (list2 == null || arrayList == null) {
                    arrayList = new ArrayList();
                }
                int size = arrayList.size();
                ArrayList arrayList3 = new ArrayList();
                for (int i10 = 0; i10 < size; i10++) {
                    Object obj2 = arrayList.get(i10);
                    String valueOf = String.valueOf(obj2);
                    Locale locale2 = Locale.getDefault();
                    kotlin.jvm.internal.t.f(locale2, "getDefault(...)");
                    String lowerCase2 = valueOf.toLowerCase(locale2);
                    kotlin.jvm.internal.t.f(lowerCase2, "toLowerCase(...)");
                    P = kotlin.text.y.P(lowerCase2, lowerCase, false, 2, null);
                    if (P) {
                        arrayList3.add(obj2);
                    } else {
                        I0 = kotlin.text.z.I0(lowerCase2, new String[]{" "}, false, 0, 6, null);
                        String[] strArr = (String[]) I0.toArray(new String[0]);
                        int length = strArr.length;
                        int i11 = 0;
                        while (true) {
                            if (i11 < length) {
                                P2 = kotlin.text.y.P(strArr[i11], lowerCase, false, 2, null);
                                if (P2) {
                                    arrayList3.add(obj2);
                                    break;
                                }
                                i11++;
                            }
                        }
                    }
                }
                filterResults.values = arrayList3;
                filterResults.count = arrayList3.size();
            }
            return filterResults;
        }

        @Override // android.widget.Filter
        protected void publishResults(CharSequence charSequence, Filter.FilterResults results) {
            kotlin.jvm.internal.t.g(results, "results");
            e eVar = e.this;
            Object obj = results.values;
            kotlin.jvm.internal.t.e(obj, "null cannot be cast to non-null type java.util.ArrayList<T of ca.canadapost.module.customsform.CustomFormStep4DropdownInputAdapter>{ kotlin.collections.TypeAliasesKt.ArrayList<T of ca.canadapost.module.customsform.CustomFormStep4DropdownInputAdapter> }");
            eVar.f22758q = (ArrayList) obj;
            if (results.count > 0) {
                e.this.notifyDataSetChanged();
            } else {
                e.this.notifyDataSetInvalidated();
            }
        }
    }

    public e(Context context, List objects) {
        kotlin.jvm.internal.t.g(objects, "objects");
        this.f22757p = context;
        this.f22758q = objects;
        LayoutInflater from = LayoutInflater.from(context);
        kotlin.jvm.internal.t.f(from, "from(...)");
        this.f22759r = from;
        this.f22760s = new a();
        this.f22762u = h7.j.f21099n;
    }

    public final void c(int i10) {
        this.f22762u = i10;
    }

    @Override // android.widget.Adapter
    public int getCount() {
        return this.f22758q.size();
    }

    @Override // android.widget.Filterable
    public Filter getFilter() {
        return this.f22760s;
    }

    @Override // android.widget.Adapter
    public Object getItem(int i10) {
        return this.f22758q.get(i10);
    }

    @Override // android.widget.Adapter
    public long getItemId(int i10) {
        return i10;
    }

    @Override // android.widget.Adapter
    public View getView(int i10, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = this.f22759r.inflate(this.f22762u, viewGroup, false);
            kotlin.jvm.internal.t.f(view, "inflate(...)");
        }
        View findViewById = view.findViewById(R.id.text1);
        kotlin.jvm.internal.t.f(findViewById, "findViewById(...)");
        TextView textView = (TextView) findViewById;
        Object item = getItem(i10);
        if (item instanceof CharSequence) {
            textView.setText((CharSequence) item);
        } else {
            textView.setText(String.valueOf(item));
        }
        return view;
    }
}
