package com.google.android.flexbox;

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.d1;
import androidx.recyclerview.widget.d2;
import androidx.recyclerview.widget.f2;
import androidx.recyclerview.widget.p1;
import androidx.recyclerview.widget.q1;
import androidx.recyclerview.widget.r1;
import androidx.recyclerview.widget.t0;
import androidx.recyclerview.widget.w0;
import androidx.recyclerview.widget.x0;
import androidx.recyclerview.widget.y1;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: loaded from: classes2.dex */
public class FlexboxLayoutManager extends q1 implements a, d2 {

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public static final Rect f7780c0 = new Rect();
    public w0 Q;
    public w0 R;
    public k S;
    public final Context Y;
    public View Z;

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public f2 f7793k;

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

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

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final f f7791i = new f(this);

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final h f7795m = new h(this);
    public int T = -1;
    public int U = Integer.MIN_VALUE;
    public int V = Integer.MIN_VALUE;
    public int W = Integer.MIN_VALUE;
    public final SparseArray X = new SparseArray();

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

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public final d f7784b0 = new d();

    public FlexboxLayoutManager(Context context) {
        E(0);
        F(1);
        if (this.f7786d != 4) {
            removeAllViews();
            this.f7790h.clear();
            h hVar = this.f7795m;
            h.b(hVar);
            hVar.f7833d = 0;
            this.f7786d = 4;
            requestLayout();
        }
        this.Y = context;
    }

    public static boolean l(int i10, int i11, int i12) {
        int mode = View.MeasureSpec.getMode(i11);
        int size = View.MeasureSpec.getSize(i11);
        if (i12 > 0 && i10 != i12) {
            return false;
        }
        if (mode == Integer.MIN_VALUE) {
            return size >= i10;
        }
        if (mode != 0) {
            return mode == 1073741824 && size == i10;
        }
        return true;
    }

    /* JADX WARN: Removed duplicated region for block: B:73:0x01ea  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int A(int i10, y1 y1Var, f2 f2Var) {
        int i11;
        f fVar;
        if (getChildCount() == 0 || i10 == 0) {
            return 0;
        }
        q();
        this.f7794l.f7856j = true;
        boolean z10 = !i() && this.f7788f;
        int i12 = (!z10 ? i10 > 0 : i10 < 0) ? -1 : 1;
        int iAbs = Math.abs(i10);
        this.f7794l.f7855i = i12;
        boolean zI = i();
        int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(getWidth(), getWidthMode());
        int iMakeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(getHeight(), getHeightMode());
        boolean z11 = !zI && this.f7788f;
        f fVar2 = this.f7791i;
        if (i12 == 1) {
            View childAt = getChildAt(getChildCount() - 1);
            if (childAt != null) {
                this.f7794l.f7851e = this.Q.d(childAt);
                int position = getPosition(childAt);
                View viewV = v(childAt, (c) this.f7790h.get(fVar2.mIndexToFlexLine[position]));
                j jVar = this.f7794l;
                jVar.f7854h = 1;
                int i13 = position + 1;
                jVar.f7850d = i13;
                int[] iArr = fVar2.mIndexToFlexLine;
                if (iArr.length <= i13) {
                    jVar.f7849c = -1;
                } else {
                    jVar.f7849c = iArr[i13];
                }
                if (z11) {
                    jVar.f7851e = this.Q.g(viewV);
                    this.f7794l.f7852f = this.Q.k() + (-this.Q.g(viewV));
                    j jVar2 = this.f7794l;
                    jVar2.f7852f = Math.max(jVar2.f7852f, 0);
                } else {
                    jVar.f7851e = this.Q.d(viewV);
                    this.f7794l.f7852f = this.Q.d(viewV) - this.Q.i();
                }
                int i14 = this.f7794l.f7849c;
                if ((i14 == -1 || i14 > this.f7790h.size() - 1) && this.f7794l.f7850d <= this.f7793k.b()) {
                    j jVar3 = this.f7794l;
                    int i15 = iAbs - jVar3.f7852f;
                    d dVar = this.f7784b0;
                    dVar.f7814a = null;
                    dVar.f7815b = 0;
                    if (i15 > 0) {
                        if (zI) {
                            fVar = fVar2;
                            this.f7791i.calculateHorizontalFlexLines(dVar, iMakeMeasureSpec, iMakeMeasureSpec2, i15, jVar3.f7850d, this.f7790h);
                        } else {
                            fVar = fVar2;
                            this.f7791i.calculateVerticalFlexLines(dVar, iMakeMeasureSpec, iMakeMeasureSpec2, i15, jVar3.f7850d, this.f7790h);
                        }
                        fVar.g(iMakeMeasureSpec, iMakeMeasureSpec2, this.f7794l.f7850d);
                        fVar.t(this.f7794l.f7850d);
                    }
                }
                j jVar4 = this.f7794l;
                jVar4.f7847a = iAbs - jVar4.f7852f;
            }
        } else {
            View childAt2 = getChildAt(0);
            if (childAt2 != null) {
                this.f7794l.f7851e = this.Q.g(childAt2);
                int position2 = getPosition(childAt2);
                View viewT = t(childAt2, (c) this.f7790h.get(fVar2.mIndexToFlexLine[position2]));
                j jVar5 = this.f7794l;
                jVar5.f7854h = 1;
                int i16 = fVar2.mIndexToFlexLine[position2];
                if (i16 == -1) {
                    i16 = 0;
                }
                if (i16 > 0) {
                    this.f7794l.f7850d = position2 - ((c) this.f7790h.get(i16 - 1)).f7803h;
                } else {
                    jVar5.f7850d = -1;
                }
                j jVar6 = this.f7794l;
                jVar6.f7849c = i16 > 0 ? i16 - 1 : 0;
                if (z11) {
                    jVar6.f7851e = this.Q.d(viewT);
                    this.f7794l.f7852f = this.Q.d(viewT) - this.Q.i();
                    j jVar7 = this.f7794l;
                    jVar7.f7852f = Math.max(jVar7.f7852f, 0);
                } else {
                    jVar6.f7851e = this.Q.g(viewT);
                    this.f7794l.f7852f = this.Q.k() + (-this.Q.g(viewT));
                }
                j jVar42 = this.f7794l;
                jVar42.f7847a = iAbs - jVar42.f7852f;
            }
        }
        j jVar8 = this.f7794l;
        int iR = r(y1Var, f2Var, jVar8) + jVar8.f7852f;
        if (iR < 0) {
            return 0;
        }
        if (z10) {
            i11 = iAbs > iR ? (-i12) * iR : i10;
        } else if (iAbs > iR) {
            i11 = i12 * iR;
        }
        this.Q.p(-i11);
        this.f7794l.f7853g = i11;
        return i11;
    }

    public final int B(int i10) {
        int i11;
        if (getChildCount() == 0 || i10 == 0) {
            return 0;
        }
        q();
        boolean zI = i();
        View view = this.Z;
        int width = zI ? view.getWidth() : view.getHeight();
        int width2 = zI ? getWidth() : getHeight();
        int layoutDirection = getLayoutDirection();
        h hVar = this.f7795m;
        if (layoutDirection == 1) {
            int iAbs = Math.abs(i10);
            if (i10 < 0) {
                return -Math.min((width2 + hVar.f7833d) - width, iAbs);
            }
            i11 = hVar.f7833d;
            if (i11 + i10 <= 0) {
                return i10;
            }
        } else {
            if (i10 > 0) {
                return Math.min((width2 - hVar.f7833d) - width, i10);
            }
            i11 = hVar.f7833d;
            if (i11 + i10 >= 0) {
                return i10;
            }
        }
        return -i11;
    }

    /* JADX WARN: Removed duplicated region for block: B:33:0x0066  */
    /* JADX WARN: Removed duplicated region for block: B:67:0x00e1  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void C(y1 y1Var, j jVar) {
        int childCount;
        int i10;
        int childCount2;
        int i11;
        View childAt;
        int i12;
        if (jVar.f7856j) {
            int i13 = jVar.f7855i;
            int i14 = -1;
            f fVar = this.f7791i;
            if (i13 == -1) {
                if (jVar.f7852f < 0 || (childCount2 = getChildCount()) == 0 || (childAt = getChildAt(childCount2 - 1)) == null || (i12 = fVar.mIndexToFlexLine[getPosition(childAt)]) == -1) {
                    return;
                }
                c cVar = (c) this.f7790h.get(i12);
                int i15 = i11;
                while (true) {
                    if (i15 < 0) {
                        break;
                    }
                    View childAt2 = getChildAt(i15);
                    if (childAt2 != null) {
                        int i16 = jVar.f7852f;
                        if (!i() && this.f7788f) {
                            if (this.Q.d(childAt2) > i16) {
                                break;
                            }
                        } else {
                            if (this.Q.g(childAt2) < this.Q.h() - i16) {
                                break;
                            }
                            if (cVar.f7810o != getPosition(childAt2)) {
                                continue;
                            } else if (i12 <= 0) {
                                childCount2 = i15;
                                break;
                            } else {
                                i12 += jVar.f7855i;
                                cVar = (c) this.f7790h.get(i12);
                                childCount2 = i15;
                            }
                        }
                    }
                    i15--;
                }
                while (i11 >= childCount2) {
                    removeAndRecycleViewAt(i11, y1Var);
                    i11--;
                }
                return;
            }
            if (jVar.f7852f >= 0 && (childCount = getChildCount()) != 0) {
                int i17 = 0;
                View childAt3 = getChildAt(0);
                if (childAt3 == null || (i10 = fVar.mIndexToFlexLine[getPosition(childAt3)]) == -1) {
                    return;
                }
                c cVar2 = (c) this.f7790h.get(i10);
                while (true) {
                    if (i17 >= childCount) {
                        break;
                    }
                    View childAt4 = getChildAt(i17);
                    if (childAt4 != null) {
                        int i18 = jVar.f7852f;
                        if (!i() && this.f7788f) {
                            if (this.Q.h() - this.Q.g(childAt4) > i18) {
                                break;
                            }
                        } else {
                            if (this.Q.d(childAt4) > i18) {
                                break;
                            }
                            if (cVar2.f7811p != getPosition(childAt4)) {
                                continue;
                            } else if (i10 >= this.f7790h.size() - 1) {
                                i14 = i17;
                                break;
                            } else {
                                i10 += jVar.f7855i;
                                cVar2 = (c) this.f7790h.get(i10);
                                i14 = i17;
                            }
                        }
                    }
                    i17++;
                }
                while (i14 >= 0) {
                    removeAndRecycleViewAt(i14, y1Var);
                    i14--;
                }
            }
        }
    }

    public final void D() {
        int heightMode = i() ? getHeightMode() : getWidthMode();
        this.f7794l.f7848b = heightMode == 0 || heightMode == Integer.MIN_VALUE;
    }

    public final void E(int i10) {
        if (this.f7781a != i10) {
            removeAllViews();
            this.f7781a = i10;
            this.Q = null;
            this.R = null;
            this.f7790h.clear();
            h hVar = this.f7795m;
            h.b(hVar);
            hVar.f7833d = 0;
            requestLayout();
        }
    }

    public final void F(int i10) {
        int i11 = this.f7783b;
        if (i11 != 1) {
            if (i11 == 0) {
                removeAllViews();
                this.f7790h.clear();
                h hVar = this.f7795m;
                h.b(hVar);
                hVar.f7833d = 0;
            }
            this.f7783b = 1;
            this.Q = null;
            this.R = null;
            requestLayout();
        }
    }

    public final boolean G(View view, int i10, int i11, i iVar) {
        return (!view.isLayoutRequested() && isMeasurementCacheEnabled() && l(view.getWidth(), i10, ((ViewGroup.MarginLayoutParams) iVar).width) && l(view.getHeight(), i11, ((ViewGroup.MarginLayoutParams) iVar).height)) ? false : true;
    }

    public final void H(int i10) {
        int paddingRight;
        View viewW = w(getChildCount() - 1, -1);
        if (i10 >= (viewW != null ? getPosition(viewW) : -1)) {
            return;
        }
        int childCount = getChildCount();
        f fVar = this.f7791i;
        fVar.i(childCount);
        fVar.j(childCount);
        fVar.h(childCount);
        if (i10 >= fVar.mIndexToFlexLine.length) {
            return;
        }
        this.f7782a0 = i10;
        View childAt = getChildAt(0);
        if (childAt == null) {
            return;
        }
        this.T = getPosition(childAt);
        if (i() || !this.f7788f) {
            this.U = this.Q.g(childAt) - this.Q.k();
            return;
        }
        int iD = this.Q.d(childAt);
        w0 w0Var = this.Q;
        int i11 = w0Var.f3942d;
        q1 q1Var = w0Var.f3953a;
        switch (i11) {
            case 0:
                paddingRight = q1Var.getPaddingRight();
                break;
            default:
                paddingRight = q1Var.getPaddingBottom();
                break;
        }
        this.U = paddingRight + iD;
    }

    public final void I(h hVar, boolean z10, boolean z11) {
        int i10;
        if (z11) {
            D();
        } else {
            this.f7794l.f7848b = false;
        }
        if (i() || !this.f7788f) {
            this.f7794l.f7847a = this.Q.i() - hVar.f7832c;
        } else {
            this.f7794l.f7847a = hVar.f7832c - getPaddingRight();
        }
        j jVar = this.f7794l;
        jVar.f7850d = hVar.f7830a;
        jVar.f7854h = 1;
        jVar.f7855i = 1;
        jVar.f7851e = hVar.f7832c;
        jVar.f7852f = Integer.MIN_VALUE;
        jVar.f7849c = hVar.f7831b;
        if (!z10 || this.f7790h.size() <= 1 || (i10 = hVar.f7831b) < 0 || i10 >= this.f7790h.size() - 1) {
            return;
        }
        c cVar = (c) this.f7790h.get(hVar.f7831b);
        j jVar2 = this.f7794l;
        jVar2.f7849c++;
        jVar2.f7850d += cVar.f7803h;
    }

    public final void J(h hVar, boolean z10, boolean z11) {
        if (z11) {
            D();
        } else {
            this.f7794l.f7848b = false;
        }
        if (i() || !this.f7788f) {
            this.f7794l.f7847a = hVar.f7832c - this.Q.k();
        } else {
            this.f7794l.f7847a = (this.Z.getWidth() - hVar.f7832c) - this.Q.k();
        }
        j jVar = this.f7794l;
        jVar.f7850d = hVar.f7830a;
        jVar.f7854h = 1;
        jVar.f7855i = -1;
        jVar.f7851e = hVar.f7832c;
        jVar.f7852f = Integer.MIN_VALUE;
        int i10 = hVar.f7831b;
        jVar.f7849c = i10;
        if (!z10 || i10 <= 0) {
            return;
        }
        int size = this.f7790h.size();
        int i11 = hVar.f7831b;
        if (size > i11) {
            c cVar = (c) this.f7790h.get(i11);
            j jVar2 = this.f7794l;
            jVar2.f7849c--;
            jVar2.f7850d -= cVar.f7803h;
        }
    }

    @Override // com.google.android.flexbox.a
    public final void a(View view, int i10, int i11, c cVar) {
        calculateItemDecorationsForChild(view, f7780c0);
        if (i()) {
            int rightDecorationWidth = getRightDecorationWidth(view) + getLeftDecorationWidth(view);
            cVar.f7800e += rightDecorationWidth;
            cVar.f7801f += rightDecorationWidth;
            return;
        }
        int bottomDecorationHeight = getBottomDecorationHeight(view) + getTopDecorationHeight(view);
        cVar.f7800e += bottomDecorationHeight;
        cVar.f7801f += bottomDecorationHeight;
    }

    @Override // com.google.android.flexbox.a
    public final void b(c cVar) {
    }

    @Override // com.google.android.flexbox.a
    public final View c(int i10) {
        return f(i10);
    }

    @Override // androidx.recyclerview.widget.q1
    public final boolean canScrollHorizontally() {
        if (this.f7783b == 0) {
            return i();
        }
        if (i()) {
            int width = getWidth();
            View view = this.Z;
            if (width <= (view != null ? view.getWidth() : 0)) {
                return false;
            }
        }
        return true;
    }

    @Override // androidx.recyclerview.widget.q1
    public final boolean canScrollVertically() {
        if (this.f7783b == 0) {
            return !i();
        }
        if (i()) {
            return true;
        }
        int height = getHeight();
        View view = this.Z;
        return height > (view != null ? view.getHeight() : 0);
    }

    @Override // androidx.recyclerview.widget.q1
    public final boolean checkLayoutParams(r1 r1Var) {
        return r1Var instanceof i;
    }

    @Override // androidx.recyclerview.widget.q1
    public final int computeHorizontalScrollExtent(f2 f2Var) {
        return n(f2Var);
    }

    @Override // androidx.recyclerview.widget.q1
    public final int computeHorizontalScrollOffset(f2 f2Var) {
        return o(f2Var);
    }

    @Override // androidx.recyclerview.widget.q1
    public final int computeHorizontalScrollRange(f2 f2Var) {
        return p(f2Var);
    }

    @Override // androidx.recyclerview.widget.d2
    public final PointF computeScrollVectorForPosition(int i10) {
        View childAt;
        if (getChildCount() == 0 || (childAt = getChildAt(0)) == null) {
            return null;
        }
        int i11 = i10 < getPosition(childAt) ? -1 : 1;
        return i() ? new PointF(0.0f, i11) : new PointF(i11, 0.0f);
    }

    @Override // androidx.recyclerview.widget.q1
    public final int computeVerticalScrollExtent(f2 f2Var) {
        return n(f2Var);
    }

    @Override // androidx.recyclerview.widget.q1
    public final int computeVerticalScrollOffset(f2 f2Var) {
        return o(f2Var);
    }

    @Override // androidx.recyclerview.widget.q1
    public final int computeVerticalScrollRange(f2 f2Var) {
        return p(f2Var);
    }

    @Override // com.google.android.flexbox.a
    public final int d(int i10, int i11, int i12) {
        return q1.getChildMeasureSpec(getWidth(), getWidthMode(), i11, i12, canScrollHorizontally());
    }

    @Override // com.google.android.flexbox.a
    public final void e(int i10, View view) {
        this.X.put(i10, view);
    }

    @Override // com.google.android.flexbox.a
    public final View f(int i10) {
        View view = (View) this.X.get(i10);
        return view != null ? view : this.f7792j.d(i10);
    }

    @Override // com.google.android.flexbox.a
    public final int g(View view, int i10, int i11) {
        int topDecorationHeight;
        int bottomDecorationHeight;
        if (i()) {
            topDecorationHeight = getLeftDecorationWidth(view);
            bottomDecorationHeight = getRightDecorationWidth(view);
        } else {
            topDecorationHeight = getTopDecorationHeight(view);
            bottomDecorationHeight = getBottomDecorationHeight(view);
        }
        return bottomDecorationHeight + topDecorationHeight;
    }

    @Override // androidx.recyclerview.widget.q1
    public final r1 generateDefaultLayoutParams() {
        i iVar = new i(-2, -2);
        iVar.f7838a = 0.0f;
        iVar.f7839b = 1.0f;
        iVar.f7840c = -1;
        iVar.f7841d = -1.0f;
        iVar.f7844g = 16777215;
        iVar.f7845h = 16777215;
        return iVar;
    }

    @Override // androidx.recyclerview.widget.q1
    public final r1 generateLayoutParams(Context context, AttributeSet attributeSet) {
        i iVar = new i(context, attributeSet);
        iVar.f7838a = 0.0f;
        iVar.f7839b = 1.0f;
        iVar.f7840c = -1;
        iVar.f7841d = -1.0f;
        iVar.f7844g = 16777215;
        iVar.f7845h = 16777215;
        return iVar;
    }

    @Override // com.google.android.flexbox.a
    public final int getAlignContent() {
        return 5;
    }

    @Override // com.google.android.flexbox.a
    public final int getAlignItems() {
        return this.f7786d;
    }

    @Override // com.google.android.flexbox.a
    public final int getFlexDirection() {
        return this.f7781a;
    }

    @Override // com.google.android.flexbox.a
    public final int getFlexItemCount() {
        return this.f7793k.b();
    }

    @Override // com.google.android.flexbox.a
    public final List getFlexLinesInternal() {
        return this.f7790h;
    }

    @Override // com.google.android.flexbox.a
    public final int getFlexWrap() {
        return this.f7783b;
    }

    @Override // com.google.android.flexbox.a
    public final int getLargestMainSize() {
        if (this.f7790h.size() == 0) {
            return 0;
        }
        int size = this.f7790h.size();
        int iMax = Integer.MIN_VALUE;
        for (int i10 = 0; i10 < size; i10++) {
            iMax = Math.max(iMax, ((c) this.f7790h.get(i10)).f7800e);
        }
        return iMax;
    }

    @Override // com.google.android.flexbox.a
    public final int getMaxLine() {
        return this.f7787e;
    }

    @Override // com.google.android.flexbox.a
    public final int getSumOfCrossSize() {
        int size = this.f7790h.size();
        int i10 = 0;
        for (int i11 = 0; i11 < size; i11++) {
            i10 += ((c) this.f7790h.get(i11)).f7802g;
        }
        return i10;
    }

    @Override // com.google.android.flexbox.a
    public final int h(int i10, int i11, int i12) {
        return q1.getChildMeasureSpec(getHeight(), getHeightMode(), i11, i12, canScrollVertically());
    }

    @Override // com.google.android.flexbox.a
    public final boolean i() {
        int i10 = this.f7781a;
        return i10 == 0 || i10 == 1;
    }

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

    @Override // com.google.android.flexbox.a
    public final int j(View view) {
        int leftDecorationWidth;
        int rightDecorationWidth;
        if (i()) {
            leftDecorationWidth = getTopDecorationHeight(view);
            rightDecorationWidth = getBottomDecorationHeight(view);
        } else {
            leftDecorationWidth = getLeftDecorationWidth(view);
            rightDecorationWidth = getRightDecorationWidth(view);
        }
        return rightDecorationWidth + leftDecorationWidth;
    }

    public final int n(f2 f2Var) {
        if (getChildCount() == 0) {
            return 0;
        }
        int iB = f2Var.b();
        q();
        View viewS = s(iB);
        View viewU = u(iB);
        if (f2Var.b() == 0 || viewS == null || viewU == null) {
            return 0;
        }
        return Math.min(this.Q.l(), this.Q.d(viewU) - this.Q.g(viewS));
    }

    public final int o(f2 f2Var) {
        if (getChildCount() == 0) {
            return 0;
        }
        int iB = f2Var.b();
        View viewS = s(iB);
        View viewU = u(iB);
        if (f2Var.b() != 0 && viewS != null && viewU != null) {
            int position = getPosition(viewS);
            int position2 = getPosition(viewU);
            int iAbs = Math.abs(this.Q.d(viewU) - this.Q.g(viewS));
            int i10 = this.f7791i.mIndexToFlexLine[position];
            if (i10 != 0 && i10 != -1) {
                return Math.round((i10 * (iAbs / ((r4[position2] - i10) + 1))) + (this.Q.k() - this.Q.g(viewS)));
            }
        }
        return 0;
    }

    @Override // androidx.recyclerview.widget.q1
    public final void onAdapterChanged(d1 d1Var, d1 d1Var2) {
        removeAllViews();
    }

    @Override // androidx.recyclerview.widget.q1
    public final void onAttachedToWindow(RecyclerView recyclerView) {
        super.onAttachedToWindow(recyclerView);
        this.Z = (View) recyclerView.getParent();
    }

    @Override // androidx.recyclerview.widget.q1
    public final void onDetachedFromWindow(RecyclerView recyclerView, y1 y1Var) {
        onDetachedFromWindow(recyclerView);
    }

    @Override // androidx.recyclerview.widget.q1
    public final void onItemsAdded(RecyclerView recyclerView, int i10, int i11) {
        super.onItemsAdded(recyclerView, i10, i11);
        H(i10);
    }

    @Override // androidx.recyclerview.widget.q1
    public final void onItemsMoved(RecyclerView recyclerView, int i10, int i11, int i12) {
        super.onItemsMoved(recyclerView, i10, i11, i12);
        H(Math.min(i10, i11));
    }

    @Override // androidx.recyclerview.widget.q1
    public final void onItemsRemoved(RecyclerView recyclerView, int i10, int i11) {
        super.onItemsRemoved(recyclerView, i10, i11);
        H(i10);
    }

    @Override // androidx.recyclerview.widget.q1
    public final void onItemsUpdated(RecyclerView recyclerView, int i10, int i11, Object obj) {
        super.onItemsUpdated(recyclerView, i10, i11, obj);
        H(i10);
    }

    /* JADX WARN: Removed duplicated region for block: B:115:0x01b8  */
    /* JADX WARN: Removed duplicated region for block: B:147:0x0240  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x00ed  */
    @Override // androidx.recyclerview.widget.q1
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void onLayoutChildren(y1 y1Var, f2 f2Var) {
        int i10;
        int paddingRight;
        View childAt;
        boolean z10;
        int i11;
        int i12;
        int i13;
        d dVar;
        int i14;
        this.f7792j = y1Var;
        this.f7793k = f2Var;
        int iB = f2Var.b();
        if (iB == 0 && f2Var.f3706g) {
            return;
        }
        int layoutDirection = getLayoutDirection();
        int i15 = this.f7781a;
        if (i15 == 0) {
            this.f7788f = layoutDirection == 1;
            this.f7789g = this.f7783b == 2;
        } else if (i15 == 1) {
            this.f7788f = layoutDirection != 1;
            this.f7789g = this.f7783b == 2;
        } else if (i15 == 2) {
            boolean z11 = layoutDirection == 1;
            this.f7788f = z11;
            if (this.f7783b == 2) {
                this.f7788f = !z11;
            }
            this.f7789g = false;
        } else if (i15 != 3) {
            this.f7788f = false;
            this.f7789g = false;
        } else {
            boolean z12 = layoutDirection == 1;
            this.f7788f = z12;
            if (this.f7783b == 2) {
                this.f7788f = !z12;
            }
            this.f7789g = true;
        }
        q();
        if (this.f7794l == null) {
            j jVar = new j();
            jVar.f7854h = 1;
            jVar.f7855i = 1;
            this.f7794l = jVar;
        }
        f fVar = this.f7791i;
        fVar.i(iB);
        fVar.j(iB);
        fVar.h(iB);
        this.f7794l.f7856j = false;
        k kVar = this.S;
        if (kVar != null && (i14 = kVar.f7857a) >= 0 && i14 < iB) {
            this.T = i14;
        }
        h hVar = this.f7795m;
        if (!hVar.f7835f || this.T != -1 || kVar != null) {
            h.b(hVar);
            k kVar2 = this.S;
            if (f2Var.f3706g || (i10 = this.T) == -1) {
                if (getChildCount() != 0) {
                    View viewU = hVar.f7834e ? u(f2Var.b()) : s(f2Var.b());
                    if (viewU != null) {
                        FlexboxLayoutManager flexboxLayoutManager = hVar.f7837h;
                        w0 w0Var = flexboxLayoutManager.f7783b == 0 ? flexboxLayoutManager.R : flexboxLayoutManager.Q;
                        if (flexboxLayoutManager.i() || !flexboxLayoutManager.f7788f) {
                            if (hVar.f7834e) {
                                hVar.f7832c = w0Var.m() + w0Var.d(viewU);
                            } else {
                                hVar.f7832c = w0Var.g(viewU);
                            }
                        } else if (hVar.f7834e) {
                            hVar.f7832c = w0Var.m() + w0Var.g(viewU);
                        } else {
                            hVar.f7832c = w0Var.d(viewU);
                        }
                        int position = flexboxLayoutManager.getPosition(viewU);
                        hVar.f7830a = position;
                        hVar.f7836g = false;
                        int[] iArr = flexboxLayoutManager.f7791i.mIndexToFlexLine;
                        if (position == -1) {
                            position = 0;
                        }
                        int i16 = iArr[position];
                        if (i16 == -1) {
                            i16 = 0;
                        }
                        hVar.f7831b = i16;
                        int size = flexboxLayoutManager.f7790h.size();
                        int i17 = hVar.f7831b;
                        if (size > i17) {
                            hVar.f7830a = ((c) flexboxLayoutManager.f7790h.get(i17)).f7810o;
                        }
                    } else {
                        h.a(hVar);
                        hVar.f7830a = 0;
                        hVar.f7831b = 0;
                    }
                    hVar.f7835f = true;
                }
            } else if (i10 < 0 || i10 >= f2Var.b()) {
                this.T = -1;
                this.U = Integer.MIN_VALUE;
                if (getChildCount() != 0) {
                }
            } else {
                int i18 = this.T;
                hVar.f7830a = i18;
                hVar.f7831b = fVar.mIndexToFlexLine[i18];
                k kVar3 = this.S;
                if (kVar3 != null) {
                    int iB2 = f2Var.b();
                    int i19 = kVar3.f7857a;
                    if (i19 >= 0 && i19 < iB2) {
                        hVar.f7832c = this.Q.k() + kVar2.f7858b;
                        hVar.f7836g = true;
                        hVar.f7831b = -1;
                    } else if (this.U == Integer.MIN_VALUE) {
                        View viewFindViewByPosition = findViewByPosition(this.T);
                        if (viewFindViewByPosition == null) {
                            if (getChildCount() > 0 && (childAt = getChildAt(0)) != null) {
                                hVar.f7834e = this.T < getPosition(childAt);
                            }
                            h.a(hVar);
                        } else if (this.Q.e(viewFindViewByPosition) > this.Q.l()) {
                            h.a(hVar);
                        } else if (this.Q.g(viewFindViewByPosition) - this.Q.k() < 0) {
                            hVar.f7832c = this.Q.k();
                            hVar.f7834e = false;
                        } else if (this.Q.i() - this.Q.d(viewFindViewByPosition) < 0) {
                            hVar.f7832c = this.Q.i();
                            hVar.f7834e = true;
                        } else {
                            hVar.f7832c = hVar.f7834e ? this.Q.m() + this.Q.d(viewFindViewByPosition) : this.Q.g(viewFindViewByPosition);
                        }
                    } else if (i() || !this.f7788f) {
                        hVar.f7832c = this.Q.k() + this.U;
                    } else {
                        int i20 = this.U;
                        w0 w0Var2 = this.Q;
                        int i21 = w0Var2.f3942d;
                        q1 q1Var = w0Var2.f3953a;
                        switch (i21) {
                            case 0:
                                paddingRight = q1Var.getPaddingRight();
                                break;
                            default:
                                paddingRight = q1Var.getPaddingBottom();
                                break;
                        }
                        hVar.f7832c = i20 - paddingRight;
                    }
                    hVar.f7835f = true;
                }
            }
        }
        detachAndScrapAttachedViews(y1Var);
        if (hVar.f7834e) {
            J(hVar, false, true);
        } else {
            I(hVar, false, true);
        }
        int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(getWidth(), getWidthMode());
        int iMakeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(getHeight(), getHeightMode());
        int width = getWidth();
        int height = getHeight();
        boolean zI = i();
        Context context = this.Y;
        if (zI) {
            int i22 = this.V;
            z10 = (i22 == Integer.MIN_VALUE || i22 == width) ? false : true;
            j jVar2 = this.f7794l;
            i11 = jVar2.f7848b ? context.getResources().getDisplayMetrics().heightPixels : jVar2.f7847a;
        } else {
            int i23 = this.W;
            z10 = (i23 == Integer.MIN_VALUE || i23 == height) ? false : true;
            j jVar3 = this.f7794l;
            i11 = jVar3.f7848b ? context.getResources().getDisplayMetrics().widthPixels : jVar3.f7847a;
        }
        int i24 = i11;
        this.V = width;
        this.W = height;
        int i25 = this.f7782a0;
        d dVar2 = this.f7784b0;
        if (i25 != -1 || (this.T == -1 && !z10)) {
            int iMin = i25 != -1 ? Math.min(i25, hVar.f7830a) : hVar.f7830a;
            dVar2.f7814a = null;
            dVar2.f7815b = 0;
            if (i()) {
                if (this.f7790h.size() > 0) {
                    fVar.c(iMin, this.f7790h);
                    this.f7791i.calculateFlexLines(this.f7784b0, iMakeMeasureSpec, iMakeMeasureSpec2, i24, iMin, hVar.f7830a, this.f7790h);
                } else {
                    fVar.h(iB);
                    this.f7791i.calculateHorizontalFlexLines(this.f7784b0, iMakeMeasureSpec, iMakeMeasureSpec2, i24, 0, this.f7790h);
                }
            } else if (this.f7790h.size() > 0) {
                fVar.c(iMin, this.f7790h);
                this.f7791i.calculateFlexLines(this.f7784b0, iMakeMeasureSpec2, iMakeMeasureSpec, i24, iMin, hVar.f7830a, this.f7790h);
            } else {
                fVar.h(iB);
                this.f7791i.calculateVerticalFlexLines(this.f7784b0, iMakeMeasureSpec, iMakeMeasureSpec2, i24, 0, this.f7790h);
            }
            this.f7790h = dVar2.f7814a;
            fVar.g(iMakeMeasureSpec, iMakeMeasureSpec2, iMin);
            fVar.t(iMin);
        } else if (!hVar.f7834e) {
            this.f7790h.clear();
            dVar2.f7814a = null;
            dVar2.f7815b = 0;
            if (i()) {
                dVar = dVar2;
                this.f7791i.calculateFlexLines(this.f7784b0, iMakeMeasureSpec, iMakeMeasureSpec2, i24, 0, hVar.f7830a, this.f7790h);
            } else {
                dVar = dVar2;
                this.f7791i.calculateFlexLines(this.f7784b0, iMakeMeasureSpec2, iMakeMeasureSpec, i24, 0, hVar.f7830a, this.f7790h);
            }
            this.f7790h = dVar.f7814a;
            fVar.g(iMakeMeasureSpec, iMakeMeasureSpec2, 0);
            fVar.t(0);
            int i26 = fVar.mIndexToFlexLine[hVar.f7830a];
            hVar.f7831b = i26;
            this.f7794l.f7849c = i26;
        }
        r(y1Var, f2Var, this.f7794l);
        if (hVar.f7834e) {
            i13 = this.f7794l.f7851e;
            I(hVar, true, false);
            r(y1Var, f2Var, this.f7794l);
            i12 = this.f7794l.f7851e;
        } else {
            i12 = this.f7794l.f7851e;
            J(hVar, true, false);
            r(y1Var, f2Var, this.f7794l);
            i13 = this.f7794l.f7851e;
        }
        if (getChildCount() > 0) {
            if (hVar.f7834e) {
                z(y(i12, y1Var, f2Var, true) + i13, y1Var, f2Var, false);
            } else {
                y(z(i13, y1Var, f2Var, true) + i12, y1Var, f2Var, false);
            }
        }
    }

    @Override // androidx.recyclerview.widget.q1
    public final void onLayoutCompleted(f2 f2Var) {
        super.onLayoutCompleted(f2Var);
        this.S = null;
        this.T = -1;
        this.U = Integer.MIN_VALUE;
        this.f7782a0 = -1;
        h.b(this.f7795m);
        this.X.clear();
    }

    @Override // androidx.recyclerview.widget.q1
    public final void onRestoreInstanceState(Parcelable parcelable) {
        if (parcelable instanceof k) {
            this.S = (k) parcelable;
            requestLayout();
        }
    }

    @Override // androidx.recyclerview.widget.q1
    public final Parcelable onSaveInstanceState() {
        k kVar = this.S;
        if (kVar != null) {
            k kVar2 = new k();
            kVar2.f7857a = kVar.f7857a;
            kVar2.f7858b = kVar.f7858b;
            return kVar2;
        }
        k kVar3 = new k();
        if (getChildCount() > 0) {
            View childAt = getChildAt(0);
            kVar3.f7857a = getPosition(childAt);
            kVar3.f7858b = this.Q.g(childAt) - this.Q.k();
        } else {
            kVar3.f7857a = -1;
        }
        return kVar3;
    }

    public final int p(f2 f2Var) {
        if (getChildCount() == 0) {
            return 0;
        }
        int iB = f2Var.b();
        View viewS = s(iB);
        View viewU = u(iB);
        if (f2Var.b() == 0 || viewS == null || viewU == null) {
            return 0;
        }
        View viewW = w(0, getChildCount());
        int position = viewW == null ? -1 : getPosition(viewW);
        return (int) ((Math.abs(this.Q.d(viewU) - this.Q.g(viewS)) / (((w(getChildCount() - 1, -1) != null ? getPosition(r4) : -1) - position) + 1)) * f2Var.b());
    }

    public final void q() {
        if (this.Q != null) {
            return;
        }
        if (i()) {
            if (this.f7783b == 0) {
                this.Q = x0.a(this);
                this.R = x0.c(this);
                return;
            } else {
                this.Q = x0.c(this);
                this.R = x0.a(this);
                return;
            }
        }
        if (this.f7783b == 0) {
            this.Q = x0.c(this);
            this.R = x0.a(this);
        } else {
            this.Q = x0.a(this);
            this.R = x0.c(this);
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:13:0x0027, code lost:
    
        r27 = r3;
        r31 = r8;
     */
    /* JADX WARN: Code restructure failed: missing block: B:151:0x0477, code lost:
    
        r1 = r37.f7847a - r31;
        r37.f7847a = r1;
        r3 = r37.f7852f;
     */
    /* JADX WARN: Code restructure failed: missing block: B:152:0x0481, code lost:
    
        if (r3 == Integer.MIN_VALUE) goto L157;
     */
    /* JADX WARN: Code restructure failed: missing block: B:153:0x0483, code lost:
    
        r3 = r3 + r31;
        r37.f7852f = r3;
     */
    /* JADX WARN: Code restructure failed: missing block: B:154:0x0487, code lost:
    
        if (r1 >= 0) goto L156;
     */
    /* JADX WARN: Code restructure failed: missing block: B:155:0x0489, code lost:
    
        r37.f7852f = r3 + r1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:156:0x048c, code lost:
    
        C(r35, r37);
     */
    /* JADX WARN: Code restructure failed: missing block: B:158:0x0495, code lost:
    
        return r27 - r37.f7847a;
     */
    /* JADX WARN: Removed duplicated region for block: B:120:0x02f3  */
    /* JADX WARN: Removed duplicated region for block: B:64:0x011d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int r(y1 y1Var, f2 f2Var, j jVar) {
        int i10;
        int i11;
        boolean z10;
        int i12;
        int i13;
        int i14;
        int i15;
        float f10;
        float f11;
        float f12;
        int i16;
        int i17;
        int i18;
        c cVar;
        boolean z11;
        View view;
        int i19;
        int i20;
        float f13;
        int i21;
        float f14;
        float f15;
        int i22;
        int i23;
        int i24;
        int i25;
        boolean z12;
        int i26;
        int i27;
        i iVar;
        int i28;
        Rect rect;
        int i29;
        f fVar;
        int i30 = jVar.f7852f;
        if (i30 != Integer.MIN_VALUE) {
            int i31 = jVar.f7847a;
            if (i31 < 0) {
                jVar.f7852f = i30 + i31;
            }
            C(y1Var, jVar);
        }
        int i32 = jVar.f7847a;
        boolean zI = i();
        int i33 = i32;
        int i34 = 0;
        while (true) {
            if (i33 <= 0 && !this.f7794l.f7848b) {
                break;
            }
            List list = this.f7790h;
            int i35 = jVar.f7850d;
            if (i35 < 0 || i35 >= f2Var.b() || (i10 = jVar.f7849c) < 0 || i10 >= list.size()) {
                break;
            }
            c cVar2 = (c) this.f7790h.get(jVar.f7849c);
            jVar.f7850d = cVar2.f7810o;
            boolean zI2 = i();
            h hVar = this.f7795m;
            f fVar2 = this.f7791i;
            Rect rect2 = f7780c0;
            if (zI2) {
                int paddingLeft = getPaddingLeft();
                int paddingRight = getPaddingRight();
                int width = getWidth();
                int i36 = jVar.f7851e;
                if (jVar.f7855i == -1) {
                    i36 -= cVar2.f7802g;
                }
                int i37 = jVar.f7850d;
                int i38 = this.f7785c;
                if (i38 != 0) {
                    i11 = i32;
                    if (i38 == 1) {
                        int i39 = cVar2.f7800e;
                        f13 = (width - i39) + paddingRight;
                        i21 = i39 - paddingLeft;
                    } else if (i38 != 2) {
                        if (i38 == 3) {
                            f13 = paddingLeft;
                            f15 = (width - cVar2.f7800e) / (cVar2.f7803h != 1 ? r3 - 1 : 1.0f);
                            f14 = width - paddingRight;
                        } else if (i38 == 4) {
                            int i40 = cVar2.f7803h;
                            f15 = i40 != 0 ? (width - cVar2.f7800e) / i40 : 0.0f;
                            float f16 = paddingLeft;
                            float f17 = f15 / 2.0f;
                            f13 = f16 + f17;
                            f14 = (width - paddingRight) - f17;
                        } else {
                            if (i38 != 5) {
                                throw new IllegalStateException("Invalid justifyContent is set: " + this.f7785c);
                            }
                            f15 = cVar2.f7803h != 0 ? (width - cVar2.f7800e) / (r3 + 1) : 0.0f;
                            f13 = paddingLeft + f15;
                            f14 = (width - paddingRight) - f15;
                        }
                        float f18 = hVar.f7833d;
                        float rightDecorationWidth = f13 - f18;
                        float leftDecorationWidth = f14 - f18;
                        float fMax = Math.max(f15, 0.0f);
                        i22 = cVar2.f7803h;
                        i12 = i33;
                        i23 = i37;
                        int i41 = 0;
                        while (i23 < i37 + i22) {
                            View viewF = f(i23);
                            if (viewF == null) {
                                i25 = i41;
                                i29 = i36;
                                z12 = zI;
                                i26 = i34;
                                i27 = i23;
                                i28 = i22;
                                rect = rect2;
                                fVar = fVar2;
                                i24 = i37;
                            } else {
                                int i42 = i22;
                                i24 = i37;
                                if (jVar.f7855i == 1) {
                                    calculateItemDecorationsForChild(viewF, rect2);
                                    addView(viewF);
                                } else {
                                    calculateItemDecorationsForChild(viewF, rect2);
                                    addView(viewF, i41);
                                    i41++;
                                }
                                Rect rect3 = rect2;
                                f fVar3 = fVar2;
                                long j10 = fVar2.mMeasureSpecCache[i23];
                                int i43 = (int) j10;
                                int i44 = (int) (j10 >> 32);
                                i iVar2 = (i) viewF.getLayoutParams();
                                if (G(viewF, i43, i44, iVar2)) {
                                    viewF.measure(i43, i44);
                                }
                                float leftDecorationWidth2 = rightDecorationWidth + getLeftDecorationWidth(viewF) + ((ViewGroup.MarginLayoutParams) iVar2).leftMargin;
                                float rightDecorationWidth2 = leftDecorationWidth - (getRightDecorationWidth(viewF) + ((ViewGroup.MarginLayoutParams) iVar2).rightMargin);
                                int topDecorationHeight = getTopDecorationHeight(viewF) + i36;
                                if (this.f7788f) {
                                    i27 = i23;
                                    i28 = i42;
                                    i25 = i41;
                                    rect = rect3;
                                    i29 = i36;
                                    z12 = zI;
                                    iVar = iVar2;
                                    fVar = fVar3;
                                    i26 = i34;
                                    this.f7791i.n(viewF, cVar2, Math.round(rightDecorationWidth2) - viewF.getMeasuredWidth(), topDecorationHeight, Math.round(rightDecorationWidth2), viewF.getMeasuredHeight() + topDecorationHeight);
                                } else {
                                    i25 = i41;
                                    z12 = zI;
                                    i26 = i34;
                                    i27 = i23;
                                    iVar = iVar2;
                                    i28 = i42;
                                    rect = rect3;
                                    i29 = i36;
                                    fVar = fVar3;
                                    this.f7791i.n(viewF, cVar2, Math.round(leftDecorationWidth2), topDecorationHeight, viewF.getMeasuredWidth() + Math.round(leftDecorationWidth2), viewF.getMeasuredHeight() + topDecorationHeight);
                                }
                                rightDecorationWidth = getRightDecorationWidth(viewF) + viewF.getMeasuredWidth() + ((ViewGroup.MarginLayoutParams) iVar).rightMargin + fMax + leftDecorationWidth2;
                                leftDecorationWidth = rightDecorationWidth2 - ((getLeftDecorationWidth(viewF) + (viewF.getMeasuredWidth() + ((ViewGroup.MarginLayoutParams) iVar).leftMargin)) + fMax);
                            }
                            i23 = i27 + 1;
                            rect2 = rect;
                            fVar2 = fVar;
                            i37 = i24;
                            i36 = i29;
                            i22 = i28;
                            i41 = i25;
                            zI = z12;
                            i34 = i26;
                        }
                        z10 = zI;
                        i13 = i34;
                        jVar.f7849c += this.f7794l.f7855i;
                        i18 = cVar2.f7802g;
                    } else {
                        float f19 = (width - cVar2.f7800e) / 2.0f;
                        float f20 = paddingLeft + f19;
                        f14 = (width - paddingRight) - f19;
                        f13 = f20;
                        f15 = 0.0f;
                        float f182 = hVar.f7833d;
                        float rightDecorationWidth3 = f13 - f182;
                        float leftDecorationWidth3 = f14 - f182;
                        float fMax2 = Math.max(f15, 0.0f);
                        i22 = cVar2.f7803h;
                        i12 = i33;
                        i23 = i37;
                        int i412 = 0;
                        while (i23 < i37 + i22) {
                        }
                        z10 = zI;
                        i13 = i34;
                        jVar.f7849c += this.f7794l.f7855i;
                        i18 = cVar2.f7802g;
                    }
                } else {
                    i11 = i32;
                    f13 = paddingLeft;
                    i21 = width - paddingRight;
                }
                f14 = i21;
                f15 = 0.0f;
                float f1822 = hVar.f7833d;
                float rightDecorationWidth32 = f13 - f1822;
                float leftDecorationWidth32 = f14 - f1822;
                float fMax22 = Math.max(f15, 0.0f);
                i22 = cVar2.f7803h;
                i12 = i33;
                i23 = i37;
                int i4122 = 0;
                while (i23 < i37 + i22) {
                }
                z10 = zI;
                i13 = i34;
                jVar.f7849c += this.f7794l.f7855i;
                i18 = cVar2.f7802g;
            } else {
                i11 = i32;
                z10 = zI;
                i12 = i33;
                i13 = i34;
                boolean z13 = true;
                int paddingTop = getPaddingTop();
                int paddingBottom = getPaddingBottom();
                int height = getHeight();
                int i45 = jVar.f7851e;
                if (jVar.f7855i == -1) {
                    int i46 = cVar2.f7802g;
                    i15 = i45 + i46;
                    i14 = i45 - i46;
                } else {
                    i14 = i45;
                    i15 = i14;
                }
                int i47 = jVar.f7850d;
                int i48 = this.f7785c;
                if (i48 != 0) {
                    if (i48 == 1) {
                        int i49 = cVar2.f7800e;
                        float f21 = (height - i49) + paddingBottom;
                        float f22 = i49 - paddingTop;
                        f12 = 0.0f;
                        f11 = f22;
                        f10 = f21;
                    } else if (i48 == 2) {
                        float f23 = (height - cVar2.f7800e) / 2.0f;
                        f10 = paddingTop + f23;
                        f11 = (height - paddingBottom) - f23;
                    } else if (i48 == 3) {
                        f10 = paddingTop;
                        f12 = (height - cVar2.f7800e) / (cVar2.f7803h != 1 ? r6 - 1 : 1.0f);
                        f11 = height - paddingBottom;
                    } else if (i48 == 4) {
                        int i50 = cVar2.f7803h;
                        f12 = i50 != 0 ? (height - cVar2.f7800e) / i50 : 0.0f;
                        float f24 = f12 / 2.0f;
                        f10 = paddingTop + f24;
                        f11 = (height - paddingBottom) - f24;
                    } else {
                        if (i48 != 5) {
                            throw new IllegalStateException("Invalid justifyContent is set: " + this.f7785c);
                        }
                        f12 = cVar2.f7803h != 0 ? (height - cVar2.f7800e) / (r6 + 1) : 0.0f;
                        f10 = paddingTop + f12;
                        f11 = (height - paddingBottom) - f12;
                    }
                    float f25 = hVar.f7833d;
                    float bottomDecorationHeight = f10 - f25;
                    float topDecorationHeight2 = f11 - f25;
                    float fMax3 = Math.max(f12, 0.0f);
                    i16 = cVar2.f7803h;
                    i17 = i47;
                    int i51 = 0;
                    while (i17 < i47 + i16) {
                        View viewF2 = f(i17);
                        if (viewF2 == null) {
                            z11 = z13;
                            cVar = cVar2;
                            i19 = i17;
                            i20 = i47;
                        } else {
                            cVar = cVar2;
                            long j11 = fVar2.mMeasureSpecCache[i17];
                            int i52 = (int) j11;
                            int i53 = (int) (j11 >> 32);
                            if (G(viewF2, i52, i53, (i) viewF2.getLayoutParams())) {
                                viewF2.measure(i52, i53);
                            }
                            float topDecorationHeight3 = bottomDecorationHeight + getTopDecorationHeight(viewF2) + ((ViewGroup.MarginLayoutParams) r9).topMargin;
                            float bottomDecorationHeight2 = topDecorationHeight2 - (getBottomDecorationHeight(viewF2) + ((ViewGroup.MarginLayoutParams) r9).rightMargin);
                            if (jVar.f7855i == 1) {
                                calculateItemDecorationsForChild(viewF2, rect2);
                                addView(viewF2);
                            } else {
                                calculateItemDecorationsForChild(viewF2, rect2);
                                addView(viewF2, i51);
                                i51++;
                            }
                            int i54 = i51;
                            int leftDecorationWidth4 = getLeftDecorationWidth(viewF2) + i14;
                            int rightDecorationWidth4 = i15 - getRightDecorationWidth(viewF2);
                            boolean z14 = this.f7788f;
                            if (!z14) {
                                z11 = true;
                                view = viewF2;
                                i19 = i17;
                                i20 = i47;
                                if (this.f7789g) {
                                    this.f7791i.o(view, cVar, z14, leftDecorationWidth4, Math.round(bottomDecorationHeight2) - view.getMeasuredHeight(), view.getMeasuredWidth() + leftDecorationWidth4, Math.round(bottomDecorationHeight2));
                                } else {
                                    this.f7791i.o(view, cVar, z14, leftDecorationWidth4, Math.round(topDecorationHeight3), view.getMeasuredWidth() + leftDecorationWidth4, view.getMeasuredHeight() + Math.round(topDecorationHeight3));
                                }
                            } else if (this.f7789g) {
                                z11 = true;
                                view = viewF2;
                                i19 = i17;
                                i20 = i47;
                                this.f7791i.o(viewF2, cVar, z14, rightDecorationWidth4 - viewF2.getMeasuredWidth(), Math.round(bottomDecorationHeight2) - viewF2.getMeasuredHeight(), rightDecorationWidth4, Math.round(bottomDecorationHeight2));
                            } else {
                                z11 = true;
                                view = viewF2;
                                i19 = i17;
                                i20 = i47;
                                this.f7791i.o(view, cVar, z14, rightDecorationWidth4 - view.getMeasuredWidth(), Math.round(topDecorationHeight3), rightDecorationWidth4, view.getMeasuredHeight() + Math.round(topDecorationHeight3));
                            }
                            View view2 = view;
                            topDecorationHeight2 = bottomDecorationHeight2 - ((getTopDecorationHeight(view2) + (view2.getMeasuredHeight() + ((ViewGroup.MarginLayoutParams) r9).bottomMargin)) + fMax3);
                            bottomDecorationHeight = getBottomDecorationHeight(view2) + view.getMeasuredHeight() + ((ViewGroup.MarginLayoutParams) r9).topMargin + fMax3 + topDecorationHeight3;
                            i51 = i54;
                        }
                        i17 = i19 + 1;
                        cVar2 = cVar;
                        z13 = z11;
                        i47 = i20;
                    }
                    jVar.f7849c += this.f7794l.f7855i;
                    cVar2 = cVar2;
                    i18 = cVar2.f7802g;
                } else {
                    f10 = paddingTop;
                    f11 = height - paddingBottom;
                }
                f12 = 0.0f;
                float f252 = hVar.f7833d;
                float bottomDecorationHeight3 = f10 - f252;
                float topDecorationHeight22 = f11 - f252;
                float fMax32 = Math.max(f12, 0.0f);
                i16 = cVar2.f7803h;
                i17 = i47;
                int i512 = 0;
                while (i17 < i47 + i16) {
                }
                jVar.f7849c += this.f7794l.f7855i;
                cVar2 = cVar2;
                i18 = cVar2.f7802g;
            }
            i34 = i13 + i18;
            if (z10 || !this.f7788f) {
                jVar.f7851e += cVar2.f7802g * jVar.f7855i;
            } else {
                jVar.f7851e -= cVar2.f7802g * jVar.f7855i;
            }
            i33 = i12 - cVar2.f7802g;
            i32 = i11;
            zI = z10;
        }
    }

    public final View s(int i10) {
        View viewX = x(0, getChildCount(), i10);
        if (viewX == null) {
            return null;
        }
        int i11 = this.f7791i.mIndexToFlexLine[getPosition(viewX)];
        if (i11 == -1) {
            return null;
        }
        return t(viewX, (c) this.f7790h.get(i11));
    }

    @Override // androidx.recyclerview.widget.q1
    public final int scrollHorizontallyBy(int i10, y1 y1Var, f2 f2Var) {
        if (!i() || this.f7783b == 0) {
            int iA = A(i10, y1Var, f2Var);
            this.X.clear();
            return iA;
        }
        int iB = B(i10);
        this.f7795m.f7833d += iB;
        this.R.p(-iB);
        return iB;
    }

    @Override // androidx.recyclerview.widget.q1
    public final void scrollToPosition(int i10) {
        this.T = i10;
        this.U = Integer.MIN_VALUE;
        k kVar = this.S;
        if (kVar != null) {
            kVar.f7857a = -1;
        }
        requestLayout();
    }

    @Override // androidx.recyclerview.widget.q1
    public final int scrollVerticallyBy(int i10, y1 y1Var, f2 f2Var) {
        if (i() || (this.f7783b == 0 && !i())) {
            int iA = A(i10, y1Var, f2Var);
            this.X.clear();
            return iA;
        }
        int iB = B(i10);
        this.f7795m.f7833d += iB;
        this.R.p(-iB);
        return iB;
    }

    @Override // com.google.android.flexbox.a
    public final void setFlexLines(List list) {
        this.f7790h = list;
    }

    @Override // androidx.recyclerview.widget.q1
    public final void smoothScrollToPosition(RecyclerView recyclerView, f2 f2Var, int i10) {
        t0 t0Var = new t0(recyclerView.getContext());
        t0Var.setTargetPosition(i10);
        startSmoothScroll(t0Var);
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x003b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final View t(View view, c cVar) {
        boolean zI = i();
        int i10 = cVar.f7803h;
        for (int i11 = 1; i11 < i10; i11++) {
            View childAt = getChildAt(i11);
            if (childAt != null && childAt.getVisibility() != 8) {
                if (!this.f7788f || zI) {
                    if (this.Q.g(view) > this.Q.g(childAt)) {
                        view = childAt;
                    }
                } else if (this.Q.d(view) < this.Q.d(childAt)) {
                }
            }
        }
        return view;
    }

    public final View u(int i10) {
        View viewX = x(getChildCount() - 1, -1, i10);
        if (viewX == null) {
            return null;
        }
        return v(viewX, (c) this.f7790h.get(this.f7791i.mIndexToFlexLine[getPosition(viewX)]));
    }

    /* JADX WARN: Removed duplicated region for block: B:17:0x0047  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final View v(View view, c cVar) {
        boolean zI = i();
        int childCount = (getChildCount() - cVar.f7803h) - 1;
        for (int childCount2 = getChildCount() - 2; childCount2 > childCount; childCount2--) {
            View childAt = getChildAt(childCount2);
            if (childAt != null && childAt.getVisibility() != 8) {
                if (!this.f7788f || zI) {
                    if (this.Q.d(view) < this.Q.d(childAt)) {
                        view = childAt;
                    }
                } else if (this.Q.g(view) > this.Q.g(childAt)) {
                }
            }
        }
        return view;
    }

    public final View w(int i10, int i11) {
        int i12 = i11 > i10 ? 1 : -1;
        while (i10 != i11) {
            View childAt = getChildAt(i10);
            int paddingLeft = getPaddingLeft();
            int paddingTop = getPaddingTop();
            int width = getWidth() - getPaddingRight();
            int height = getHeight() - getPaddingBottom();
            int decoratedLeft = getDecoratedLeft(childAt) - ((ViewGroup.MarginLayoutParams) ((r1) childAt.getLayoutParams())).leftMargin;
            int decoratedTop = getDecoratedTop(childAt) - ((ViewGroup.MarginLayoutParams) ((r1) childAt.getLayoutParams())).topMargin;
            int decoratedRight = getDecoratedRight(childAt) + ((ViewGroup.MarginLayoutParams) ((r1) childAt.getLayoutParams())).rightMargin;
            int decoratedBottom = getDecoratedBottom(childAt) + ((ViewGroup.MarginLayoutParams) ((r1) childAt.getLayoutParams())).bottomMargin;
            boolean z10 = decoratedLeft >= width || decoratedRight >= paddingLeft;
            boolean z11 = decoratedTop >= height || decoratedBottom >= paddingTop;
            if (z10 && z11) {
                return childAt;
            }
            i10 += i12;
        }
        return null;
    }

    public final View x(int i10, int i11, int i12) {
        int position;
        q();
        if (this.f7794l == null) {
            j jVar = new j();
            jVar.f7854h = 1;
            jVar.f7855i = 1;
            this.f7794l = jVar;
        }
        int iK = this.Q.k();
        int i13 = this.Q.i();
        int i14 = i11 <= i10 ? -1 : 1;
        View view = null;
        View view2 = null;
        while (i10 != i11) {
            View childAt = getChildAt(i10);
            if (childAt != null && (position = getPosition(childAt)) >= 0 && position < i12) {
                if (((r1) childAt.getLayoutParams()).isItemRemoved()) {
                    if (view2 == null) {
                        view2 = childAt;
                    }
                } else {
                    if (this.Q.g(childAt) >= iK && this.Q.d(childAt) <= i13) {
                        return childAt;
                    }
                    if (view == null) {
                        view = childAt;
                    }
                }
            }
            i10 += i14;
        }
        return view != null ? view : view2;
    }

    public final int y(int i10, y1 y1Var, f2 f2Var, boolean z10) {
        int iA;
        int i11;
        if (i() || !this.f7788f) {
            int i12 = this.Q.i() - i10;
            if (i12 <= 0) {
                return 0;
            }
            iA = -A(-i12, y1Var, f2Var);
        } else {
            int iK = i10 - this.Q.k();
            if (iK <= 0) {
                return 0;
            }
            iA = A(iK, y1Var, f2Var);
        }
        int i13 = i10 + iA;
        if (!z10 || (i11 = this.Q.i() - i13) <= 0) {
            return iA;
        }
        this.Q.p(i11);
        return i11 + iA;
    }

    public final int z(int i10, y1 y1Var, f2 f2Var, boolean z10) {
        int iA;
        int iK;
        if (i() || !this.f7788f) {
            int iK2 = i10 - this.Q.k();
            if (iK2 <= 0) {
                return 0;
            }
            iA = -A(iK2, y1Var, f2Var);
        } else {
            int i11 = this.Q.i() - i10;
            if (i11 <= 0) {
                return 0;
            }
            iA = A(-i11, y1Var, f2Var);
        }
        int i12 = i10 + iA;
        if (!z10 || (iK = i12 - this.Q.k()) <= 0) {
            return iA;
        }
        this.Q.p(-iK);
        return iA - iK;
    }

    @Override // androidx.recyclerview.widget.q1
    public final void onItemsUpdated(RecyclerView recyclerView, int i10, int i11) {
        super.onItemsUpdated(recyclerView, i10, i11);
        H(i10);
    }

    public FlexboxLayoutManager(Context context, AttributeSet attributeSet, int i10, int i11) {
        p1 properties = q1.getProperties(context, attributeSet, i10, i11);
        int i12 = properties.f3851a;
        if (i12 != 0) {
            if (i12 == 1) {
                if (properties.f3853c) {
                    E(3);
                } else {
                    E(2);
                }
            }
        } else if (properties.f3853c) {
            E(1);
        } else {
            E(0);
        }
        F(1);
        if (this.f7786d != 4) {
            removeAllViews();
            this.f7790h.clear();
            h hVar = this.f7795m;
            h.b(hVar);
            hVar.f7833d = 0;
            this.f7786d = 4;
            requestLayout();
        }
        this.Y = context;
    }
}
