package i3;

import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
import i3.e;
import j3.b;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;

/* loaded from: classes.dex */
public class f extends k {
    private int O0;
    int S0;
    int T0;
    int U0;
    int V0;
    j3.b M0 = new j3.b(this);
    public j3.e N0 = new j3.e(this);
    protected b.InterfaceC0509b P0 = null;
    private boolean Q0 = false;
    protected f3.d R0 = new f3.d();
    public int W0 = 0;
    public int X0 = 0;
    c[] Y0 = new c[4];
    c[] Z0 = new c[4];

    /* renamed from: a1, reason: collision with root package name */
    public boolean f22387a1 = false;

    /* renamed from: b1, reason: collision with root package name */
    public boolean f22388b1 = false;

    /* renamed from: c1, reason: collision with root package name */
    public boolean f22389c1 = false;

    /* renamed from: d1, reason: collision with root package name */
    public int f22390d1 = 0;

    /* renamed from: e1, reason: collision with root package name */
    public int f22391e1 = 0;

    /* renamed from: f1, reason: collision with root package name */
    private int f22392f1 = 257;

    /* renamed from: g1, reason: collision with root package name */
    public boolean f22393g1 = false;

    /* renamed from: h1, reason: collision with root package name */
    private boolean f22394h1 = false;

    /* renamed from: i1, reason: collision with root package name */
    private boolean f22395i1 = false;

    /* renamed from: j1, reason: collision with root package name */
    int f22396j1 = 0;

    /* renamed from: k1, reason: collision with root package name */
    private WeakReference f22397k1 = null;

    /* renamed from: l1, reason: collision with root package name */
    private WeakReference f22398l1 = null;

    /* renamed from: m1, reason: collision with root package name */
    private WeakReference f22399m1 = null;

    /* renamed from: n1, reason: collision with root package name */
    private WeakReference f22400n1 = null;

    /* renamed from: o1, reason: collision with root package name */
    HashSet f22401o1 = new HashSet();

    /* renamed from: p1, reason: collision with root package name */
    public b.a f22402p1 = new b.a();

    public static boolean N1(int i10, e eVar, b.InterfaceC0509b interfaceC0509b, b.a aVar, int i11) {
        int i12;
        int i13;
        if (interfaceC0509b == null) {
            return false;
        }
        if (eVar.T() == 8 || (eVar instanceof g) || (eVar instanceof a)) {
            aVar.f23888e = 0;
            aVar.f23889f = 0;
            return false;
        }
        aVar.f23884a = eVar.y();
        aVar.f23885b = eVar.R();
        aVar.f23886c = eVar.U();
        aVar.f23887d = eVar.v();
        aVar.f23892i = false;
        aVar.f23893j = i11;
        e.b bVar = aVar.f23884a;
        e.b bVar2 = e.b.MATCH_CONSTRAINT;
        boolean z10 = bVar == bVar2;
        boolean z11 = aVar.f23885b == bVar2;
        boolean z12 = z10 && eVar.f22340d0 > BitmapDescriptorFactory.HUE_RED;
        boolean z13 = z11 && eVar.f22340d0 > BitmapDescriptorFactory.HUE_RED;
        if (z10 && eVar.Y(0) && eVar.f22377w == 0 && !z12) {
            aVar.f23884a = e.b.WRAP_CONTENT;
            if (z11 && eVar.f22379x == 0) {
                aVar.f23884a = e.b.FIXED;
            }
            z10 = false;
        }
        if (z11 && eVar.Y(1) && eVar.f22379x == 0 && !z13) {
            aVar.f23885b = e.b.WRAP_CONTENT;
            if (z10 && eVar.f22377w == 0) {
                aVar.f23885b = e.b.FIXED;
            }
            z11 = false;
        }
        if (eVar.l0()) {
            aVar.f23884a = e.b.FIXED;
            z10 = false;
        }
        if (eVar.m0()) {
            aVar.f23885b = e.b.FIXED;
            z11 = false;
        }
        if (z12) {
            if (eVar.f22381y[0] == 4) {
                aVar.f23884a = e.b.FIXED;
            } else if (!z11) {
                e.b bVar3 = aVar.f23885b;
                e.b bVar4 = e.b.FIXED;
                if (bVar3 == bVar4) {
                    i13 = aVar.f23887d;
                } else {
                    aVar.f23884a = e.b.WRAP_CONTENT;
                    interfaceC0509b.b(eVar, aVar);
                    i13 = aVar.f23889f;
                }
                aVar.f23884a = bVar4;
                aVar.f23886c = (int) (eVar.t() * i13);
            }
        }
        if (z13) {
            if (eVar.f22381y[1] == 4) {
                aVar.f23885b = e.b.FIXED;
            } else if (!z10) {
                e.b bVar5 = aVar.f23884a;
                e.b bVar6 = e.b.FIXED;
                if (bVar5 == bVar6) {
                    i12 = aVar.f23886c;
                } else {
                    aVar.f23885b = e.b.WRAP_CONTENT;
                    interfaceC0509b.b(eVar, aVar);
                    i12 = aVar.f23888e;
                }
                aVar.f23885b = bVar6;
                if (eVar.u() == -1) {
                    aVar.f23887d = (int) (i12 / eVar.t());
                } else {
                    aVar.f23887d = (int) (eVar.t() * i12);
                }
            }
        }
        interfaceC0509b.b(eVar, aVar);
        eVar.g1(aVar.f23888e);
        eVar.I0(aVar.f23889f);
        eVar.H0(aVar.f23891h);
        eVar.x0(aVar.f23890g);
        aVar.f23893j = b.a.f23881k;
        return aVar.f23892i;
    }

    private void P1() {
        this.W0 = 0;
        this.X0 = 0;
    }

    private void t1(e eVar) {
        int i10 = this.W0 + 1;
        c[] cVarArr = this.Z0;
        if (i10 >= cVarArr.length) {
            this.Z0 = (c[]) Arrays.copyOf(cVarArr, cVarArr.length * 2);
        }
        this.Z0[this.W0] = new c(eVar, 0, K1());
        this.W0++;
    }

    private void w1(d dVar, f3.i iVar) {
        this.R0.h(iVar, this.R0.q(dVar), 0, 5);
    }

    private void x1(d dVar, f3.i iVar) {
        this.R0.h(this.R0.q(dVar), iVar, 0, 5);
    }

    private void y1(e eVar) {
        int i10 = this.X0 + 1;
        c[] cVarArr = this.Y0;
        if (i10 >= cVarArr.length) {
            this.Y0 = (c[]) Arrays.copyOf(cVarArr, cVarArr.length * 2);
        }
        this.Y0[this.X0] = new c(eVar, 1, K1());
        this.X0++;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void A1(d dVar) {
        WeakReference weakReference = this.f22397k1;
        if (weakReference == null || weakReference.get() == null || dVar.d() > ((d) this.f22397k1.get()).d()) {
            this.f22397k1 = new WeakReference(dVar);
        }
    }

    public boolean B1(boolean z10) {
        return this.N0.f(z10);
    }

    public boolean C1(boolean z10) {
        return this.N0.g(z10);
    }

    public boolean D1(boolean z10, int i10) {
        return this.N0.h(z10, i10);
    }

    public b.InterfaceC0509b E1() {
        return this.P0;
    }

    public int F1() {
        return this.f22392f1;
    }

    public f3.d G1() {
        return this.R0;
    }

    public void H1() {
        this.N0.j();
    }

    public void I1() {
        this.N0.k();
    }

    public boolean J1() {
        return this.f22395i1;
    }

    public boolean K1() {
        return this.Q0;
    }

    public boolean L1() {
        return this.f22394h1;
    }

    @Override // i3.e
    public void M(StringBuilder sb2) {
        sb2.append(this.f22361o + ":{\n");
        sb2.append("  actualWidth:" + this.f22336b0);
        sb2.append("\n");
        sb2.append("  actualHeight:" + this.f22338c0);
        sb2.append("\n");
        Iterator it = n1().iterator();
        while (it.hasNext()) {
            ((e) it.next()).M(sb2);
            sb2.append(",\n");
        }
        sb2.append("}");
    }

    public long M1(int i10, int i11, int i12, int i13, int i14, int i15, int i16, int i17, int i18) {
        this.S0 = i17;
        this.T0 = i18;
        return this.M0.d(this, i10, i17, i18, i11, i12, i13, i14, i15, i16);
    }

    public boolean O1(int i10) {
        return (this.f22392f1 & i10) == i10;
    }

    public void Q1(b.InterfaceC0509b interfaceC0509b) {
        this.P0 = interfaceC0509b;
        this.N0.n(interfaceC0509b);
    }

    public void R1(int i10) {
        this.f22392f1 = i10;
        f3.d.f17571r = O1(512);
    }

    public void S1(int i10) {
        this.O0 = i10;
    }

    public void T1(boolean z10) {
        this.Q0 = z10;
    }

    public boolean U1(f3.d dVar, boolean[] zArr) {
        zArr[2] = false;
        boolean O1 = O1(64);
        m1(dVar, O1);
        int size = this.L0.size();
        boolean z10 = false;
        for (int i10 = 0; i10 < size; i10++) {
            e eVar = (e) this.L0.get(i10);
            eVar.m1(dVar, O1);
            if (eVar.a0()) {
                z10 = true;
            }
        }
        return z10;
    }

    public void V1() {
        this.M0.e(this);
    }

    @Override // i3.e
    public void l1(boolean z10, boolean z11) {
        super.l1(z10, z11);
        int size = this.L0.size();
        for (int i10 = 0; i10 < size; i10++) {
            ((e) this.L0.get(i10)).l1(z10, z11);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:149:0x030c  */
    /* JADX WARN: Removed duplicated region for block: B:152:0x030e  */
    /* JADX WARN: Type inference failed for: r6v3 */
    /* JADX WARN: Type inference failed for: r6v4, types: [boolean] */
    /* JADX WARN: Type inference failed for: r6v6 */
    @Override // i3.k
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void o1() {
        int i10;
        int i11;
        boolean z10;
        boolean z11;
        boolean z12;
        ?? r62;
        boolean z13;
        boolean z14;
        int i12;
        e.b bVar;
        int i13 = 0;
        this.f22344f0 = 0;
        this.f22346g0 = 0;
        this.f22394h1 = false;
        this.f22395i1 = false;
        int size = this.L0.size();
        int max = Math.max(0, U());
        int max2 = Math.max(0, v());
        e.b[] bVarArr = this.Z;
        e.b bVar2 = bVarArr[1];
        e.b bVar3 = bVarArr[0];
        if (this.O0 == 0 && j.b(this.f22392f1, 1)) {
            j3.h.h(this, E1());
            for (int i14 = 0; i14 < size; i14++) {
                e eVar = (e) this.L0.get(i14);
                if (eVar.k0() && !(eVar instanceof g) && !(eVar instanceof a) && !eVar.j0()) {
                    e.b s10 = eVar.s(0);
                    e.b s11 = eVar.s(1);
                    e.b bVar4 = e.b.MATCH_CONSTRAINT;
                    if (!(s10 == bVar4 && eVar.f22377w != 1 && s11 == bVar4 && eVar.f22379x != 1)) {
                        N1(0, eVar, this.P0, new b.a(), b.a.f23881k);
                    }
                }
            }
        }
        if (size <= 2 || !((bVar3 == (bVar = e.b.WRAP_CONTENT) || bVar2 == bVar) && j.b(this.f22392f1, UserMetadata.MAX_ATTRIBUTE_SIZE) && j3.i.c(this, E1()))) {
            i10 = max2;
            i11 = max;
            z10 = false;
        } else {
            if (bVar3 == bVar) {
                if (max >= U() || max <= 0) {
                    max = U();
                } else {
                    g1(max);
                    this.f22394h1 = true;
                }
            }
            if (bVar2 == bVar) {
                if (max2 >= v() || max2 <= 0) {
                    max2 = v();
                } else {
                    I0(max2);
                    this.f22395i1 = true;
                }
            }
            i10 = max2;
            i11 = max;
            z10 = true;
        }
        boolean z15 = O1(64) || O1(128);
        f3.d dVar = this.R0;
        dVar.f17586h = false;
        dVar.f17587i = false;
        if (this.f22392f1 != 0 && z15) {
            dVar.f17587i = true;
        }
        ArrayList arrayList = this.L0;
        e.b y10 = y();
        e.b bVar5 = e.b.WRAP_CONTENT;
        boolean z16 = y10 == bVar5 || R() == bVar5;
        P1();
        for (int i15 = 0; i15 < size; i15++) {
            e eVar2 = (e) this.L0.get(i15);
            if (eVar2 instanceof k) {
                ((k) eVar2).o1();
            }
        }
        boolean O1 = O1(64);
        boolean z17 = z10;
        int i16 = 0;
        boolean z18 = true;
        while (z18) {
            int i17 = i16 + 1;
            try {
                this.R0.D();
                P1();
                k(this.R0);
                for (int i18 = i13; i18 < size; i18++) {
                    ((e) this.L0.get(i18)).k(this.R0);
                }
                z18 = s1(this.R0);
                WeakReference weakReference = this.f22397k1;
                if (weakReference != null && weakReference.get() != null) {
                    x1((d) this.f22397k1.get(), this.R0.q(this.P));
                    this.f22397k1 = null;
                }
                WeakReference weakReference2 = this.f22399m1;
                if (weakReference2 != null && weakReference2.get() != null) {
                    w1((d) this.f22399m1.get(), this.R0.q(this.R));
                    this.f22399m1 = null;
                }
                WeakReference weakReference3 = this.f22398l1;
                if (weakReference3 != null && weakReference3.get() != null) {
                    x1((d) this.f22398l1.get(), this.R0.q(this.O));
                    this.f22398l1 = null;
                }
                WeakReference weakReference4 = this.f22400n1;
                if (weakReference4 != null && weakReference4.get() != null) {
                    w1((d) this.f22400n1.get(), this.R0.q(this.Q));
                    this.f22400n1 = null;
                }
                if (z18) {
                    this.R0.z();
                }
            } catch (Exception e10) {
                e10.printStackTrace();
                System.out.println("EXCEPTION : " + e10);
            }
            if (z18) {
                z11 = U1(this.R0, j.f22404a);
            } else {
                m1(this.R0, O1);
                for (int i19 = 0; i19 < size; i19++) {
                    ((e) this.L0.get(i19)).m1(this.R0, O1);
                }
                z11 = false;
            }
            if (z16 && i17 < 8 && j.f22404a[2]) {
                int i20 = 0;
                int i21 = 0;
                int i22 = 0;
                while (i20 < size) {
                    e eVar3 = (e) this.L0.get(i20);
                    i22 = Math.max(i22, eVar3.f22344f0 + eVar3.U());
                    i21 = Math.max(i21, eVar3.f22346g0 + eVar3.v());
                    i20++;
                    z11 = z11;
                }
                z12 = z11;
                int max3 = Math.max(this.f22358m0, i22);
                int max4 = Math.max(this.f22360n0, i21);
                e.b bVar6 = e.b.WRAP_CONTENT;
                if (bVar3 == bVar6 && U() < max3) {
                    g1(max3);
                    this.Z[0] = bVar6;
                    z17 = true;
                    z12 = true;
                }
                if (bVar2 == bVar6 && v() < max4) {
                    I0(max4);
                    this.Z[1] = bVar6;
                    z17 = true;
                    z12 = true;
                }
            } else {
                z12 = z11;
            }
            int max5 = Math.max(this.f22358m0, U());
            if (max5 > U()) {
                g1(max5);
                this.Z[0] = e.b.FIXED;
                z17 = true;
                z12 = true;
            }
            int max6 = Math.max(this.f22360n0, v());
            if (max6 > v()) {
                I0(max6);
                r62 = 1;
                this.Z[1] = e.b.FIXED;
                z13 = true;
                z12 = true;
            } else {
                r62 = 1;
                z13 = z17;
            }
            if (!z13) {
                e.b bVar7 = this.Z[0];
                e.b bVar8 = e.b.WRAP_CONTENT;
                if (bVar7 == bVar8 && i11 > 0 && U() > i11) {
                    this.f22394h1 = r62;
                    this.Z[0] = e.b.FIXED;
                    g1(i11);
                    z13 = r62;
                    z12 = z13;
                }
                if (this.Z[r62] == bVar8 && i10 > 0 && v() > i10) {
                    this.f22395i1 = r62;
                    this.Z[r62] = e.b.FIXED;
                    I0(i10);
                    i12 = 8;
                    z14 = true;
                    z17 = true;
                    z18 = i17 <= i12 ? false : z14;
                    i16 = i17;
                    i13 = 0;
                }
            }
            z17 = z13;
            z14 = z12;
            i12 = 8;
            if (i17 <= i12) {
            }
            i16 = i17;
            i13 = 0;
        }
        this.L0 = arrayList;
        if (z17) {
            e.b[] bVarArr2 = this.Z;
            bVarArr2[0] = bVar3;
            bVarArr2[1] = bVar2;
        }
        t0(this.R0.v());
    }

    @Override // i3.k, i3.e
    public void r0() {
        this.R0.D();
        this.S0 = 0;
        this.U0 = 0;
        this.T0 = 0;
        this.V0 = 0;
        this.f22393g1 = false;
        super.r0();
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void r1(e eVar, int i10) {
        if (i10 == 0) {
            t1(eVar);
        } else if (i10 == 1) {
            y1(eVar);
        }
    }

    public boolean s1(f3.d dVar) {
        boolean O1 = O1(64);
        g(dVar, O1);
        int size = this.L0.size();
        boolean z10 = false;
        for (int i10 = 0; i10 < size; i10++) {
            e eVar = (e) this.L0.get(i10);
            eVar.P0(0, false);
            eVar.P0(1, false);
            if (eVar instanceof a) {
                z10 = true;
            }
        }
        if (z10) {
            for (int i11 = 0; i11 < size; i11++) {
                e eVar2 = (e) this.L0.get(i11);
                if (eVar2 instanceof a) {
                    ((a) eVar2).u1();
                }
            }
        }
        this.f22401o1.clear();
        for (int i12 = 0; i12 < size; i12++) {
            e eVar3 = (e) this.L0.get(i12);
            if (eVar3.f()) {
                eVar3.g(dVar, O1);
            }
        }
        while (this.f22401o1.size() > 0) {
            int size2 = this.f22401o1.size();
            Iterator it = this.f22401o1.iterator();
            if (it.hasNext()) {
                android.support.v4.media.session.b.a((e) it.next());
                throw null;
            }
            if (size2 == this.f22401o1.size()) {
                Iterator it2 = this.f22401o1.iterator();
                while (it2.hasNext()) {
                    ((e) it2.next()).g(dVar, O1);
                }
                this.f22401o1.clear();
            }
        }
        if (f3.d.f17571r) {
            HashSet hashSet = new HashSet();
            for (int i13 = 0; i13 < size; i13++) {
                e eVar4 = (e) this.L0.get(i13);
                if (!eVar4.f()) {
                    hashSet.add(eVar4);
                }
            }
            e(this, dVar, hashSet, y() == e.b.WRAP_CONTENT ? 0 : 1, false);
            Iterator it3 = hashSet.iterator();
            while (it3.hasNext()) {
                e eVar5 = (e) it3.next();
                j.a(this, dVar, eVar5);
                eVar5.g(dVar, O1);
            }
        } else {
            for (int i14 = 0; i14 < size; i14++) {
                e eVar6 = (e) this.L0.get(i14);
                if (eVar6 instanceof f) {
                    e.b[] bVarArr = eVar6.Z;
                    e.b bVar = bVarArr[0];
                    e.b bVar2 = bVarArr[1];
                    e.b bVar3 = e.b.WRAP_CONTENT;
                    if (bVar == bVar3) {
                        eVar6.M0(e.b.FIXED);
                    }
                    if (bVar2 == bVar3) {
                        eVar6.c1(e.b.FIXED);
                    }
                    eVar6.g(dVar, O1);
                    if (bVar == bVar3) {
                        eVar6.M0(bVar);
                    }
                    if (bVar2 == bVar3) {
                        eVar6.c1(bVar2);
                    }
                } else {
                    j.a(this, dVar, eVar6);
                    if (!eVar6.f()) {
                        eVar6.g(dVar, O1);
                    }
                }
            }
        }
        if (this.W0 > 0) {
            b.b(this, dVar, null, 0);
        }
        if (this.X0 > 0) {
            b.b(this, dVar, null, 1);
        }
        return true;
    }

    public void u1(d dVar) {
        WeakReference weakReference = this.f22400n1;
        if (weakReference == null || weakReference.get() == null || dVar.d() > ((d) this.f22400n1.get()).d()) {
            this.f22400n1 = new WeakReference(dVar);
        }
    }

    public void v1(d dVar) {
        WeakReference weakReference = this.f22398l1;
        if (weakReference == null || weakReference.get() == null || dVar.d() > ((d) this.f22398l1.get()).d()) {
            this.f22398l1 = new WeakReference(dVar);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void z1(d dVar) {
        WeakReference weakReference = this.f22399m1;
        if (weakReference == null || weakReference.get() == null || dVar.d() > ((d) this.f22399m1.get()).d()) {
            this.f22399m1 = new WeakReference(dVar);
        }
    }
}
