package com.google.android.flexbox;

import A1.C0005f;
import K2.c;
import K2.e;
import K2.g;
import K2.h;
import K2.i;
import K2.j;
import N1.C0201c0;
import N1.C0203d0;
import N1.H;
import N1.L;
import N1.M;
import N1.T;
import N1.i0;
import N1.o0;
import N1.p0;
import android.content.Context;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.a;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class FlexboxLayoutManager extends a implements K2.a, o0 {

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public static final Rect f9523d0 = new Rect();

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    public int f9524F;

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    public final int f9525G;
    public final int H;

    /* JADX INFO: renamed from: J, reason: collision with root package name */
    public boolean f9527J;

    /* JADX INFO: renamed from: K, reason: collision with root package name */
    public boolean f9528K;

    /* JADX INFO: renamed from: N, reason: collision with root package name */
    public i0 f9531N;

    /* JADX INFO: renamed from: O, reason: collision with root package name */
    public p0 f9532O;

    /* JADX INFO: renamed from: P, reason: collision with root package name */
    public i f9533P;

    /* JADX INFO: renamed from: R, reason: collision with root package name */
    public M f9535R;

    /* JADX INFO: renamed from: S, reason: collision with root package name */
    public M f9536S;

    /* JADX INFO: renamed from: T, reason: collision with root package name */
    public j f9537T;

    /* JADX INFO: renamed from: Z, reason: collision with root package name */
    public final Context f9542Z;

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public View f9543a0;

    /* JADX INFO: renamed from: I, reason: collision with root package name */
    public final int f9526I = -1;

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    public List f9529L = new ArrayList();

    /* JADX INFO: renamed from: M, reason: collision with root package name */
    public final e f9530M = new e(this);

    /* JADX INFO: renamed from: Q, reason: collision with root package name */
    public final g f9534Q = new g(this);

    /* JADX INFO: renamed from: U, reason: collision with root package name */
    public int f9538U = -1;

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

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

    /* JADX INFO: renamed from: Y, reason: collision with root package name */
    public final SparseArray f9541Y = new SparseArray();

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public int f9544b0 = -1;

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public final C0005f f9545c0 = new C0005f();

    public FlexboxLayoutManager(Context context, AttributeSet attributeSet, int i, int i5) {
        C0201c0 c0201c0U = a.U(context, attributeSet, i, i5);
        int i8 = c0201c0U.f4515a;
        if (i8 != 0) {
            if (i8 == 1) {
                if (c0201c0U.f4517c) {
                    s1(3);
                } else {
                    s1(2);
                }
            }
        } else if (c0201c0U.f4517c) {
            s1(1);
        } else {
            s1(0);
        }
        int i9 = this.f9525G;
        if (i9 != 1) {
            if (i9 == 0) {
                F0();
                this.f9529L.clear();
                g gVar = this.f9534Q;
                g.b(gVar);
                gVar.f3570d = 0;
            }
            this.f9525G = 1;
            this.f9535R = null;
            this.f9536S = null;
            M0();
        }
        if (this.H != 4) {
            F0();
            this.f9529L.clear();
            g gVar2 = this.f9534Q;
            g.b(gVar2);
            gVar2.f3570d = 0;
            this.H = 4;
            M0();
        }
        this.f9542Z = context;
    }

    public static boolean a0(int i, int i5, int i8) {
        int mode = View.MeasureSpec.getMode(i5);
        int size = View.MeasureSpec.getSize(i5);
        if (i8 > 0 && i != i8) {
            return false;
        }
        if (mode == Integer.MIN_VALUE) {
            return size >= i;
        }
        if (mode != 0) {
            return mode == 1073741824 && size == i;
        }
        return true;
    }

    @Override // androidx.recyclerview.widget.a
    public final int A(p0 p0Var) {
        return e1(p0Var);
    }

    @Override // androidx.recyclerview.widget.a
    public final void A0(Parcelable parcelable) {
        if (parcelable instanceof j) {
            this.f9537T = (j) parcelable;
            M0();
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final Parcelable B0() {
        j jVar = this.f9537T;
        if (jVar != null) {
            j jVar2 = new j();
            jVar2.f3592q = jVar.f3592q;
            jVar2.f3593r = jVar.f3593r;
            return jVar2;
        }
        j jVar3 = new j();
        if (I() <= 0) {
            jVar3.f3592q = -1;
            return jVar3;
        }
        View viewH = H(0);
        jVar3.f3592q = a.T(viewH);
        jVar3.f3593r = this.f9535R.g(viewH) - this.f9535R.m();
        return jVar3;
    }

    @Override // androidx.recyclerview.widget.a
    public final C0203d0 E() {
        h hVar = new h(-2, -2);
        hVar.f3578u = 0.0f;
        hVar.f3579v = 1.0f;
        hVar.f3580w = -1;
        hVar.f3581x = -1.0f;
        hVar.f3575A = 16777215;
        hVar.f3576B = 16777215;
        return hVar;
    }

    @Override // androidx.recyclerview.widget.a
    public final C0203d0 F(Context context, AttributeSet attributeSet) {
        h hVar = new h(context, attributeSet);
        hVar.f3578u = 0.0f;
        hVar.f3579v = 1.0f;
        hVar.f3580w = -1;
        hVar.f3581x = -1.0f;
        hVar.f3575A = 16777215;
        hVar.f3576B = 16777215;
        return hVar;
    }

    @Override // androidx.recyclerview.widget.a
    public final int O0(int i, i0 i0Var, p0 p0Var) {
        if (!j() || this.f9525G == 0) {
            int iP1 = p1(i, i0Var, p0Var);
            this.f9541Y.clear();
            return iP1;
        }
        int iQ1 = q1(i);
        this.f9534Q.f3570d += iQ1;
        this.f9536S.r(-iQ1);
        return iQ1;
    }

    @Override // androidx.recyclerview.widget.a
    public final void P0(int i) {
        this.f9538U = i;
        this.f9539V = Integer.MIN_VALUE;
        j jVar = this.f9537T;
        if (jVar != null) {
            jVar.f3592q = -1;
        }
        M0();
    }

    @Override // androidx.recyclerview.widget.a
    public final int Q0(int i, i0 i0Var, p0 p0Var) {
        if (j() || (this.f9525G == 0 && !j())) {
            int iP1 = p1(i, i0Var, p0Var);
            this.f9541Y.clear();
            return iP1;
        }
        int iQ1 = q1(i);
        this.f9534Q.f3570d += iQ1;
        this.f9536S.r(-iQ1);
        return iQ1;
    }

    @Override // androidx.recyclerview.widget.a
    public final boolean Y() {
        return true;
    }

    @Override // androidx.recyclerview.widget.a
    public final void Z0(RecyclerView recyclerView, p0 p0Var, int i) {
        H h8 = new H(recyclerView.getContext());
        h8.f4460a = i;
        a1(h8);
    }

    @Override // K2.a
    public final void a(View view, int i, int i5, c cVar) {
        o(view, f9523d0);
        if (j()) {
            int i8 = ((C0203d0) view.getLayoutParams()).f4521r.left + ((C0203d0) view.getLayoutParams()).f4521r.right;
            cVar.f3537e += i8;
            cVar.f3538f += i8;
        } else {
            int i9 = ((C0203d0) view.getLayoutParams()).f4521r.top + ((C0203d0) view.getLayoutParams()).f4521r.bottom;
            cVar.f3537e += i9;
            cVar.f3538f += i9;
        }
    }

    @Override // K2.a
    public final View b(int i) {
        View view = (View) this.f9541Y.get(i);
        return view != null ? view : this.f9531N.d(i);
    }

    @Override // K2.a
    public final int c(View view, int i, int i5) {
        return j() ? ((C0203d0) view.getLayoutParams()).f4521r.left + ((C0203d0) view.getLayoutParams()).f4521r.right : ((C0203d0) view.getLayoutParams()).f4521r.top + ((C0203d0) view.getLayoutParams()).f4521r.bottom;
    }

    public final int c1(p0 p0Var) {
        if (I() == 0) {
            return 0;
        }
        int iB = p0Var.b();
        f1();
        View viewH1 = h1(iB);
        View viewJ1 = j1(iB);
        if (p0Var.b() == 0 || viewH1 == null || viewJ1 == null) {
            return 0;
        }
        return Math.min(this.f9535R.n(), this.f9535R.d(viewJ1) - this.f9535R.g(viewH1));
    }

    @Override // K2.a
    public final int d(int i, int i5, int i8) {
        return a.J(q(), this.f9113E, this.f9112C, i5, i8);
    }

    public final int d1(p0 p0Var) {
        if (I() == 0) {
            return 0;
        }
        int iB = p0Var.b();
        View viewH1 = h1(iB);
        View viewJ1 = j1(iB);
        if (p0Var.b() == 0 || viewH1 == null || viewJ1 == null) {
            return 0;
        }
        int iT = a.T(viewH1);
        int iT2 = a.T(viewJ1);
        int iAbs = Math.abs(this.f9535R.d(viewJ1) - this.f9535R.g(viewH1));
        int i = ((int[]) this.f9530M.f3554s)[iT];
        if (i == 0 || i == -1) {
            return 0;
        }
        return Math.round((i * (iAbs / ((r3[iT2] - i) + 1))) + (this.f9535R.m() - this.f9535R.g(viewH1)));
    }

    public final int e1(p0 p0Var) {
        if (I() != 0) {
            int iB = p0Var.b();
            View viewH1 = h1(iB);
            View viewJ1 = j1(iB);
            if (p0Var.b() != 0 && viewH1 != null && viewJ1 != null) {
                View viewL1 = l1(0, I());
                int iT = viewL1 == null ? -1 : a.T(viewL1);
                return (int) ((Math.abs(this.f9535R.d(viewJ1) - this.f9535R.g(viewH1)) / (((l1(I() - 1, -1) != null ? a.T(r4) : -1) - iT) + 1)) * p0Var.b());
            }
        }
        return 0;
    }

    @Override // N1.o0
    public final PointF f(int i) {
        View viewH;
        if (I() == 0 || (viewH = H(0)) == null) {
            return null;
        }
        int i5 = i < a.T(viewH) ? -1 : 1;
        return j() ? new PointF(0.0f, i5) : new PointF(i5, 0.0f);
    }

    public final void f1() {
        if (this.f9535R != null) {
            return;
        }
        if (j()) {
            if (this.f9525G == 0) {
                this.f9535R = new L(this, 0);
                this.f9536S = new L(this, 1);
                return;
            } else {
                this.f9535R = new L(this, 1);
                this.f9536S = new L(this, 0);
                return;
            }
        }
        if (this.f9525G == 0) {
            this.f9535R = new L(this, 1);
            this.f9536S = new L(this, 0);
        } else {
            this.f9535R = new L(this, 0);
            this.f9536S = new L(this, 1);
        }
    }

    @Override // K2.a
    public final View g(int i) {
        return b(i);
    }

    @Override // androidx.recyclerview.widget.a
    public final void g0(T t6, T t8) {
        F0();
    }

    public final int g1(i0 i0Var, p0 p0Var, i iVar) {
        int i;
        int i5;
        boolean z8;
        int i8;
        int i9;
        int i10;
        e eVar;
        int i11;
        Rect rect;
        float f3;
        int i12;
        int i13;
        int i14;
        boolean z9;
        boolean z10;
        int i15;
        int i16;
        e eVar2;
        Rect rect2;
        int i17;
        int i18;
        int i19 = iVar.f3589f;
        if (i19 != Integer.MIN_VALUE) {
            int i20 = iVar.f3584a;
            if (i20 < 0) {
                iVar.f3589f = i19 + i20;
            }
            r1(i0Var, iVar);
        }
        int i21 = iVar.f3584a;
        boolean zJ = j();
        int i22 = i21;
        int i23 = 0;
        while (true) {
            if (i22 <= 0 && !this.f9533P.f3585b) {
                break;
            }
            List list = this.f9529L;
            int i24 = iVar.f3587d;
            if (i24 < 0 || i24 >= p0Var.b() || (i = iVar.f3586c) < 0 || i >= list.size()) {
                break;
            }
            c cVar = (c) this.f9529L.get(iVar.f3586c);
            iVar.f3587d = cVar.f3546o;
            boolean zJ2 = j();
            g gVar = this.f9534Q;
            e eVar3 = this.f9530M;
            Rect rect3 = f9523d0;
            if (zJ2) {
                int paddingLeft = getPaddingLeft();
                int paddingRight = getPaddingRight();
                int i25 = this.D;
                int i26 = iVar.f3588e;
                if (iVar.f3591h == -1) {
                    i26 -= cVar.f3539g;
                }
                int i27 = i26;
                int i28 = iVar.f3587d;
                float f7 = gVar.f3570d;
                float f8 = paddingLeft - f7;
                float measuredWidth = (i25 - paddingRight) - f7;
                float fMax = Math.max(0.0f, 0.0f);
                int i29 = cVar.f3540h;
                i5 = i21;
                int i30 = i28;
                int i31 = 0;
                while (i30 < i28 + i29) {
                    int i32 = i28;
                    View viewB = b(i30);
                    if (viewB == null) {
                        i15 = i31;
                        i18 = i32;
                        z10 = zJ;
                        i16 = i29;
                        eVar2 = eVar3;
                        rect2 = rect3;
                        i17 = i30;
                    } else {
                        z10 = zJ;
                        if (iVar.f3591h == 1) {
                            o(viewB, rect3);
                            l(viewB);
                        } else {
                            o(viewB, rect3);
                            m(viewB, i31, false);
                            i31++;
                        }
                        float f9 = measuredWidth;
                        long j8 = ((long[]) eVar3.f3555t)[i30];
                        int i33 = (int) j8;
                        int i34 = (int) (j8 >> 32);
                        if (t1(viewB, i33, i34, (h) viewB.getLayoutParams())) {
                            viewB.measure(i33, i34);
                        }
                        float f10 = f8 + ((ViewGroup.MarginLayoutParams) r6).leftMargin + ((C0203d0) viewB.getLayoutParams()).f4521r.left;
                        float f11 = f9 - (((ViewGroup.MarginLayoutParams) r6).rightMargin + ((C0203d0) viewB.getLayoutParams()).f4521r.right);
                        int i35 = i27 + ((C0203d0) viewB.getLayoutParams()).f4521r.top;
                        i15 = i31;
                        if (this.f9527J) {
                            i17 = i30;
                            i16 = i29;
                            eVar2 = eVar3;
                            rect2 = rect3;
                            i18 = i32;
                            this.f9530M.H(viewB, cVar, Math.round(f11) - viewB.getMeasuredWidth(), i35, Math.round(f11), viewB.getMeasuredHeight() + i35);
                        } else {
                            i16 = i29;
                            eVar2 = eVar3;
                            rect2 = rect3;
                            i17 = i30;
                            i18 = i32;
                            this.f9530M.H(viewB, cVar, Math.round(f10), i35, viewB.getMeasuredWidth() + Math.round(f10), viewB.getMeasuredHeight() + i35);
                        }
                        float measuredWidth2 = viewB.getMeasuredWidth() + ((ViewGroup.MarginLayoutParams) r6).rightMargin + ((C0203d0) viewB.getLayoutParams()).f4521r.right + fMax + f10;
                        measuredWidth = f11 - (((viewB.getMeasuredWidth() + ((ViewGroup.MarginLayoutParams) r6).leftMargin) + ((C0203d0) viewB.getLayoutParams()).f4521r.left) + fMax);
                        f8 = measuredWidth2;
                    }
                    i30 = i17 + 1;
                    eVar3 = eVar2;
                    i31 = i15;
                    zJ = z10;
                    i28 = i18;
                    i29 = i16;
                    rect3 = rect2;
                }
                z8 = zJ;
                iVar.f3586c += this.f9533P.f3591h;
                i10 = cVar.f3539g;
            } else {
                i5 = i21;
                z8 = zJ;
                e eVar4 = eVar3;
                Rect rect4 = rect3;
                boolean z11 = true;
                int paddingTop = getPaddingTop();
                int paddingBottom = getPaddingBottom();
                int i36 = this.f9113E;
                int i37 = iVar.f3588e;
                if (iVar.f3591h == -1) {
                    int i38 = cVar.f3539g;
                    i9 = i37 + i38;
                    i8 = i37 - i38;
                } else {
                    i8 = i37;
                    i9 = i8;
                }
                int i39 = iVar.f3587d;
                float f12 = gVar.f3570d;
                float f13 = paddingTop - f12;
                float f14 = (i36 - paddingBottom) - f12;
                float fMax2 = Math.max(0.0f, 0.0f);
                int i40 = cVar.f3540h;
                float measuredHeight = f14;
                int i41 = i39;
                float measuredHeight2 = f13;
                int i42 = 0;
                while (i41 < i39 + i40) {
                    float f15 = measuredHeight;
                    View viewB2 = b(i41);
                    if (viewB2 == null) {
                        Rect rect5 = rect4;
                        z9 = z11;
                        rect = rect5;
                        eVar = eVar4;
                        i11 = i8;
                        i12 = i40;
                        i14 = i39;
                        i13 = i41;
                        measuredHeight = f15;
                    } else {
                        eVar = eVar4;
                        i11 = i8;
                        long j9 = ((long[]) eVar4.f3555t)[i41];
                        int i43 = (int) j9;
                        int i44 = (int) (j9 >> 32);
                        if (t1(viewB2, i43, i44, (h) viewB2.getLayoutParams())) {
                            viewB2.measure(i43, i44);
                        }
                        float f16 = measuredHeight2 + ((ViewGroup.MarginLayoutParams) r4).topMargin + ((C0203d0) viewB2.getLayoutParams()).f4521r.top;
                        float f17 = f15 - (((ViewGroup.MarginLayoutParams) r4).rightMargin + ((C0203d0) viewB2.getLayoutParams()).f4521r.bottom);
                        if (iVar.f3591h == 1) {
                            rect = rect4;
                            o(viewB2, rect);
                            l(viewB2);
                            f3 = f17;
                        } else {
                            rect = rect4;
                            o(viewB2, rect);
                            f3 = f17;
                            m(viewB2, i42, false);
                            i42++;
                        }
                        int i45 = i11 + ((C0203d0) viewB2.getLayoutParams()).f4521r.left;
                        int i46 = i9 - ((C0203d0) viewB2.getLayoutParams()).f4521r.right;
                        int i47 = i39;
                        boolean z12 = this.f9527J;
                        if (!z12) {
                            i12 = i40;
                            i13 = i41;
                            i14 = i47;
                            z9 = true;
                            if (this.f9528K) {
                                this.f9530M.I(viewB2, cVar, z12, i45, Math.round(f3) - viewB2.getMeasuredHeight(), viewB2.getMeasuredWidth() + i45, Math.round(f3));
                            } else {
                                this.f9530M.I(viewB2, cVar, z12, i45, Math.round(f16), viewB2.getMeasuredWidth() + i45, viewB2.getMeasuredHeight() + Math.round(f16));
                            }
                        } else if (this.f9528K) {
                            z9 = true;
                            i12 = i40;
                            i14 = i47;
                            i13 = i41;
                            this.f9530M.I(viewB2, cVar, z12, i46 - viewB2.getMeasuredWidth(), Math.round(f3) - viewB2.getMeasuredHeight(), i46, Math.round(f3));
                        } else {
                            i12 = i40;
                            i13 = i41;
                            i14 = i47;
                            z9 = true;
                            this.f9530M.I(viewB2, cVar, z12, i46 - viewB2.getMeasuredWidth(), Math.round(f16), i46, viewB2.getMeasuredHeight() + Math.round(f16));
                        }
                        measuredHeight2 = viewB2.getMeasuredHeight() + ((ViewGroup.MarginLayoutParams) r4).topMargin + ((C0203d0) viewB2.getLayoutParams()).f4521r.bottom + fMax2 + f16;
                        measuredHeight = f3 - (((viewB2.getMeasuredHeight() + ((ViewGroup.MarginLayoutParams) r4).bottomMargin) + ((C0203d0) viewB2.getLayoutParams()).f4521r.top) + fMax2);
                    }
                    i41 = i13 + 1;
                    boolean z13 = z9;
                    rect4 = rect;
                    z11 = z13;
                    eVar4 = eVar;
                    i8 = i11;
                    i39 = i14;
                    i40 = i12;
                }
                iVar.f3586c += this.f9533P.f3591h;
                i10 = cVar.f3539g;
            }
            i23 += i10;
            if (z8 || !this.f9527J) {
                iVar.f3588e += cVar.f3539g * iVar.f3591h;
            } else {
                iVar.f3588e -= cVar.f3539g * iVar.f3591h;
            }
            i22 -= cVar.f3539g;
            i21 = i5;
            zJ = z8;
        }
        int i48 = i21;
        int i49 = iVar.f3584a - i23;
        iVar.f3584a = i49;
        int i50 = iVar.f3589f;
        if (i50 != Integer.MIN_VALUE) {
            int i51 = i50 + i23;
            iVar.f3589f = i51;
            if (i49 < 0) {
                iVar.f3589f = i51 + i49;
            }
            r1(i0Var, iVar);
        }
        return i48 - iVar.f3584a;
    }

    @Override // K2.a
    public final int getAlignContent() {
        return 5;
    }

    @Override // K2.a
    public final int getAlignItems() {
        return this.H;
    }

    @Override // K2.a
    public final int getFlexDirection() {
        return this.f9524F;
    }

    @Override // K2.a
    public final int getFlexItemCount() {
        return this.f9532O.b();
    }

    @Override // K2.a
    public final List getFlexLinesInternal() {
        return this.f9529L;
    }

    @Override // K2.a
    public final int getFlexWrap() {
        return this.f9525G;
    }

    @Override // K2.a
    public final int getLargestMainSize() {
        if (this.f9529L.size() == 0) {
            return 0;
        }
        int size = this.f9529L.size();
        int iMax = Integer.MIN_VALUE;
        for (int i = 0; i < size; i++) {
            iMax = Math.max(iMax, ((c) this.f9529L.get(i)).f3537e);
        }
        return iMax;
    }

    @Override // K2.a
    public final int getMaxLine() {
        return this.f9526I;
    }

    @Override // K2.a
    public final int getSumOfCrossSize() {
        int size = this.f9529L.size();
        int i = 0;
        for (int i5 = 0; i5 < size; i5++) {
            i += ((c) this.f9529L.get(i5)).f3539g;
        }
        return i;
    }

    @Override // K2.a
    public final void h(View view, int i) {
        this.f9541Y.put(i, view);
    }

    public final View h1(int i) {
        View viewM1 = m1(0, I(), i);
        if (viewM1 == null) {
            return null;
        }
        int i5 = ((int[]) this.f9530M.f3554s)[a.T(viewM1)];
        if (i5 == -1) {
            return null;
        }
        return i1(viewM1, (c) this.f9529L.get(i5));
    }

    @Override // K2.a
    public final int i(int i, int i5, int i8) {
        return a.J(p(), this.D, this.f9111B, i5, i8);
    }

    @Override // androidx.recyclerview.widget.a
    public final void i0(RecyclerView recyclerView) {
        this.f9543a0 = (View) recyclerView.getParent();
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x003b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final View i1(View view, c cVar) {
        boolean zJ = j();
        int i = cVar.f3540h;
        for (int i5 = 1; i5 < i; i5++) {
            View viewH = H(i5);
            if (viewH != null && viewH.getVisibility() != 8) {
                if (!this.f9527J || zJ) {
                    if (this.f9535R.g(view) > this.f9535R.g(viewH)) {
                        view = viewH;
                    }
                } else if (this.f9535R.d(view) < this.f9535R.d(viewH)) {
                }
            }
        }
        return view;
    }

    @Override // K2.a
    public final boolean j() {
        int i = this.f9524F;
        return i == 0 || i == 1;
    }

    public final View j1(int i) {
        View viewM1 = m1(I() - 1, -1, i);
        if (viewM1 == null) {
            return null;
        }
        return k1(viewM1, (c) this.f9529L.get(((int[]) this.f9530M.f3554s)[a.T(viewM1)]));
    }

    @Override // K2.a
    public final int k(View view) {
        return j() ? ((C0203d0) view.getLayoutParams()).f4521r.top + ((C0203d0) view.getLayoutParams()).f4521r.bottom : ((C0203d0) view.getLayoutParams()).f4521r.left + ((C0203d0) view.getLayoutParams()).f4521r.right;
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x0047  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final View k1(View view, c cVar) {
        boolean zJ = j();
        int I7 = (I() - cVar.f3540h) - 1;
        for (int I8 = I() - 2; I8 > I7; I8--) {
            View viewH = H(I8);
            if (viewH != null && viewH.getVisibility() != 8) {
                if (!this.f9527J || zJ) {
                    if (this.f9535R.d(view) < this.f9535R.d(viewH)) {
                        view = viewH;
                    }
                } else if (this.f9535R.g(view) > this.f9535R.g(viewH)) {
                }
            }
        }
        return view;
    }

    public final View l1(int i, int i5) {
        int i8 = i5 > i ? 1 : -1;
        while (i != i5) {
            View viewH = H(i);
            int paddingLeft = getPaddingLeft();
            int paddingTop = getPaddingTop();
            int paddingRight = this.D - getPaddingRight();
            int paddingBottom = this.f9113E - getPaddingBottom();
            int iN = N(viewH) - ((ViewGroup.MarginLayoutParams) ((C0203d0) viewH.getLayoutParams())).leftMargin;
            int iR = R(viewH) - ((ViewGroup.MarginLayoutParams) ((C0203d0) viewH.getLayoutParams())).topMargin;
            int iQ = Q(viewH) + ((ViewGroup.MarginLayoutParams) ((C0203d0) viewH.getLayoutParams())).rightMargin;
            int iL = L(viewH) + ((ViewGroup.MarginLayoutParams) ((C0203d0) viewH.getLayoutParams())).bottomMargin;
            boolean z8 = iN >= paddingRight || iQ >= paddingLeft;
            boolean z9 = iR >= paddingBottom || iL >= paddingTop;
            if (z8 && z9) {
                return viewH;
            }
            i += i8;
        }
        return null;
    }

    public final View m1(int i, int i5, int i8) {
        int iT;
        f1();
        if (this.f9533P == null) {
            i iVar = new i();
            iVar.f3591h = 1;
            this.f9533P = iVar;
        }
        int iM = this.f9535R.m();
        int i9 = this.f9535R.i();
        int i10 = i5 <= i ? -1 : 1;
        View view = null;
        View view2 = null;
        while (i != i5) {
            View viewH = H(i);
            if (viewH != null && (iT = a.T(viewH)) >= 0 && iT < i8) {
                if (((C0203d0) viewH.getLayoutParams()).f4520q.j()) {
                    if (view2 == null) {
                        view2 = viewH;
                    }
                } else {
                    if (this.f9535R.g(viewH) >= iM && this.f9535R.d(viewH) <= i9) {
                        return viewH;
                    }
                    if (view == null) {
                        view = viewH;
                    }
                }
            }
            i += i10;
        }
        return view != null ? view : view2;
    }

    public final int n1(int i, i0 i0Var, p0 p0Var, boolean z8) {
        int iP1;
        int i5;
        if (j() || !this.f9527J) {
            int i8 = this.f9535R.i() - i;
            if (i8 <= 0) {
                return 0;
            }
            iP1 = -p1(-i8, i0Var, p0Var);
        } else {
            int iM = i - this.f9535R.m();
            if (iM <= 0) {
                return 0;
            }
            iP1 = p1(iM, i0Var, p0Var);
        }
        int i9 = i + iP1;
        if (!z8 || (i5 = this.f9535R.i() - i9) <= 0) {
            return iP1;
        }
        this.f9535R.r(i5);
        return i5 + iP1;
    }

    public final int o1(int i, i0 i0Var, p0 p0Var, boolean z8) {
        int iP1;
        int iM;
        if (j() || !this.f9527J) {
            int iM2 = i - this.f9535R.m();
            if (iM2 <= 0) {
                return 0;
            }
            iP1 = -p1(iM2, i0Var, p0Var);
        } else {
            int i5 = this.f9535R.i() - i;
            if (i5 <= 0) {
                return 0;
            }
            iP1 = p1(-i5, i0Var, p0Var);
        }
        int i8 = i + iP1;
        if (!z8 || (iM = i8 - this.f9535R.m()) <= 0) {
            return iP1;
        }
        this.f9535R.r(-iM);
        return iP1 - iM;
    }

    @Override // androidx.recyclerview.widget.a
    public final boolean p() {
        if (this.f9525G == 0) {
            return j();
        }
        if (!j()) {
            return true;
        }
        int i = this.D;
        View view = this.f9543a0;
        return i > (view != null ? view.getWidth() : 0);
    }

    /* JADX WARN: Removed duplicated region for block: B:70:0x01ee  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x01f5  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int p1(int i, i0 i0Var, p0 p0Var) {
        int iG1;
        int i5;
        if (I() != 0 && i != 0) {
            f1();
            this.f9533P.i = true;
            boolean z8 = !j() && this.f9527J;
            int i8 = (!z8 ? i > 0 : i < 0) ? -1 : 1;
            int iAbs = Math.abs(i);
            this.f9533P.f3591h = i8;
            boolean zJ = j();
            int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(this.D, this.f9111B);
            int iMakeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(this.f9113E, this.f9112C);
            boolean z9 = !zJ && this.f9527J;
            e eVar = this.f9530M;
            if (i8 == 1) {
                View viewH = H(I() - 1);
                if (viewH != null) {
                    this.f9533P.f3588e = this.f9535R.d(viewH);
                    int iT = a.T(viewH);
                    View viewK1 = k1(viewH, (c) this.f9529L.get(((int[]) eVar.f3554s)[iT]));
                    i iVar = this.f9533P;
                    iVar.getClass();
                    int i9 = iT + 1;
                    iVar.f3587d = i9;
                    int[] iArr = (int[]) eVar.f3554s;
                    if (iArr.length <= i9) {
                        iVar.f3586c = -1;
                    } else {
                        iVar.f3586c = iArr[i9];
                    }
                    if (z9) {
                        iVar.f3588e = this.f9535R.g(viewK1);
                        this.f9533P.f3589f = this.f9535R.m() + (-this.f9535R.g(viewK1));
                        i iVar2 = this.f9533P;
                        iVar2.f3589f = Math.max(iVar2.f3589f, 0);
                    } else {
                        iVar.f3588e = this.f9535R.d(viewK1);
                        this.f9533P.f3589f = this.f9535R.d(viewK1) - this.f9535R.i();
                    }
                    int i10 = this.f9533P.f3586c;
                    if ((i10 == -1 || i10 > this.f9529L.size() - 1) && this.f9533P.f3587d <= this.f9532O.b()) {
                        i iVar3 = this.f9533P;
                        int i11 = iAbs - iVar3.f3589f;
                        C0005f c0005f = this.f9545c0;
                        c0005f.f156b = null;
                        c0005f.f155a = 0;
                        if (i11 > 0) {
                            if (zJ) {
                                this.f9530M.s(c0005f, iMakeMeasureSpec, iMakeMeasureSpec2, i11, iVar3.f3587d, -1, this.f9529L);
                            } else {
                                this.f9530M.s(c0005f, iMakeMeasureSpec2, iMakeMeasureSpec, i11, iVar3.f3587d, -1, this.f9529L);
                                iMakeMeasureSpec2 = iMakeMeasureSpec2;
                                iMakeMeasureSpec = iMakeMeasureSpec;
                            }
                            eVar.y(iMakeMeasureSpec, iMakeMeasureSpec2, this.f9533P.f3587d);
                            eVar.S(this.f9533P.f3587d);
                        }
                    }
                    i iVar4 = this.f9533P;
                    iVar4.f3584a = iAbs - iVar4.f3589f;
                }
                i iVar5 = this.f9533P;
                iG1 = g1(i0Var, p0Var, iVar5) + iVar5.f3589f;
                if (iG1 >= 0) {
                    if (z8) {
                        i5 = iAbs > iG1 ? (-i8) * iG1 : i;
                    } else if (iAbs > iG1) {
                        i5 = i8 * iG1;
                    }
                    this.f9535R.r(-i5);
                    this.f9533P.f3590g = i5;
                    return i5;
                }
            } else {
                View viewH2 = H(0);
                if (viewH2 != null) {
                    this.f9533P.f3588e = this.f9535R.g(viewH2);
                    int iT2 = a.T(viewH2);
                    View viewI1 = i1(viewH2, (c) this.f9529L.get(((int[]) eVar.f3554s)[iT2]));
                    i iVar6 = this.f9533P;
                    iVar6.getClass();
                    int i12 = ((int[]) eVar.f3554s)[iT2];
                    if (i12 == -1) {
                        i12 = 0;
                    }
                    if (i12 > 0) {
                        this.f9533P.f3587d = iT2 - ((c) this.f9529L.get(i12 - 1)).f3540h;
                    } else {
                        iVar6.f3587d = -1;
                    }
                    i iVar7 = this.f9533P;
                    iVar7.f3586c = i12 > 0 ? i12 - 1 : 0;
                    if (z9) {
                        iVar7.f3588e = this.f9535R.d(viewI1);
                        this.f9533P.f3589f = this.f9535R.d(viewI1) - this.f9535R.i();
                        i iVar8 = this.f9533P;
                        iVar8.f3589f = Math.max(iVar8.f3589f, 0);
                    } else {
                        iVar7.f3588e = this.f9535R.g(viewI1);
                        this.f9533P.f3589f = this.f9535R.m() + (-this.f9535R.g(viewI1));
                    }
                    i iVar42 = this.f9533P;
                    iVar42.f3584a = iAbs - iVar42.f3589f;
                }
                i iVar52 = this.f9533P;
                iG1 = g1(i0Var, p0Var, iVar52) + iVar52.f3589f;
                if (iG1 >= 0) {
                }
            }
        }
        return 0;
    }

    @Override // androidx.recyclerview.widget.a
    public final boolean q() {
        if (this.f9525G == 0) {
            return !j();
        }
        if (!j()) {
            int i = this.f9113E;
            View view = this.f9543a0;
            if (i <= (view != null ? view.getHeight() : 0)) {
                return false;
            }
        }
        return true;
    }

    @Override // androidx.recyclerview.widget.a
    public final void q0(RecyclerView recyclerView, int i, int i5) {
        u1(i);
    }

    public final int q1(int i) {
        if (I() == 0 || i == 0) {
            return 0;
        }
        f1();
        boolean zJ = j();
        View view = this.f9543a0;
        int width = zJ ? view.getWidth() : view.getHeight();
        int i5 = zJ ? this.D : this.f9113E;
        int layoutDirection = this.f9115r.getLayoutDirection();
        g gVar = this.f9534Q;
        if (layoutDirection == 1) {
            int iAbs = Math.abs(i);
            if (i < 0) {
                return -Math.min((i5 + gVar.f3570d) - width, iAbs);
            }
            int i8 = gVar.f3570d;
            if (i8 + i > 0) {
                return -i8;
            }
        } else {
            if (i > 0) {
                return Math.min((i5 - gVar.f3570d) - width, i);
            }
            int i9 = gVar.f3570d;
            if (i9 + i < 0) {
                return -i9;
            }
        }
        return i;
    }

    @Override // androidx.recyclerview.widget.a
    public final boolean r(C0203d0 c0203d0) {
        return c0203d0 instanceof h;
    }

    /* JADX WARN: Removed duplicated region for block: B:33:0x0069  */
    /* JADX WARN: Removed duplicated region for block: B:67:0x00e6  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void r1(i0 i0Var, i iVar) {
        int I7;
        int i;
        int I8;
        int i5;
        View viewH;
        int i8;
        if (iVar.i) {
            int i9 = iVar.f3591h;
            int i10 = -1;
            e eVar = this.f9530M;
            if (i9 == -1) {
                if (iVar.f3589f < 0 || (I8 = I()) == 0 || (viewH = H(I8 - 1)) == null || (i8 = ((int[]) eVar.f3554s)[a.T(viewH)]) == -1) {
                    return;
                }
                c cVar = (c) this.f9529L.get(i8);
                int i11 = i5;
                while (true) {
                    if (i11 < 0) {
                        break;
                    }
                    View viewH2 = H(i11);
                    if (viewH2 != null) {
                        int i12 = iVar.f3589f;
                        if (!j() && this.f9527J) {
                            if (this.f9535R.d(viewH2) > i12) {
                                break;
                            }
                        } else {
                            if (this.f9535R.g(viewH2) < this.f9535R.h() - i12) {
                                break;
                            }
                            if (cVar.f3546o != a.T(viewH2)) {
                                continue;
                            } else if (i8 <= 0) {
                                I8 = i11;
                                break;
                            } else {
                                i8 += iVar.f3591h;
                                cVar = (c) this.f9529L.get(i8);
                                I8 = i11;
                            }
                        }
                    }
                    i11--;
                }
                while (i5 >= I8) {
                    J0(i5, i0Var);
                    i5--;
                }
                return;
            }
            if (iVar.f3589f >= 0 && (I7 = I()) != 0) {
                int i13 = 0;
                View viewH3 = H(0);
                if (viewH3 == null || (i = ((int[]) eVar.f3554s)[a.T(viewH3)]) == -1) {
                    return;
                }
                c cVar2 = (c) this.f9529L.get(i);
                while (true) {
                    if (i13 >= I7) {
                        break;
                    }
                    View viewH4 = H(i13);
                    if (viewH4 != null) {
                        int i14 = iVar.f3589f;
                        if (!j() && this.f9527J) {
                            if (this.f9535R.h() - this.f9535R.g(viewH4) > i14) {
                                break;
                            }
                        } else {
                            if (this.f9535R.d(viewH4) > i14) {
                                break;
                            }
                            if (cVar2.f3547p != a.T(viewH4)) {
                                continue;
                            } else if (i >= this.f9529L.size() - 1) {
                                i10 = i13;
                                break;
                            } else {
                                i += iVar.f3591h;
                                cVar2 = (c) this.f9529L.get(i);
                                i10 = i13;
                            }
                        }
                    }
                    i13++;
                }
                while (i10 >= 0) {
                    J0(i10, i0Var);
                    i10--;
                }
            }
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final void s0(RecyclerView recyclerView, int i, int i5) {
        u1(Math.min(i, i5));
    }

    public final void s1(int i) {
        if (this.f9524F != i) {
            F0();
            this.f9524F = i;
            this.f9535R = null;
            this.f9536S = null;
            this.f9529L.clear();
            g gVar = this.f9534Q;
            g.b(gVar);
            gVar.f3570d = 0;
            M0();
        }
    }

    @Override // K2.a
    public final void setFlexLines(List list) {
        this.f9529L = list;
    }

    @Override // androidx.recyclerview.widget.a
    public final void t0(RecyclerView recyclerView, int i, int i5) {
        u1(i);
    }

    public final boolean t1(View view, int i, int i5, h hVar) {
        return (!view.isLayoutRequested() && this.f9121x && a0(view.getWidth(), i, ((ViewGroup.MarginLayoutParams) hVar).width) && a0(view.getHeight(), i5, ((ViewGroup.MarginLayoutParams) hVar).height)) ? false : true;
    }

    @Override // androidx.recyclerview.widget.a
    public final void u0(int i, int i5) {
        u1(i);
    }

    public final void u1(int i) {
        View viewL1 = l1(I() - 1, -1);
        if (i >= (viewL1 != null ? a.T(viewL1) : -1)) {
            return;
        }
        int I7 = I();
        e eVar = this.f9530M;
        eVar.A(I7);
        eVar.B(I7);
        eVar.z(I7);
        if (i >= ((int[]) eVar.f3554s).length) {
            return;
        }
        this.f9544b0 = i;
        View viewH = H(0);
        if (viewH == null) {
            return;
        }
        this.f9538U = a.T(viewH);
        if (j() || !this.f9527J) {
            this.f9539V = this.f9535R.g(viewH) - this.f9535R.m();
        } else {
            this.f9539V = this.f9535R.j() + this.f9535R.d(viewH);
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final int v(p0 p0Var) {
        return c1(p0Var);
    }

    @Override // androidx.recyclerview.widget.a
    public final void v0(RecyclerView recyclerView, int i, int i5) {
        u1(i);
        u1(i);
    }

    public final void v1(g gVar, boolean z8, boolean z9) {
        int i;
        if (z9) {
            int i5 = j() ? this.f9112C : this.f9111B;
            this.f9533P.f3585b = i5 == 0 || i5 == Integer.MIN_VALUE;
        } else {
            this.f9533P.f3585b = false;
        }
        if (j() || !this.f9527J) {
            this.f9533P.f3584a = this.f9535R.i() - gVar.f3569c;
        } else {
            this.f9533P.f3584a = gVar.f3569c - getPaddingRight();
        }
        i iVar = this.f9533P;
        iVar.f3587d = gVar.f3567a;
        iVar.f3591h = 1;
        iVar.f3588e = gVar.f3569c;
        iVar.f3589f = Integer.MIN_VALUE;
        iVar.f3586c = gVar.f3568b;
        if (!z8 || this.f9529L.size() <= 1 || (i = gVar.f3568b) < 0 || i >= this.f9529L.size() - 1) {
            return;
        }
        c cVar = (c) this.f9529L.get(gVar.f3568b);
        i iVar2 = this.f9533P;
        iVar2.f3586c++;
        iVar2.f3587d += cVar.f3540h;
    }

    @Override // androidx.recyclerview.widget.a
    public final int w(p0 p0Var) {
        return d1(p0Var);
    }

    /* JADX WARN: Removed duplicated region for block: B:111:0x01af  */
    /* JADX WARN: Removed duplicated region for block: B:144:0x023b  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x00f0  */
    @Override // androidx.recyclerview.widget.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void w0(i0 i0Var, p0 p0Var) {
        int i;
        View viewH;
        boolean z8;
        int i5;
        int i8;
        int i9;
        int i10;
        this.f9531N = i0Var;
        this.f9532O = p0Var;
        int iB = p0Var.b();
        if (iB == 0 && p0Var.f4620g) {
            return;
        }
        int layoutDirection = this.f9115r.getLayoutDirection();
        int i11 = this.f9524F;
        if (i11 == 0) {
            this.f9527J = layoutDirection == 1;
            this.f9528K = this.f9525G == 2;
        } else if (i11 == 1) {
            this.f9527J = layoutDirection != 1;
            this.f9528K = this.f9525G == 2;
        } else if (i11 == 2) {
            boolean z9 = layoutDirection == 1;
            this.f9527J = z9;
            if (this.f9525G == 2) {
                this.f9527J = !z9;
            }
            this.f9528K = false;
        } else if (i11 != 3) {
            this.f9527J = false;
            this.f9528K = false;
        } else {
            boolean z10 = layoutDirection == 1;
            this.f9527J = z10;
            if (this.f9525G == 2) {
                this.f9527J = !z10;
            }
            this.f9528K = true;
        }
        f1();
        if (this.f9533P == null) {
            i iVar = new i();
            iVar.f3591h = 1;
            this.f9533P = iVar;
        }
        e eVar = this.f9530M;
        eVar.A(iB);
        eVar.B(iB);
        eVar.z(iB);
        this.f9533P.i = false;
        j jVar = this.f9537T;
        if (jVar != null && (i10 = jVar.f3592q) >= 0 && i10 < iB) {
            this.f9538U = i10;
        }
        g gVar = this.f9534Q;
        if (!gVar.f3572f || this.f9538U != -1 || jVar != null) {
            g.b(gVar);
            j jVar2 = this.f9537T;
            if (p0Var.f4620g || (i = this.f9538U) == -1) {
                if (I() != 0) {
                    View viewJ1 = gVar.f3571e ? j1(p0Var.b()) : h1(p0Var.b());
                    if (viewJ1 != null) {
                        FlexboxLayoutManager flexboxLayoutManager = gVar.f3574h;
                        M m8 = flexboxLayoutManager.f9525G == 0 ? flexboxLayoutManager.f9536S : flexboxLayoutManager.f9535R;
                        if (flexboxLayoutManager.j() || !flexboxLayoutManager.f9527J) {
                            if (gVar.f3571e) {
                                gVar.f3569c = m8.o() + m8.d(viewJ1);
                            } else {
                                gVar.f3569c = m8.g(viewJ1);
                            }
                        } else if (gVar.f3571e) {
                            gVar.f3569c = m8.o() + m8.g(viewJ1);
                        } else {
                            gVar.f3569c = m8.d(viewJ1);
                        }
                        int iT = a.T(viewJ1);
                        gVar.f3567a = iT;
                        gVar.f3573g = false;
                        int[] iArr = (int[]) flexboxLayoutManager.f9530M.f3554s;
                        if (iT == -1) {
                            iT = 0;
                        }
                        int i12 = iArr[iT];
                        if (i12 == -1) {
                            i12 = 0;
                        }
                        gVar.f3568b = i12;
                        int size = flexboxLayoutManager.f9529L.size();
                        int i13 = gVar.f3568b;
                        if (size > i13) {
                            gVar.f3567a = ((c) flexboxLayoutManager.f9529L.get(i13)).f3546o;
                        }
                        boolean z11 = p0Var.f4620g;
                    } else {
                        g.a(gVar);
                        gVar.f3567a = 0;
                        gVar.f3568b = 0;
                    }
                    gVar.f3572f = true;
                }
            } else if (i < 0 || i >= p0Var.b()) {
                this.f9538U = -1;
                this.f9539V = Integer.MIN_VALUE;
                if (I() != 0) {
                }
            } else {
                int i14 = this.f9538U;
                gVar.f3567a = i14;
                gVar.f3568b = ((int[]) eVar.f3554s)[i14];
                j jVar3 = this.f9537T;
                if (jVar3 != null) {
                    int iB2 = p0Var.b();
                    int i15 = jVar3.f3592q;
                    if (i15 >= 0 && i15 < iB2) {
                        gVar.f3569c = this.f9535R.m() + jVar2.f3593r;
                        gVar.f3573g = true;
                        gVar.f3568b = -1;
                    } else if (this.f9539V == Integer.MIN_VALUE) {
                        View viewD = D(this.f9538U);
                        if (viewD == null) {
                            if (I() > 0 && (viewH = H(0)) != null) {
                                gVar.f3571e = this.f9538U < a.T(viewH);
                            }
                            g.a(gVar);
                        } else if (this.f9535R.e(viewD) > this.f9535R.n()) {
                            g.a(gVar);
                        } else if (this.f9535R.g(viewD) - this.f9535R.m() < 0) {
                            gVar.f3569c = this.f9535R.m();
                            gVar.f3571e = false;
                        } else if (this.f9535R.i() - this.f9535R.d(viewD) < 0) {
                            gVar.f3569c = this.f9535R.i();
                            gVar.f3571e = true;
                        } else {
                            gVar.f3569c = gVar.f3571e ? this.f9535R.o() + this.f9535R.d(viewD) : this.f9535R.g(viewD);
                        }
                    } else if (j() || !this.f9527J) {
                        gVar.f3569c = this.f9535R.m() + this.f9539V;
                    } else {
                        gVar.f3569c = this.f9539V - this.f9535R.j();
                    }
                    gVar.f3572f = true;
                }
            }
        }
        B(i0Var);
        if (gVar.f3571e) {
            w1(gVar, false, true);
        } else {
            v1(gVar, false, true);
        }
        int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(this.D, this.f9111B);
        int iMakeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(this.f9113E, this.f9112C);
        int i16 = this.D;
        int i17 = this.f9113E;
        boolean zJ = j();
        Context context = this.f9542Z;
        if (zJ) {
            int i18 = this.f9540W;
            z8 = (i18 == Integer.MIN_VALUE || i18 == i16) ? false : true;
            i iVar2 = this.f9533P;
            i5 = iVar2.f3585b ? context.getResources().getDisplayMetrics().heightPixels : iVar2.f3584a;
        } else {
            int i19 = this.X;
            z8 = (i19 == Integer.MIN_VALUE || i19 == i17) ? false : true;
            i iVar3 = this.f9533P;
            i5 = iVar3.f3585b ? context.getResources().getDisplayMetrics().widthPixels : iVar3.f3584a;
        }
        int i20 = i5;
        this.f9540W = i16;
        this.X = i17;
        int i21 = this.f9544b0;
        C0005f c0005f = this.f9545c0;
        if (i21 != -1 || (this.f9538U == -1 && !z8)) {
            int iMin = i21 != -1 ? Math.min(i21, gVar.f3567a) : gVar.f3567a;
            c0005f.f156b = null;
            c0005f.f155a = 0;
            if (j()) {
                if (this.f9529L.size() > 0) {
                    eVar.u(iMin, this.f9529L);
                    this.f9530M.s(this.f9545c0, iMakeMeasureSpec, iMakeMeasureSpec2, i20, iMin, gVar.f3567a, this.f9529L);
                } else {
                    eVar.z(iB);
                    this.f9530M.s(this.f9545c0, iMakeMeasureSpec, iMakeMeasureSpec2, i20, 0, -1, this.f9529L);
                }
            } else if (this.f9529L.size() > 0) {
                eVar.u(iMin, this.f9529L);
                int i22 = iMin;
                this.f9530M.s(this.f9545c0, iMakeMeasureSpec2, iMakeMeasureSpec, i20, i22, gVar.f3567a, this.f9529L);
                iMakeMeasureSpec2 = iMakeMeasureSpec2;
                iMakeMeasureSpec = iMakeMeasureSpec;
                iMin = i22;
            } else {
                eVar.z(iB);
                this.f9530M.s(this.f9545c0, iMakeMeasureSpec2, iMakeMeasureSpec, i20, 0, -1, this.f9529L);
                iMakeMeasureSpec2 = iMakeMeasureSpec2;
                iMakeMeasureSpec = iMakeMeasureSpec;
            }
            this.f9529L = c0005f.f156b;
            eVar.y(iMakeMeasureSpec, iMakeMeasureSpec2, iMin);
            eVar.S(iMin);
        } else if (!gVar.f3571e) {
            this.f9529L.clear();
            c0005f.f156b = null;
            c0005f.f155a = 0;
            if (j()) {
                this.f9530M.s(this.f9545c0, iMakeMeasureSpec, iMakeMeasureSpec2, i20, 0, gVar.f3567a, this.f9529L);
            } else {
                this.f9530M.s(this.f9545c0, iMakeMeasureSpec2, iMakeMeasureSpec, i20, 0, gVar.f3567a, this.f9529L);
                iMakeMeasureSpec2 = iMakeMeasureSpec2;
                iMakeMeasureSpec = iMakeMeasureSpec;
            }
            this.f9529L = c0005f.f156b;
            eVar.y(iMakeMeasureSpec, iMakeMeasureSpec2, 0);
            eVar.S(0);
            int i23 = ((int[]) eVar.f3554s)[gVar.f3567a];
            gVar.f3568b = i23;
            this.f9533P.f3586c = i23;
        }
        g1(i0Var, p0Var, this.f9533P);
        if (gVar.f3571e) {
            i9 = this.f9533P.f3588e;
            v1(gVar, true, false);
            g1(i0Var, p0Var, this.f9533P);
            i8 = this.f9533P.f3588e;
        } else {
            i8 = this.f9533P.f3588e;
            w1(gVar, true, false);
            g1(i0Var, p0Var, this.f9533P);
            i9 = this.f9533P.f3588e;
        }
        if (I() > 0) {
            if (gVar.f3571e) {
                o1(n1(i8, i0Var, p0Var, true) + i9, i0Var, p0Var, false);
            } else {
                n1(o1(i9, i0Var, p0Var, true) + i8, i0Var, p0Var, false);
            }
        }
    }

    public final void w1(g gVar, boolean z8, boolean z9) {
        if (z9) {
            int i = j() ? this.f9112C : this.f9111B;
            this.f9533P.f3585b = i == 0 || i == Integer.MIN_VALUE;
        } else {
            this.f9533P.f3585b = false;
        }
        if (j() || !this.f9527J) {
            this.f9533P.f3584a = gVar.f3569c - this.f9535R.m();
        } else {
            this.f9533P.f3584a = (this.f9543a0.getWidth() - gVar.f3569c) - this.f9535R.m();
        }
        i iVar = this.f9533P;
        iVar.f3587d = gVar.f3567a;
        iVar.f3591h = -1;
        iVar.f3588e = gVar.f3569c;
        iVar.f3589f = Integer.MIN_VALUE;
        int i5 = gVar.f3568b;
        iVar.f3586c = i5;
        if (!z8 || i5 <= 0) {
            return;
        }
        int size = this.f9529L.size();
        int i8 = gVar.f3568b;
        if (size > i8) {
            c cVar = (c) this.f9529L.get(i8);
            i iVar2 = this.f9533P;
            iVar2.f3586c--;
            iVar2.f3587d -= cVar.f3540h;
        }
    }

    @Override // androidx.recyclerview.widget.a
    public final int x(p0 p0Var) {
        return e1(p0Var);
    }

    @Override // androidx.recyclerview.widget.a
    public final void x0(p0 p0Var) {
        this.f9537T = null;
        this.f9538U = -1;
        this.f9539V = Integer.MIN_VALUE;
        this.f9544b0 = -1;
        g.b(this.f9534Q);
        this.f9541Y.clear();
    }

    @Override // androidx.recyclerview.widget.a
    public final int y(p0 p0Var) {
        return c1(p0Var);
    }

    @Override // androidx.recyclerview.widget.a
    public final int z(p0 p0Var) {
        return d1(p0Var);
    }

    @Override // K2.a
    public final void e(c cVar) {
    }

    @Override // androidx.recyclerview.widget.a
    public final void j0(RecyclerView recyclerView, i0 i0Var) {
    }
}
