package com.google.android.flexbox;

import android.graphics.drawable.Drawable;
import android.util.SparseIntArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import androidx.core.view.u;
import com.google.android.gms.common.api.Api;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public class d {

    /* renamed from: a, reason: collision with root package name */
    private final com.google.android.flexbox.a f12765a;

    /* renamed from: b, reason: collision with root package name */
    private boolean[] f12766b;

    /* renamed from: c, reason: collision with root package name */
    int[] f12767c;

    /* renamed from: d, reason: collision with root package name */
    long[] f12768d;

    /* renamed from: e, reason: collision with root package name */
    private long[] f12769e;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static class b {

        /* renamed from: a, reason: collision with root package name */
        List f12770a;

        /* renamed from: b, reason: collision with root package name */
        int f12771b;

        /* JADX INFO: Access modifiers changed from: package-private */
        public void a() {
            this.f12770a = null;
            this.f12771b = 0;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes.dex */
    public static class c implements Comparable {

        /* renamed from: p, reason: collision with root package name */
        int f12772p;

        /* renamed from: q, reason: collision with root package name */
        int f12773q;

        private c() {
        }

        @Override // java.lang.Comparable
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public int compareTo(c cVar) {
            int i10 = this.f12773q;
            int i11 = cVar.f12773q;
            return i10 != i11 ? i10 - i11 : this.f12772p - cVar.f12772p;
        }

        public String toString() {
            return "Order{order=" + this.f12773q + ", index=" + this.f12772p + '}';
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public d(com.google.android.flexbox.a aVar) {
        this.f12765a = aVar;
    }

    private int A(int i10, com.google.android.flexbox.b bVar, int i11) {
        com.google.android.flexbox.a aVar = this.f12765a;
        int e10 = aVar.e(i10, aVar.getPaddingLeft() + this.f12765a.getPaddingRight() + bVar.V() + bVar.A0() + i11, bVar.getWidth());
        int size = View.MeasureSpec.getSize(e10);
        return size > bVar.Q0() ? View.MeasureSpec.makeMeasureSpec(bVar.Q0(), View.MeasureSpec.getMode(e10)) : size < bVar.L() ? View.MeasureSpec.makeMeasureSpec(bVar.L(), View.MeasureSpec.getMode(e10)) : e10;
    }

    private int B(com.google.android.flexbox.b bVar, boolean z10) {
        return z10 ? bVar.T() : bVar.A0();
    }

    private int C(com.google.android.flexbox.b bVar, boolean z10) {
        return z10 ? bVar.A0() : bVar.T();
    }

    private int D(com.google.android.flexbox.b bVar, boolean z10) {
        return z10 ? bVar.a0() : bVar.V();
    }

    private int E(com.google.android.flexbox.b bVar, boolean z10) {
        return z10 ? bVar.V() : bVar.a0();
    }

    private int F(com.google.android.flexbox.b bVar, boolean z10) {
        return z10 ? bVar.getHeight() : bVar.getWidth();
    }

    private int G(com.google.android.flexbox.b bVar, boolean z10) {
        return z10 ? bVar.getWidth() : bVar.getHeight();
    }

    private int H(boolean z10) {
        return z10 ? this.f12765a.getPaddingBottom() : this.f12765a.getPaddingEnd();
    }

    private int I(boolean z10) {
        return z10 ? this.f12765a.getPaddingEnd() : this.f12765a.getPaddingBottom();
    }

    private int J(boolean z10) {
        return z10 ? this.f12765a.getPaddingTop() : this.f12765a.getPaddingStart();
    }

    private int K(boolean z10) {
        return z10 ? this.f12765a.getPaddingStart() : this.f12765a.getPaddingTop();
    }

    private int L(View view, boolean z10) {
        return z10 ? view.getMeasuredHeight() : view.getMeasuredWidth();
    }

    private int M(View view, boolean z10) {
        return z10 ? view.getMeasuredWidth() : view.getMeasuredHeight();
    }

    private boolean N(int i10, int i11, com.google.android.flexbox.c cVar) {
        return i10 == i11 - 1 && cVar.c() != 0;
    }

    private boolean P(View view, int i10, int i11, int i12, int i13, com.google.android.flexbox.b bVar, int i14, int i15, int i16) {
        if (this.f12765a.getFlexWrap() == 0) {
            return false;
        }
        if (bVar.D0()) {
            return true;
        }
        if (i10 == 0) {
            return false;
        }
        int maxLine = this.f12765a.getMaxLine();
        if (maxLine != -1 && maxLine <= i16 + 1) {
            return false;
        }
        int h10 = this.f12765a.h(view, i14, i15);
        if (h10 > 0) {
            i13 += h10;
        }
        return i11 < i12 + i13;
    }

    private void T(int i10, int i11, com.google.android.flexbox.c cVar, int i12, int i13, boolean z10) {
        int i14;
        int i15 = cVar.f12751e;
        float f10 = cVar.f12757k;
        float f11 = BitmapDescriptorFactory.HUE_RED;
        if (f10 <= BitmapDescriptorFactory.HUE_RED || i12 > i15) {
            return;
        }
        float f12 = (i15 - i12) / f10;
        cVar.f12751e = i13 + cVar.f12752f;
        if (!z10) {
            cVar.f12753g = Integer.MIN_VALUE;
        }
        int i16 = 0;
        boolean z11 = false;
        int i17 = 0;
        float f13 = 0.0f;
        while (i16 < cVar.f12754h) {
            int i18 = cVar.f12761o + i16;
            View d10 = this.f12765a.d(i18);
            if (d10 != null && d10.getVisibility() != 8) {
                com.google.android.flexbox.b bVar = (com.google.android.flexbox.b) d10.getLayoutParams();
                int flexDirection = this.f12765a.getFlexDirection();
                if (flexDirection == 0 || flexDirection == 1) {
                    int measuredWidth = d10.getMeasuredWidth();
                    long[] jArr = this.f12769e;
                    if (jArr != null) {
                        measuredWidth = y(jArr[i18]);
                    }
                    int measuredHeight = d10.getMeasuredHeight();
                    long[] jArr2 = this.f12769e;
                    if (jArr2 != null) {
                        measuredHeight = x(jArr2[i18]);
                    }
                    if (!this.f12766b[i18] && bVar.G() > BitmapDescriptorFactory.HUE_RED) {
                        float G = measuredWidth - (bVar.G() * f12);
                        if (i16 == cVar.f12754h - 1) {
                            G += f13;
                            f13 = 0.0f;
                        }
                        int round = Math.round(G);
                        if (round < bVar.L()) {
                            round = bVar.L();
                            this.f12766b[i18] = true;
                            cVar.f12757k -= bVar.G();
                            z11 = true;
                        } else {
                            f13 += G - round;
                            double d11 = f13;
                            if (d11 > 1.0d) {
                                round++;
                                f13 -= 1.0f;
                            } else if (d11 < -1.0d) {
                                round--;
                                f13 += 1.0f;
                            }
                        }
                        int z12 = z(i11, bVar, cVar.f12759m);
                        int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(round, 1073741824);
                        d10.measure(makeMeasureSpec, z12);
                        int measuredWidth2 = d10.getMeasuredWidth();
                        int measuredHeight2 = d10.getMeasuredHeight();
                        Z(i18, makeMeasureSpec, z12, d10);
                        this.f12765a.f(i18, d10);
                        measuredWidth = measuredWidth2;
                        measuredHeight = measuredHeight2;
                    }
                    int max = Math.max(i17, measuredHeight + bVar.a0() + bVar.T() + this.f12765a.k(d10));
                    cVar.f12751e += measuredWidth + bVar.V() + bVar.A0();
                    i14 = max;
                } else {
                    int measuredHeight3 = d10.getMeasuredHeight();
                    long[] jArr3 = this.f12769e;
                    if (jArr3 != null) {
                        measuredHeight3 = x(jArr3[i18]);
                    }
                    int measuredWidth3 = d10.getMeasuredWidth();
                    long[] jArr4 = this.f12769e;
                    if (jArr4 != null) {
                        measuredWidth3 = y(jArr4[i18]);
                    }
                    if (!this.f12766b[i18] && bVar.G() > f11) {
                        float G2 = measuredHeight3 - (bVar.G() * f12);
                        if (i16 == cVar.f12754h - 1) {
                            G2 += f13;
                            f13 = f11;
                        }
                        int round2 = Math.round(G2);
                        if (round2 < bVar.C0()) {
                            round2 = bVar.C0();
                            this.f12766b[i18] = true;
                            cVar.f12757k -= bVar.G();
                            z11 = true;
                        } else {
                            f13 += G2 - round2;
                            double d12 = f13;
                            if (d12 > 1.0d) {
                                round2++;
                                f13 -= 1.0f;
                            } else if (d12 < -1.0d) {
                                round2--;
                                f13 += 1.0f;
                            }
                        }
                        int A = A(i10, bVar, cVar.f12759m);
                        int makeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(round2, 1073741824);
                        d10.measure(A, makeMeasureSpec2);
                        measuredWidth3 = d10.getMeasuredWidth();
                        int measuredHeight4 = d10.getMeasuredHeight();
                        Z(i18, A, makeMeasureSpec2, d10);
                        this.f12765a.f(i18, d10);
                        measuredHeight3 = measuredHeight4;
                    }
                    i14 = Math.max(i17, measuredWidth3 + bVar.V() + bVar.A0() + this.f12765a.k(d10));
                    cVar.f12751e += measuredHeight3 + bVar.a0() + bVar.T();
                }
                cVar.f12753g = Math.max(cVar.f12753g, i14);
                i17 = i14;
            }
            i16++;
            f11 = BitmapDescriptorFactory.HUE_RED;
        }
        if (!z11 || i15 == cVar.f12751e) {
            return;
        }
        T(i10, i11, cVar, i12, i13, true);
    }

    private int[] U(int i10, List list, SparseIntArray sparseIntArray) {
        Collections.sort(list);
        sparseIntArray.clear();
        int[] iArr = new int[i10];
        Iterator it = list.iterator();
        int i11 = 0;
        while (it.hasNext()) {
            c cVar = (c) it.next();
            int i12 = cVar.f12772p;
            iArr[i11] = i12;
            sparseIntArray.append(i12, cVar.f12773q);
            i11++;
        }
        return iArr;
    }

    private void V(View view, int i10, int i11) {
        com.google.android.flexbox.b bVar = (com.google.android.flexbox.b) view.getLayoutParams();
        int min = Math.min(Math.max(((i10 - bVar.V()) - bVar.A0()) - this.f12765a.k(view), bVar.L()), bVar.Q0());
        long[] jArr = this.f12769e;
        int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(jArr != null ? x(jArr[i11]) : view.getMeasuredHeight(), 1073741824);
        int makeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(min, 1073741824);
        view.measure(makeMeasureSpec2, makeMeasureSpec);
        Z(i11, makeMeasureSpec2, makeMeasureSpec, view);
        this.f12765a.f(i11, view);
    }

    private void W(View view, int i10, int i11) {
        com.google.android.flexbox.b bVar = (com.google.android.flexbox.b) view.getLayoutParams();
        int min = Math.min(Math.max(((i10 - bVar.a0()) - bVar.T()) - this.f12765a.k(view), bVar.C0()), bVar.F0());
        long[] jArr = this.f12769e;
        int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(jArr != null ? y(jArr[i11]) : view.getMeasuredWidth(), 1073741824);
        int makeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(min, 1073741824);
        view.measure(makeMeasureSpec, makeMeasureSpec2);
        Z(i11, makeMeasureSpec, makeMeasureSpec2, view);
        this.f12765a.f(i11, view);
    }

    private void Z(int i10, int i11, int i12, View view) {
        long[] jArr = this.f12768d;
        if (jArr != null) {
            jArr[i10] = S(i11, i12);
        }
        long[] jArr2 = this.f12769e;
        if (jArr2 != null) {
            jArr2[i10] = S(view.getMeasuredWidth(), view.getMeasuredHeight());
        }
    }

    private void a(List list, com.google.android.flexbox.c cVar, int i10, int i11) {
        cVar.f12759m = i11;
        this.f12765a.c(cVar);
        cVar.f12762p = i10;
        list.add(cVar);
    }

    /* JADX WARN: Removed duplicated region for block: B:12:? A[RETURN, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:13:0x0032  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x002d  */
    /* JADX WARN: Removed duplicated region for block: B:9:0x0040  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private void i(View view, int i10) {
        boolean z10;
        com.google.android.flexbox.b bVar = (com.google.android.flexbox.b) view.getLayoutParams();
        int measuredWidth = view.getMeasuredWidth();
        int measuredHeight = view.getMeasuredHeight();
        boolean z11 = true;
        if (measuredWidth < bVar.L()) {
            measuredWidth = bVar.L();
        } else {
            if (measuredWidth <= bVar.Q0()) {
                z10 = false;
                if (measuredHeight >= bVar.C0()) {
                    measuredHeight = bVar.C0();
                } else if (measuredHeight > bVar.F0()) {
                    measuredHeight = bVar.F0();
                } else {
                    z11 = z10;
                }
                if (z11) {
                    return;
                }
                int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(measuredWidth, 1073741824);
                int makeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(measuredHeight, 1073741824);
                view.measure(makeMeasureSpec, makeMeasureSpec2);
                Z(i10, makeMeasureSpec, makeMeasureSpec2, view);
                this.f12765a.f(i10, view);
                return;
            }
            measuredWidth = bVar.Q0();
        }
        z10 = true;
        if (measuredHeight >= bVar.C0()) {
        }
        if (z11) {
        }
    }

    private List k(List list, int i10, int i11) {
        int i12 = (i10 - i11) / 2;
        ArrayList arrayList = new ArrayList();
        com.google.android.flexbox.c cVar = new com.google.android.flexbox.c();
        cVar.f12753g = i12;
        int size = list.size();
        for (int i13 = 0; i13 < size; i13++) {
            if (i13 == 0) {
                arrayList.add(cVar);
            }
            arrayList.add((com.google.android.flexbox.c) list.get(i13));
            if (i13 == list.size() - 1) {
                arrayList.add(cVar);
            }
        }
        return arrayList;
    }

    private List l(int i10) {
        ArrayList arrayList = new ArrayList(i10);
        for (int i11 = 0; i11 < i10; i11++) {
            com.google.android.flexbox.b bVar = (com.google.android.flexbox.b) this.f12765a.g(i11).getLayoutParams();
            c cVar = new c();
            cVar.f12773q = bVar.getOrder();
            cVar.f12772p = i11;
            arrayList.add(cVar);
        }
        return arrayList;
    }

    private void r(int i10) {
        boolean[] zArr = this.f12766b;
        if (zArr == null) {
            this.f12766b = new boolean[Math.max(i10, 10)];
        } else if (zArr.length < i10) {
            this.f12766b = new boolean[Math.max(zArr.length * 2, i10)];
        } else {
            Arrays.fill(zArr, false);
        }
    }

    private void v(CompoundButton compoundButton) {
        com.google.android.flexbox.b bVar = (com.google.android.flexbox.b) compoundButton.getLayoutParams();
        int L = bVar.L();
        int C0 = bVar.C0();
        Drawable a10 = androidx.core.widget.d.a(compoundButton);
        int minimumWidth = a10 == null ? 0 : a10.getMinimumWidth();
        int minimumHeight = a10 != null ? a10.getMinimumHeight() : 0;
        if (L == -1) {
            L = minimumWidth;
        }
        bVar.S(L);
        if (C0 == -1) {
            C0 = minimumHeight;
        }
        bVar.g0(C0);
    }

    private void w(int i10, int i11, com.google.android.flexbox.c cVar, int i12, int i13, boolean z10) {
        int i14;
        int i15;
        int i16;
        double d10;
        double d11;
        float f10 = cVar.f12756j;
        float f11 = BitmapDescriptorFactory.HUE_RED;
        if (f10 <= BitmapDescriptorFactory.HUE_RED || i12 < (i14 = cVar.f12751e)) {
            return;
        }
        float f12 = (i12 - i14) / f10;
        cVar.f12751e = i13 + cVar.f12752f;
        if (!z10) {
            cVar.f12753g = Integer.MIN_VALUE;
        }
        int i17 = 0;
        boolean z11 = false;
        int i18 = 0;
        float f13 = 0.0f;
        while (i17 < cVar.f12754h) {
            int i19 = cVar.f12761o + i17;
            View d12 = this.f12765a.d(i19);
            if (d12 == null || d12.getVisibility() == 8) {
                i15 = i14;
            } else {
                com.google.android.flexbox.b bVar = (com.google.android.flexbox.b) d12.getLayoutParams();
                int flexDirection = this.f12765a.getFlexDirection();
                if (flexDirection == 0 || flexDirection == 1) {
                    i15 = i14;
                    int measuredWidth = d12.getMeasuredWidth();
                    long[] jArr = this.f12769e;
                    if (jArr != null) {
                        measuredWidth = y(jArr[i19]);
                    }
                    int measuredHeight = d12.getMeasuredHeight();
                    long[] jArr2 = this.f12769e;
                    if (jArr2 != null) {
                        measuredHeight = x(jArr2[i19]);
                    }
                    if (!this.f12766b[i19] && bVar.j0() > BitmapDescriptorFactory.HUE_RED) {
                        float j02 = measuredWidth + (bVar.j0() * f12);
                        if (i17 == cVar.f12754h - 1) {
                            j02 += f13;
                            f13 = 0.0f;
                        }
                        int round = Math.round(j02);
                        if (round > bVar.Q0()) {
                            round = bVar.Q0();
                            this.f12766b[i19] = true;
                            cVar.f12756j -= bVar.j0();
                            z11 = true;
                        } else {
                            f13 += j02 - round;
                            double d13 = f13;
                            if (d13 > 1.0d) {
                                round++;
                                d10 = d13 - 1.0d;
                            } else if (d13 < -1.0d) {
                                round--;
                                d10 = d13 + 1.0d;
                            }
                            f13 = (float) d10;
                        }
                        int z12 = z(i11, bVar, cVar.f12759m);
                        int makeMeasureSpec = View.MeasureSpec.makeMeasureSpec(round, 1073741824);
                        d12.measure(makeMeasureSpec, z12);
                        int measuredWidth2 = d12.getMeasuredWidth();
                        int measuredHeight2 = d12.getMeasuredHeight();
                        Z(i19, makeMeasureSpec, z12, d12);
                        this.f12765a.f(i19, d12);
                        measuredWidth = measuredWidth2;
                        measuredHeight = measuredHeight2;
                    }
                    int max = Math.max(i18, measuredHeight + bVar.a0() + bVar.T() + this.f12765a.k(d12));
                    cVar.f12751e += measuredWidth + bVar.V() + bVar.A0();
                    i16 = max;
                } else {
                    int measuredHeight3 = d12.getMeasuredHeight();
                    long[] jArr3 = this.f12769e;
                    if (jArr3 != null) {
                        measuredHeight3 = x(jArr3[i19]);
                    }
                    int measuredWidth3 = d12.getMeasuredWidth();
                    long[] jArr4 = this.f12769e;
                    if (jArr4 != null) {
                        measuredWidth3 = y(jArr4[i19]);
                    }
                    if (this.f12766b[i19] || bVar.j0() <= f11) {
                        i15 = i14;
                    } else {
                        float j03 = measuredHeight3 + (bVar.j0() * f12);
                        if (i17 == cVar.f12754h - 1) {
                            j03 += f13;
                            f13 = f11;
                        }
                        int round2 = Math.round(j03);
                        if (round2 > bVar.F0()) {
                            round2 = bVar.F0();
                            this.f12766b[i19] = true;
                            cVar.f12756j -= bVar.j0();
                            i15 = i14;
                            z11 = true;
                        } else {
                            f13 += j03 - round2;
                            i15 = i14;
                            double d14 = f13;
                            if (d14 > 1.0d) {
                                round2++;
                                d11 = d14 - 1.0d;
                            } else if (d14 < -1.0d) {
                                round2--;
                                d11 = d14 + 1.0d;
                            }
                            f13 = (float) d11;
                        }
                        int A = A(i10, bVar, cVar.f12759m);
                        int makeMeasureSpec2 = View.MeasureSpec.makeMeasureSpec(round2, 1073741824);
                        d12.measure(A, makeMeasureSpec2);
                        measuredWidth3 = d12.getMeasuredWidth();
                        int measuredHeight4 = d12.getMeasuredHeight();
                        Z(i19, A, makeMeasureSpec2, d12);
                        this.f12765a.f(i19, d12);
                        measuredHeight3 = measuredHeight4;
                    }
                    i16 = Math.max(i18, measuredWidth3 + bVar.V() + bVar.A0() + this.f12765a.k(d12));
                    cVar.f12751e += measuredHeight3 + bVar.a0() + bVar.T();
                }
                cVar.f12753g = Math.max(cVar.f12753g, i16);
                i18 = i16;
            }
            i17++;
            i14 = i15;
            f11 = BitmapDescriptorFactory.HUE_RED;
        }
        int i20 = i14;
        if (!z11 || i20 == cVar.f12751e) {
            return;
        }
        w(i10, i11, cVar, i12, i13, true);
    }

    private int z(int i10, com.google.android.flexbox.b bVar, int i11) {
        com.google.android.flexbox.a aVar = this.f12765a;
        int i12 = aVar.i(i10, aVar.getPaddingTop() + this.f12765a.getPaddingBottom() + bVar.a0() + bVar.T() + i11, bVar.getHeight());
        int size = View.MeasureSpec.getSize(i12);
        return size > bVar.F0() ? View.MeasureSpec.makeMeasureSpec(bVar.F0(), View.MeasureSpec.getMode(i12)) : size < bVar.C0() ? View.MeasureSpec.makeMeasureSpec(bVar.C0(), View.MeasureSpec.getMode(i12)) : i12;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean O(SparseIntArray sparseIntArray) {
        int flexItemCount = this.f12765a.getFlexItemCount();
        if (sparseIntArray.size() != flexItemCount) {
            return true;
        }
        for (int i10 = 0; i10 < flexItemCount; i10++) {
            View g10 = this.f12765a.g(i10);
            if (g10 != null && ((com.google.android.flexbox.b) g10.getLayoutParams()).getOrder() != sparseIntArray.get(i10)) {
                return true;
            }
        }
        return false;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void Q(View view, com.google.android.flexbox.c cVar, int i10, int i11, int i12, int i13) {
        com.google.android.flexbox.b bVar = (com.google.android.flexbox.b) view.getLayoutParams();
        int alignItems = this.f12765a.getAlignItems();
        if (bVar.C() != -1) {
            alignItems = bVar.C();
        }
        int i14 = cVar.f12753g;
        if (alignItems != 0) {
            if (alignItems == 1) {
                if (this.f12765a.getFlexWrap() == 2) {
                    view.layout(i10, (i11 - i14) + view.getMeasuredHeight() + bVar.a0(), i12, (i13 - i14) + view.getMeasuredHeight() + bVar.a0());
                    return;
                } else {
                    int i15 = i11 + i14;
                    view.layout(i10, (i15 - view.getMeasuredHeight()) - bVar.T(), i12, i15 - bVar.T());
                    return;
                }
            }
            if (alignItems == 2) {
                int measuredHeight = (((i14 - view.getMeasuredHeight()) + bVar.a0()) - bVar.T()) / 2;
                if (this.f12765a.getFlexWrap() != 2) {
                    int i16 = i11 + measuredHeight;
                    view.layout(i10, i16, i12, view.getMeasuredHeight() + i16);
                    return;
                } else {
                    int i17 = i11 - measuredHeight;
                    view.layout(i10, i17, i12, view.getMeasuredHeight() + i17);
                    return;
                }
            }
            if (alignItems == 3) {
                if (this.f12765a.getFlexWrap() != 2) {
                    int max = Math.max(cVar.f12758l - view.getBaseline(), bVar.a0());
                    view.layout(i10, i11 + max, i12, i13 + max);
                    return;
                } else {
                    int max2 = Math.max((cVar.f12758l - view.getMeasuredHeight()) + view.getBaseline(), bVar.T());
                    view.layout(i10, i11 - max2, i12, i13 - max2);
                    return;
                }
            }
            if (alignItems != 4) {
                return;
            }
        }
        if (this.f12765a.getFlexWrap() != 2) {
            view.layout(i10, i11 + bVar.a0(), i12, i13 + bVar.a0());
        } else {
            view.layout(i10, i11 - bVar.T(), i12, i13 - bVar.T());
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void R(View view, com.google.android.flexbox.c cVar, boolean z10, int i10, int i11, int i12, int i13) {
        com.google.android.flexbox.b bVar = (com.google.android.flexbox.b) view.getLayoutParams();
        int alignItems = this.f12765a.getAlignItems();
        if (bVar.C() != -1) {
            alignItems = bVar.C();
        }
        int i14 = cVar.f12753g;
        if (alignItems != 0) {
            if (alignItems == 1) {
                if (z10) {
                    view.layout((i10 - i14) + view.getMeasuredWidth() + bVar.V(), i11, (i12 - i14) + view.getMeasuredWidth() + bVar.V(), i13);
                    return;
                } else {
                    view.layout(((i10 + i14) - view.getMeasuredWidth()) - bVar.A0(), i11, ((i12 + i14) - view.getMeasuredWidth()) - bVar.A0(), i13);
                    return;
                }
            }
            if (alignItems == 2) {
                ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
                int measuredWidth = (((i14 - view.getMeasuredWidth()) + u.b(marginLayoutParams)) - u.a(marginLayoutParams)) / 2;
                if (z10) {
                    view.layout(i10 - measuredWidth, i11, i12 - measuredWidth, i13);
                    return;
                } else {
                    view.layout(i10 + measuredWidth, i11, i12 + measuredWidth, i13);
                    return;
                }
            }
            if (alignItems != 3 && alignItems != 4) {
                return;
            }
        }
        if (z10) {
            view.layout(i10 - bVar.A0(), i11, i12 - bVar.A0(), i13);
        } else {
            view.layout(i10 + bVar.V(), i11, i12 + bVar.V(), i13);
        }
    }

    long S(int i10, int i11) {
        return (i10 & 4294967295L) | (i11 << 32);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void X() {
        Y(0);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void Y(int i10) {
        View d10;
        if (i10 >= this.f12765a.getFlexItemCount()) {
            return;
        }
        int flexDirection = this.f12765a.getFlexDirection();
        if (this.f12765a.getAlignItems() != 4) {
            for (com.google.android.flexbox.c cVar : this.f12765a.getFlexLinesInternal()) {
                for (Integer num : cVar.f12760n) {
                    View d11 = this.f12765a.d(num.intValue());
                    if (flexDirection == 0 || flexDirection == 1) {
                        W(d11, cVar.f12753g, num.intValue());
                    } else {
                        if (flexDirection != 2 && flexDirection != 3) {
                            throw new IllegalArgumentException("Invalid flex direction: " + flexDirection);
                        }
                        V(d11, cVar.f12753g, num.intValue());
                    }
                }
            }
            return;
        }
        int[] iArr = this.f12767c;
        List flexLinesInternal = this.f12765a.getFlexLinesInternal();
        int size = flexLinesInternal.size();
        for (int i11 = iArr != null ? iArr[i10] : 0; i11 < size; i11++) {
            com.google.android.flexbox.c cVar2 = (com.google.android.flexbox.c) flexLinesInternal.get(i11);
            int i12 = cVar2.f12754h;
            for (int i13 = 0; i13 < i12; i13++) {
                int i14 = cVar2.f12761o + i13;
                if (i13 < this.f12765a.getFlexItemCount() && (d10 = this.f12765a.d(i14)) != null && d10.getVisibility() != 8) {
                    com.google.android.flexbox.b bVar = (com.google.android.flexbox.b) d10.getLayoutParams();
                    if (bVar.C() == -1 || bVar.C() == 4) {
                        if (flexDirection == 0 || flexDirection == 1) {
                            W(d10, cVar2.f12753g, i14);
                        } else {
                            if (flexDirection != 2 && flexDirection != 3) {
                                throw new IllegalArgumentException("Invalid flex direction: " + flexDirection);
                            }
                            V(d10, cVar2.f12753g, i14);
                        }
                    }
                }
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* JADX WARN: Multi-variable type inference failed */
    public void b(b bVar, int i10, int i11, int i12, int i13, int i14, List list) {
        int i15;
        b bVar2;
        int i16;
        int i17;
        int i18;
        List list2;
        int i19;
        View view;
        int i20;
        int i21;
        int i22;
        int i23;
        int i24;
        int i25;
        int i26;
        int i27 = i10;
        int i28 = i11;
        int i29 = i14;
        boolean j10 = this.f12765a.j();
        int mode = View.MeasureSpec.getMode(i10);
        int size = View.MeasureSpec.getSize(i10);
        List arrayList = list == null ? new ArrayList() : list;
        bVar.f12770a = arrayList;
        int i30 = i29 == -1 ? 1 : 0;
        int K = K(j10);
        int I = I(j10);
        int J = J(j10);
        int H = H(j10);
        com.google.android.flexbox.c cVar = new com.google.android.flexbox.c();
        int i31 = i13;
        cVar.f12761o = i31;
        int i32 = I + K;
        cVar.f12751e = i32;
        int flexItemCount = this.f12765a.getFlexItemCount();
        int i33 = i30;
        int i34 = Integer.MIN_VALUE;
        int i35 = 0;
        int i36 = 0;
        int i37 = 0;
        while (true) {
            if (i31 >= flexItemCount) {
                i15 = i36;
                bVar2 = bVar;
                break;
            }
            View d10 = this.f12765a.d(i31);
            if (d10 != null) {
                if (d10.getVisibility() != 8) {
                    if (d10 instanceof CompoundButton) {
                        v((CompoundButton) d10);
                    }
                    com.google.android.flexbox.b bVar3 = (com.google.android.flexbox.b) d10.getLayoutParams();
                    int i38 = flexItemCount;
                    if (bVar3.C() == 4) {
                        cVar.f12760n.add(Integer.valueOf(i31));
                    }
                    int G = G(bVar3, j10);
                    if (bVar3.o0() != -1.0f && mode == 1073741824) {
                        G = Math.round(size * bVar3.o0());
                    }
                    if (j10) {
                        int e10 = this.f12765a.e(i27, i32 + E(bVar3, true) + C(bVar3, true), G);
                        i16 = size;
                        i17 = mode;
                        int i39 = this.f12765a.i(i28, J + H + D(bVar3, true) + B(bVar3, true) + i35, F(bVar3, true));
                        d10.measure(e10, i39);
                        Z(i31, e10, i39, d10);
                        i18 = e10;
                    } else {
                        i16 = size;
                        i17 = mode;
                        int e11 = this.f12765a.e(i28, J + H + D(bVar3, false) + B(bVar3, false) + i35, F(bVar3, false));
                        int i40 = this.f12765a.i(i27, E(bVar3, false) + i32 + C(bVar3, false), G);
                        d10.measure(e11, i40);
                        Z(i31, e11, i40, d10);
                        i18 = i40;
                    }
                    this.f12765a.f(i31, d10);
                    i(d10, i31);
                    i36 = View.combineMeasuredStates(i36, d10.getMeasuredState());
                    int i41 = i35;
                    int i42 = i32;
                    com.google.android.flexbox.c cVar2 = cVar;
                    int i43 = i31;
                    list2 = arrayList;
                    int i44 = i18;
                    if (P(d10, i17, i16, cVar.f12751e, C(bVar3, j10) + M(d10, j10) + E(bVar3, j10), bVar3, i43, i37, arrayList.size())) {
                        if (cVar2.c() > 0) {
                            a(list2, cVar2, i43 > 0 ? i43 - 1 : 0, i41);
                            i35 = cVar2.f12753g + i41;
                        } else {
                            i35 = i41;
                        }
                        if (!j10) {
                            i19 = i11;
                            view = d10;
                            i31 = i43;
                            if (bVar3.getWidth() == -1) {
                                com.google.android.flexbox.a aVar = this.f12765a;
                                view.measure(aVar.e(i19, aVar.getPaddingLeft() + this.f12765a.getPaddingRight() + bVar3.V() + bVar3.A0() + i35, bVar3.getWidth()), i44);
                                i(view, i31);
                            }
                        } else if (bVar3.getHeight() == -1) {
                            com.google.android.flexbox.a aVar2 = this.f12765a;
                            i19 = i11;
                            i31 = i43;
                            view = d10;
                            view.measure(i44, aVar2.i(i19, aVar2.getPaddingTop() + this.f12765a.getPaddingBottom() + bVar3.a0() + bVar3.T() + i35, bVar3.getHeight()));
                            i(view, i31);
                        } else {
                            i19 = i11;
                            view = d10;
                            i31 = i43;
                        }
                        cVar = new com.google.android.flexbox.c();
                        i21 = 1;
                        cVar.f12754h = 1;
                        i20 = i42;
                        cVar.f12751e = i20;
                        cVar.f12761o = i31;
                        i23 = Integer.MIN_VALUE;
                        i22 = 0;
                    } else {
                        i19 = i11;
                        view = d10;
                        i31 = i43;
                        cVar = cVar2;
                        i20 = i42;
                        i21 = 1;
                        cVar.f12754h++;
                        i22 = i37 + 1;
                        i35 = i41;
                        i23 = i34;
                    }
                    cVar.f12763q = (cVar.f12763q ? 1 : 0) | (bVar3.j0() != BitmapDescriptorFactory.HUE_RED ? i21 : 0);
                    cVar.f12764r = (cVar.f12764r ? 1 : 0) | (bVar3.G() != BitmapDescriptorFactory.HUE_RED ? i21 : 0);
                    int[] iArr = this.f12767c;
                    if (iArr != null) {
                        iArr[i31] = list2.size();
                    }
                    cVar.f12751e += M(view, j10) + E(bVar3, j10) + C(bVar3, j10);
                    cVar.f12756j += bVar3.j0();
                    cVar.f12757k += bVar3.G();
                    this.f12765a.b(view, i31, i22, cVar);
                    int max = Math.max(i23, L(view, j10) + D(bVar3, j10) + B(bVar3, j10) + this.f12765a.k(view));
                    cVar.f12753g = Math.max(cVar.f12753g, max);
                    if (j10) {
                        if (this.f12765a.getFlexWrap() != 2) {
                            cVar.f12758l = Math.max(cVar.f12758l, view.getBaseline() + bVar3.a0());
                        } else {
                            cVar.f12758l = Math.max(cVar.f12758l, (view.getMeasuredHeight() - view.getBaseline()) + bVar3.T());
                        }
                    }
                    i24 = i38;
                    if (N(i31, i24, cVar)) {
                        a(list2, cVar, i31, i35);
                        i35 += cVar.f12753g;
                    }
                    i25 = i14;
                    if (i25 == -1 || list2.size() <= 0 || ((com.google.android.flexbox.c) list2.get(list2.size() - i21)).f12762p < i25 || i31 < i25 || i33 != 0) {
                        i26 = i12;
                    } else {
                        i35 = -cVar.a();
                        i26 = i12;
                        i33 = i21;
                    }
                    if (i35 > i26 && i33 != 0) {
                        bVar2 = bVar;
                        i15 = i36;
                        break;
                    }
                    i37 = i22;
                    i34 = max;
                    i31++;
                    i27 = i10;
                    flexItemCount = i24;
                    i28 = i19;
                    i32 = i20;
                    arrayList = list2;
                    size = i16;
                    i29 = i25;
                    mode = i17;
                } else {
                    cVar.f12755i++;
                    cVar.f12754h++;
                    if (N(i31, flexItemCount, cVar)) {
                        a(arrayList, cVar, i31, i35);
                    }
                }
            } else if (N(i31, flexItemCount, cVar)) {
                a(arrayList, cVar, i31, i35);
            }
            i16 = size;
            i17 = mode;
            i19 = i28;
            i25 = i29;
            list2 = arrayList;
            i20 = i32;
            i24 = flexItemCount;
            i31++;
            i27 = i10;
            flexItemCount = i24;
            i28 = i19;
            i32 = i20;
            arrayList = list2;
            size = i16;
            i29 = i25;
            mode = i17;
        }
        bVar2.f12771b = i15;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void c(b bVar, int i10, int i11) {
        b(bVar, i10, i11, Api.BaseClientBuilder.API_PRIORITY_OTHER, 0, -1, null);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void d(b bVar, int i10, int i11, int i12, int i13, List list) {
        b(bVar, i10, i11, i12, i13, -1, list);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void e(b bVar, int i10, int i11, int i12, int i13, List list) {
        b(bVar, i10, i11, i12, 0, i13, list);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void f(b bVar, int i10, int i11) {
        b(bVar, i11, i10, Api.BaseClientBuilder.API_PRIORITY_OTHER, 0, -1, null);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void g(b bVar, int i10, int i11, int i12, int i13, List list) {
        b(bVar, i11, i10, i12, i13, -1, list);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void h(b bVar, int i10, int i11, int i12, int i13, List list) {
        b(bVar, i11, i10, i12, 0, i13, list);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void j(List list, int i10) {
        int i11 = this.f12767c[i10];
        if (i11 == -1) {
            i11 = 0;
        }
        if (list.size() > i11) {
            list.subList(i11, list.size()).clear();
        }
        int[] iArr = this.f12767c;
        int length = iArr.length - 1;
        if (i10 > length) {
            Arrays.fill(iArr, -1);
        } else {
            Arrays.fill(iArr, i10, length, -1);
        }
        long[] jArr = this.f12768d;
        int length2 = jArr.length - 1;
        if (i10 > length2) {
            Arrays.fill(jArr, 0L);
        } else {
            Arrays.fill(jArr, i10, length2, 0L);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public int[] m(SparseIntArray sparseIntArray) {
        int flexItemCount = this.f12765a.getFlexItemCount();
        return U(flexItemCount, l(flexItemCount), sparseIntArray);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* JADX WARN: Multi-variable type inference failed */
    public int[] n(View view, int i10, ViewGroup.LayoutParams layoutParams, SparseIntArray sparseIntArray) {
        int flexItemCount = this.f12765a.getFlexItemCount();
        List l10 = l(flexItemCount);
        c cVar = new c();
        if (view == null || !(layoutParams instanceof com.google.android.flexbox.b)) {
            cVar.f12773q = 1;
        } else {
            cVar.f12773q = ((com.google.android.flexbox.b) layoutParams).getOrder();
        }
        if (i10 == -1 || i10 == flexItemCount) {
            cVar.f12772p = flexItemCount;
        } else if (i10 < this.f12765a.getFlexItemCount()) {
            cVar.f12772p = i10;
            while (i10 < flexItemCount) {
                ((c) l10.get(i10)).f12772p++;
                i10++;
            }
        } else {
            cVar.f12772p = flexItemCount;
        }
        l10.add(cVar);
        return U(flexItemCount + 1, l10, sparseIntArray);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void o(int i10, int i11, int i12) {
        int i13;
        int i14;
        int flexDirection = this.f12765a.getFlexDirection();
        if (flexDirection == 0 || flexDirection == 1) {
            int mode = View.MeasureSpec.getMode(i11);
            int size = View.MeasureSpec.getSize(i11);
            i13 = mode;
            i14 = size;
        } else {
            if (flexDirection != 2 && flexDirection != 3) {
                throw new IllegalArgumentException("Invalid flex direction: " + flexDirection);
            }
            i13 = View.MeasureSpec.getMode(i10);
            i14 = View.MeasureSpec.getSize(i10);
        }
        List<com.google.android.flexbox.c> flexLinesInternal = this.f12765a.getFlexLinesInternal();
        if (i13 == 1073741824) {
            int sumOfCrossSize = this.f12765a.getSumOfCrossSize() + i12;
            int i15 = 0;
            if (flexLinesInternal.size() == 1) {
                ((com.google.android.flexbox.c) flexLinesInternal.get(0)).f12753g = i14 - i12;
                return;
            }
            if (flexLinesInternal.size() >= 2) {
                int alignContent = this.f12765a.getAlignContent();
                if (alignContent == 1) {
                    com.google.android.flexbox.c cVar = new com.google.android.flexbox.c();
                    cVar.f12753g = i14 - sumOfCrossSize;
                    flexLinesInternal.add(0, cVar);
                    return;
                }
                if (alignContent == 2) {
                    this.f12765a.setFlexLines(k(flexLinesInternal, i14, sumOfCrossSize));
                    return;
                }
                if (alignContent == 3) {
                    if (sumOfCrossSize >= i14) {
                        return;
                    }
                    float size2 = (i14 - sumOfCrossSize) / (flexLinesInternal.size() - 1);
                    ArrayList arrayList = new ArrayList();
                    int size3 = flexLinesInternal.size();
                    float f10 = 0.0f;
                    while (i15 < size3) {
                        arrayList.add((com.google.android.flexbox.c) flexLinesInternal.get(i15));
                        if (i15 != flexLinesInternal.size() - 1) {
                            com.google.android.flexbox.c cVar2 = new com.google.android.flexbox.c();
                            if (i15 == flexLinesInternal.size() - 2) {
                                cVar2.f12753g = Math.round(f10 + size2);
                                f10 = 0.0f;
                            } else {
                                cVar2.f12753g = Math.round(size2);
                            }
                            int i16 = cVar2.f12753g;
                            f10 += size2 - i16;
                            if (f10 > 1.0f) {
                                cVar2.f12753g = i16 + 1;
                                f10 -= 1.0f;
                            } else if (f10 < -1.0f) {
                                cVar2.f12753g = i16 - 1;
                                f10 += 1.0f;
                            }
                            arrayList.add(cVar2);
                        }
                        i15++;
                    }
                    this.f12765a.setFlexLines(arrayList);
                    return;
                }
                if (alignContent == 4) {
                    if (sumOfCrossSize >= i14) {
                        this.f12765a.setFlexLines(k(flexLinesInternal, i14, sumOfCrossSize));
                        return;
                    }
                    int size4 = (i14 - sumOfCrossSize) / (flexLinesInternal.size() * 2);
                    ArrayList arrayList2 = new ArrayList();
                    com.google.android.flexbox.c cVar3 = new com.google.android.flexbox.c();
                    cVar3.f12753g = size4;
                    for (com.google.android.flexbox.c cVar4 : flexLinesInternal) {
                        arrayList2.add(cVar3);
                        arrayList2.add(cVar4);
                        arrayList2.add(cVar3);
                    }
                    this.f12765a.setFlexLines(arrayList2);
                    return;
                }
                if (alignContent == 5 && sumOfCrossSize < i14) {
                    float size5 = (i14 - sumOfCrossSize) / flexLinesInternal.size();
                    int size6 = flexLinesInternal.size();
                    float f11 = 0.0f;
                    while (i15 < size6) {
                        com.google.android.flexbox.c cVar5 = (com.google.android.flexbox.c) flexLinesInternal.get(i15);
                        float f12 = cVar5.f12753g + size5;
                        if (i15 == flexLinesInternal.size() - 1) {
                            f12 += f11;
                            f11 = 0.0f;
                        }
                        int round = Math.round(f12);
                        f11 += f12 - round;
                        if (f11 > 1.0f) {
                            round++;
                            f11 -= 1.0f;
                        } else if (f11 < -1.0f) {
                            round--;
                            f11 += 1.0f;
                        }
                        cVar5.f12753g = round;
                        i15++;
                    }
                }
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void p(int i10, int i11) {
        q(i10, i11, 0);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void q(int i10, int i11, int i12) {
        int size;
        int paddingLeft;
        int paddingRight;
        r(this.f12765a.getFlexItemCount());
        if (i12 >= this.f12765a.getFlexItemCount()) {
            return;
        }
        int flexDirection = this.f12765a.getFlexDirection();
        int flexDirection2 = this.f12765a.getFlexDirection();
        if (flexDirection2 == 0 || flexDirection2 == 1) {
            int mode = View.MeasureSpec.getMode(i10);
            size = View.MeasureSpec.getSize(i10);
            int largestMainSize = this.f12765a.getLargestMainSize();
            if (mode != 1073741824) {
                size = Math.min(largestMainSize, size);
            }
            paddingLeft = this.f12765a.getPaddingLeft();
            paddingRight = this.f12765a.getPaddingRight();
        } else {
            if (flexDirection2 != 2 && flexDirection2 != 3) {
                throw new IllegalArgumentException("Invalid flex direction: " + flexDirection);
            }
            int mode2 = View.MeasureSpec.getMode(i11);
            size = View.MeasureSpec.getSize(i11);
            if (mode2 != 1073741824) {
                size = this.f12765a.getLargestMainSize();
            }
            paddingLeft = this.f12765a.getPaddingTop();
            paddingRight = this.f12765a.getPaddingBottom();
        }
        int i13 = paddingLeft + paddingRight;
        int[] iArr = this.f12767c;
        List flexLinesInternal = this.f12765a.getFlexLinesInternal();
        int size2 = flexLinesInternal.size();
        for (int i14 = iArr != null ? iArr[i12] : 0; i14 < size2; i14++) {
            com.google.android.flexbox.c cVar = (com.google.android.flexbox.c) flexLinesInternal.get(i14);
            int i15 = cVar.f12751e;
            if (i15 < size && cVar.f12763q) {
                w(i10, i11, cVar, size, i13, false);
            } else if (i15 > size && cVar.f12764r) {
                T(i10, i11, cVar, size, i13, false);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void s(int i10) {
        int[] iArr = this.f12767c;
        if (iArr == null) {
            this.f12767c = new int[Math.max(i10, 10)];
        } else if (iArr.length < i10) {
            this.f12767c = Arrays.copyOf(this.f12767c, Math.max(iArr.length * 2, i10));
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void t(int i10) {
        long[] jArr = this.f12768d;
        if (jArr == null) {
            this.f12768d = new long[Math.max(i10, 10)];
        } else if (jArr.length < i10) {
            this.f12768d = Arrays.copyOf(this.f12768d, Math.max(jArr.length * 2, i10));
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void u(int i10) {
        long[] jArr = this.f12769e;
        if (jArr == null) {
            this.f12769e = new long[Math.max(i10, 10)];
        } else if (jArr.length < i10) {
            this.f12769e = Arrays.copyOf(this.f12769e, Math.max(jArr.length * 2, i10));
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public int x(long j10) {
        return (int) (j10 >> 32);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public int y(long j10) {
        return (int) j10;
    }
}
