package androidx.recyclerview.widget;

import android.view.View;
import java.util.ArrayList;
import q.AbstractC2761L;

/* JADX INFO: loaded from: classes.dex */
public final class g0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ArrayList f13076a = new ArrayList();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f13077b = Integer.MIN_VALUE;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f13078c = Integer.MIN_VALUE;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f13079d = 0;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final int f13080e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ StaggeredGridLayoutManager f13081f;

    public g0(StaggeredGridLayoutManager staggeredGridLayoutManager, int i6) {
        this.f13081f = staggeredGridLayoutManager;
        this.f13080e = i6;
    }

    public final void a() {
        View view = (View) AbstractC2761L.f(1, this.f13076a);
        d0 d0Var = (d0) view.getLayoutParams();
        this.f13078c = this.f13081f.f12980r.b(view);
        d0Var.getClass();
    }

    public final void b() {
        this.f13076a.clear();
        this.f13077b = Integer.MIN_VALUE;
        this.f13078c = Integer.MIN_VALUE;
        this.f13079d = 0;
    }

    public final int c() {
        return this.f13081f.f12985w ? e(r1.size() - 1, -1) : e(0, this.f13076a.size());
    }

    public final int d() {
        return this.f13081f.f12985w ? e(0, this.f13076a.size()) : e(r1.size() - 1, -1);
    }

    public final int e(int i6, int i7) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = this.f13081f;
        int iK = staggeredGridLayoutManager.f12980r.k();
        int iG = staggeredGridLayoutManager.f12980r.g();
        int i8 = i7 > i6 ? 1 : -1;
        while (i6 != i7) {
            View view = (View) this.f13076a.get(i6);
            int iE = staggeredGridLayoutManager.f12980r.e(view);
            int iB = staggeredGridLayoutManager.f12980r.b(view);
            boolean z6 = iE <= iG;
            boolean z7 = iB >= iK;
            if (z6 && z7 && (iE < iK || iB > iG)) {
                return J.L(view);
            }
            i6 += i8;
        }
        return -1;
    }

    public final int f(int i6) {
        int i7 = this.f13078c;
        if (i7 != Integer.MIN_VALUE) {
            return i7;
        }
        if (this.f13076a.size() == 0) {
            return i6;
        }
        a();
        return this.f13078c;
    }

    public final View g(int i6, int i7) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = this.f13081f;
        ArrayList arrayList = this.f13076a;
        View view = null;
        if (i7 != -1) {
            int size = arrayList.size() - 1;
            while (size >= 0) {
                View view2 = (View) arrayList.get(size);
                if ((staggeredGridLayoutManager.f12985w && J.L(view2) >= i6) || ((!staggeredGridLayoutManager.f12985w && J.L(view2) <= i6) || !view2.hasFocusable())) {
                    break;
                }
                size--;
                view = view2;
            }
            return view;
        }
        int size2 = arrayList.size();
        int i8 = 0;
        while (i8 < size2) {
            View view3 = (View) arrayList.get(i8);
            if ((staggeredGridLayoutManager.f12985w && J.L(view3) <= i6) || ((!staggeredGridLayoutManager.f12985w && J.L(view3) >= i6) || !view3.hasFocusable())) {
                break;
            }
            i8++;
            view = view3;
        }
        return view;
    }

    public final int h(int i6) {
        int i7 = this.f13077b;
        if (i7 != Integer.MIN_VALUE) {
            return i7;
        }
        if (this.f13076a.size() == 0) {
            return i6;
        }
        View view = (View) this.f13076a.get(0);
        d0 d0Var = (d0) view.getLayoutParams();
        this.f13077b = this.f13081f.f12980r.e(view);
        d0Var.getClass();
        return this.f13077b;
    }
}
