package j2;

import j2.g0;
import j2.j1;

/* loaded from: classes.dex */
public final class r0 {

    /* renamed from: a */
    private final g0 f23774a;

    /* renamed from: b */
    private final o f23775b;

    /* renamed from: c */
    private boolean f23776c;

    /* renamed from: d */
    private boolean f23777d;

    /* renamed from: e */
    private final h1 f23778e;

    /* renamed from: f */
    private final a1.b f23779f;

    /* renamed from: g */
    private long f23780g;

    /* renamed from: h */
    private final a1.b f23781h;

    /* renamed from: i */
    private c3.b f23782i;

    /* renamed from: j */
    private final n0 f23783j;

    /* loaded from: classes.dex */
    public static final class a {

        /* renamed from: a */
        private final g0 f23784a;

        /* renamed from: b */
        private final boolean f23785b;

        /* renamed from: c */
        private final boolean f23786c;

        public a(g0 g0Var, boolean z10, boolean z11) {
            this.f23784a = g0Var;
            this.f23785b = z10;
            this.f23786c = z11;
        }

        public final g0 a() {
            return this.f23784a;
        }

        public final boolean b() {
            return this.f23786c;
        }

        public final boolean c() {
            return this.f23785b;
        }
    }

    /* loaded from: classes.dex */
    public /* synthetic */ class b {

        /* renamed from: a */
        public static final /* synthetic */ int[] f23787a;

        static {
            int[] iArr = new int[g0.e.values().length];
            try {
                iArr[g0.e.LookaheadMeasuring.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[g0.e.Measuring.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[g0.e.LookaheadLayingOut.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                iArr[g0.e.LayingOut.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                iArr[g0.e.Idle.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            f23787a = iArr;
        }
    }

    public r0(g0 g0Var) {
        this.f23774a = g0Var;
        j1.a aVar = j1.f23670e;
        o oVar = new o(aVar.a());
        this.f23775b = oVar;
        this.f23778e = new h1();
        this.f23779f = new a1.b(new j1.b[16], 0);
        this.f23780g = 1L;
        a1.b bVar = new a1.b(new a[16], 0);
        this.f23781h = bVar;
        this.f23783j = aVar.a() ? new n0(g0Var, oVar, bVar.j()) : null;
    }

    private final void A(g0 g0Var, boolean z10) {
        c3.b bVar;
        if (g0Var.L0()) {
            return;
        }
        if (g0Var == this.f23774a) {
            bVar = this.f23782i;
            kotlin.jvm.internal.t.d(bVar);
        } else {
            bVar = null;
        }
        if (z10) {
            e(g0Var, bVar);
        } else {
            f(g0Var, bVar);
        }
    }

    public static /* synthetic */ boolean G(r0 r0Var, g0 g0Var, boolean z10, int i10, Object obj) {
        if ((i10 & 2) != 0) {
            z10 = false;
        }
        return r0Var.F(g0Var, z10);
    }

    private final void b() {
        a1.b bVar = this.f23779f;
        int q10 = bVar.q();
        if (q10 > 0) {
            Object[] p10 = bVar.p();
            int i10 = 0;
            do {
                ((j1.b) p10[i10]).b();
                i10++;
            } while (i10 < q10);
        }
        this.f23779f.k();
    }

    public static /* synthetic */ void d(r0 r0Var, boolean z10, int i10, Object obj) {
        if ((i10 & 1) != 0) {
            z10 = false;
        }
        r0Var.c(z10);
    }

    private final boolean e(g0 g0Var, c3.b bVar) {
        if (g0Var.b0() == null) {
            return false;
        }
        boolean P0 = bVar != null ? g0Var.P0(bVar) : g0.Q0(g0Var, null, 1, null);
        g0 o02 = g0Var.o0();
        if (P0 && o02 != null) {
            if (o02.b0() == null) {
                g0.w1(o02, false, false, false, 3, null);
            } else if (g0Var.h0() == g0.g.InMeasureBlock) {
                g0.s1(o02, false, false, false, 3, null);
            } else if (g0Var.h0() == g0.g.InLayoutBlock) {
                g0.q1(o02, false, 1, null);
            }
        }
        return P0;
    }

    private final boolean f(g0 g0Var, c3.b bVar) {
        boolean k12 = bVar != null ? g0Var.k1(bVar) : g0.l1(g0Var, null, 1, null);
        g0 o02 = g0Var.o0();
        if (k12 && o02 != null) {
            if (g0Var.g0() == g0.g.InMeasureBlock) {
                g0.w1(o02, false, false, false, 3, null);
            } else if (g0Var.g0() == g0.g.InLayoutBlock) {
                g0.u1(o02, false, 1, null);
            }
        }
        return k12;
    }

    private final void g() {
        if (this.f23781h.t()) {
            a1.b bVar = this.f23781h;
            int q10 = bVar.q();
            if (q10 > 0) {
                Object[] p10 = bVar.p();
                int i10 = 0;
                do {
                    a aVar = (a) p10[i10];
                    if (aVar.a().K0()) {
                        if (aVar.c()) {
                            g0.s1(aVar.a(), aVar.b(), false, false, 2, null);
                        } else {
                            g0.w1(aVar.a(), aVar.b(), false, false, 2, null);
                        }
                    }
                    i10++;
                } while (i10 < q10);
            }
            this.f23781h.k();
        }
    }

    private final void h(g0 g0Var) {
        a1.b w02 = g0Var.w0();
        int q10 = w02.q();
        if (q10 > 0) {
            Object[] p10 = w02.p();
            int i10 = 0;
            do {
                g0 g0Var2 = (g0) p10[i10];
                if (kotlin.jvm.internal.t.b(g0Var2.N0(), Boolean.TRUE) && !g0Var2.L0()) {
                    if (this.f23775b.e(g0Var2, true)) {
                        g0Var2.R0();
                    }
                    h(g0Var2);
                }
                i10++;
            } while (i10 < q10);
        }
    }

    private final void j(g0 g0Var, boolean z10) {
        a1.b w02 = g0Var.w0();
        int q10 = w02.q();
        if (q10 > 0) {
            Object[] p10 = w02.p();
            int i10 = 0;
            do {
                g0 g0Var2 = (g0) p10[i10];
                if ((!z10 && o(g0Var2)) || (z10 && p(g0Var2))) {
                    if (m0.a(g0Var2) && !z10) {
                        if (g0Var2.Z() && this.f23775b.e(g0Var2, true)) {
                            x(g0Var2, true, false);
                        } else {
                            i(g0Var2, true);
                        }
                    }
                    w(g0Var2, z10);
                    if (!u(g0Var2, z10)) {
                        j(g0Var2, z10);
                    }
                }
                i10++;
            } while (i10 < q10);
        }
        w(g0Var, z10);
    }

    private final boolean k(g0 g0Var) {
        return g0Var.e0() && o(g0Var);
    }

    private final boolean l(g0 g0Var) {
        return g0Var.Z() && p(g0Var);
    }

    private final boolean o(g0 g0Var) {
        return g0Var.g0() == g0.g.InMeasureBlock || g0Var.U().r().h().k();
    }

    private final boolean p(g0 g0Var) {
        j2.a h10;
        if (g0Var.h0() == g0.g.InMeasureBlock) {
            return true;
        }
        j2.b C = g0Var.U().C();
        return C != null && (h10 = C.h()) != null && h10.k();
    }

    private final boolean u(g0 g0Var, boolean z10) {
        return z10 ? g0Var.Z() : g0Var.e0();
    }

    private final void w(g0 g0Var, boolean z10) {
        if (u(g0Var, z10) && this.f23775b.e(g0Var, z10)) {
            x(g0Var, z10, false);
        }
    }

    private final boolean x(g0 g0Var, boolean z10, boolean z11) {
        c3.b bVar;
        if (g0Var.L0()) {
            return false;
        }
        if (g0Var.q() || g0Var.M0() || k(g0Var) || kotlin.jvm.internal.t.b(g0Var.N0(), Boolean.TRUE) || l(g0Var) || g0Var.C()) {
            if (g0Var == this.f23774a) {
                bVar = this.f23782i;
                kotlin.jvm.internal.t.d(bVar);
            } else {
                bVar = null;
            }
            if (z10) {
                r1 = g0Var.Z() ? e(g0Var, bVar) : false;
                if (z11 && ((r1 || g0Var.Y()) && kotlin.jvm.internal.t.b(g0Var.N0(), Boolean.TRUE))) {
                    g0Var.R0();
                }
            } else {
                boolean f10 = g0Var.e0() ? f(g0Var, bVar) : false;
                if (z11 && g0Var.V()) {
                    boolean z12 = true;
                    if (g0Var != this.f23774a) {
                        g0 o02 = g0Var.o0();
                        if (!(o02 != null && o02.q()) || !g0Var.M0()) {
                            z12 = false;
                        }
                    }
                    if (z12) {
                        if (g0Var == this.f23774a) {
                            g0Var.i1(0, 0);
                        } else {
                            g0Var.o1();
                        }
                        this.f23778e.d(g0Var);
                        n0 n0Var = this.f23783j;
                        if (n0Var != null) {
                            n0Var.a();
                        }
                    }
                }
                r1 = f10;
            }
            g();
        }
        return r1;
    }

    static /* synthetic */ boolean y(r0 r0Var, g0 g0Var, boolean z10, boolean z11, int i10, Object obj) {
        if ((i10 & 2) != 0) {
            z10 = true;
        }
        if ((i10 & 4) != 0) {
            z11 = true;
        }
        return r0Var.x(g0Var, z10, z11);
    }

    private final void z(g0 g0Var) {
        a1.b w02 = g0Var.w0();
        int q10 = w02.q();
        if (q10 > 0) {
            Object[] p10 = w02.p();
            int i10 = 0;
            do {
                g0 g0Var2 = (g0) p10[i10];
                if (o(g0Var2)) {
                    if (m0.a(g0Var2)) {
                        A(g0Var2, true);
                    } else {
                        z(g0Var2);
                    }
                }
                i10++;
            } while (i10 < q10);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:35:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean B(g0 g0Var, boolean z10) {
        int i10 = b.f23787a[g0Var.X().ordinal()];
        if (i10 != 1) {
            if (i10 != 2) {
                if (i10 != 3) {
                    if (i10 != 4 && i10 != 5) {
                        throw new rm.t();
                    }
                }
            }
            if ((g0Var.Z() || g0Var.Y()) && !z10) {
                n0 n0Var = this.f23783j;
                if (n0Var != null) {
                    n0Var.a();
                }
            } else {
                g0Var.T0();
                g0Var.S0();
                if (!g0Var.L0()) {
                    g0 o02 = g0Var.o0();
                    if (kotlin.jvm.internal.t.b(g0Var.N0(), Boolean.TRUE)) {
                        if (!(o02 != null && o02.Z())) {
                            if (!(o02 != null && o02.Y())) {
                                this.f23775b.c(g0Var, true);
                                if (!this.f23777d) {
                                    return true;
                                }
                            }
                        }
                    }
                    if (g0Var.q()) {
                        if (!(o02 != null && o02.V())) {
                            if (!(o02 != null && o02.e0())) {
                                this.f23775b.c(g0Var, false);
                            }
                        }
                    }
                    if (!this.f23777d) {
                    }
                }
            }
            return false;
        }
        n0 n0Var2 = this.f23783j;
        if (n0Var2 != null) {
            n0Var2.a();
        }
        return false;
    }

    /* JADX WARN: Removed duplicated region for block: B:31:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean C(g0 g0Var, boolean z10) {
        if (!(g0Var.b0() != null)) {
            g2.a.b("Error: requestLookaheadRemeasure cannot be called on a node outside LookaheadScope");
        }
        int i10 = b.f23787a[g0Var.X().ordinal()];
        if (i10 != 1) {
            if (i10 == 2 || i10 == 3 || i10 == 4) {
                this.f23781h.c(new a(g0Var, true, z10));
                n0 n0Var = this.f23783j;
                if (n0Var != null) {
                    n0Var.a();
                }
            } else {
                if (i10 != 5) {
                    throw new rm.t();
                }
                if (!g0Var.Z() || z10) {
                    g0Var.U0();
                    g0Var.V0();
                    if (!g0Var.L0()) {
                        if (kotlin.jvm.internal.t.b(g0Var.N0(), Boolean.TRUE) || l(g0Var)) {
                            g0 o02 = g0Var.o0();
                            if (!(o02 != null && o02.Z())) {
                                this.f23775b.c(g0Var, true);
                                if (!this.f23777d) {
                                    return true;
                                }
                            }
                        }
                        if (g0Var.q() || k(g0Var)) {
                            g0 o03 = g0Var.o0();
                            if (!(o03 != null && o03.e0())) {
                                this.f23775b.c(g0Var, false);
                            }
                        }
                        if (!this.f23777d) {
                        }
                    }
                }
            }
        }
        return false;
    }

    public final void D(g0 g0Var) {
        this.f23778e.d(g0Var);
    }

    public final boolean E(g0 g0Var, boolean z10) {
        int i10 = b.f23787a[g0Var.X().ordinal()];
        if (i10 == 1 || i10 == 2 || i10 == 3 || i10 == 4) {
            n0 n0Var = this.f23783j;
            if (n0Var != null) {
                n0Var.a();
            }
        } else {
            if (i10 != 5) {
                throw new rm.t();
            }
            if (!z10 && g0Var.q() == g0Var.M0() && (g0Var.e0() || g0Var.V())) {
                n0 n0Var2 = this.f23783j;
                if (n0Var2 != null) {
                    n0Var2.a();
                }
            } else {
                g0Var.S0();
                if (!g0Var.L0() && g0Var.M0()) {
                    g0 o02 = g0Var.o0();
                    if (!(o02 != null && o02.V())) {
                        if (!(o02 != null && o02.e0())) {
                            this.f23775b.c(g0Var, false);
                        }
                    }
                    if (!this.f23777d) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    public final boolean F(g0 g0Var, boolean z10) {
        int i10 = b.f23787a[g0Var.X().ordinal()];
        if (i10 != 1 && i10 != 2) {
            if (i10 == 3 || i10 == 4) {
                this.f23781h.c(new a(g0Var, false, z10));
                n0 n0Var = this.f23783j;
                if (n0Var != null) {
                    n0Var.a();
                }
            } else {
                if (i10 != 5) {
                    throw new rm.t();
                }
                if (!g0Var.e0() || z10) {
                    g0Var.V0();
                    if (!g0Var.L0() && (g0Var.q() || k(g0Var))) {
                        g0 o02 = g0Var.o0();
                        if (!(o02 != null && o02.e0())) {
                            this.f23775b.c(g0Var, false);
                        }
                        if (!this.f23777d) {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }

    public final void H(long j10) {
        c3.b bVar = this.f23782i;
        if (bVar == null ? false : c3.b.f(bVar.r(), j10)) {
            return;
        }
        if (!(!this.f23776c)) {
            g2.a.a("updateRootConstraints called while measuring");
        }
        this.f23782i = c3.b.a(j10);
        if (this.f23774a.b0() != null) {
            this.f23774a.U0();
        }
        this.f23774a.V0();
        o oVar = this.f23775b;
        g0 g0Var = this.f23774a;
        oVar.c(g0Var, g0Var.b0() != null);
    }

    public final void c(boolean z10) {
        if (z10) {
            this.f23778e.e(this.f23774a);
        }
        this.f23778e.a();
    }

    public final void i(g0 g0Var, boolean z10) {
        if (this.f23775b.g(z10)) {
            return;
        }
        if (!this.f23776c) {
            g2.a.b("forceMeasureTheSubtree should be executed during the measureAndLayout pass");
        }
        if (!(!u(g0Var, z10))) {
            g2.a.a("node not yet measured");
        }
        j(g0Var, z10);
    }

    public final boolean m() {
        return this.f23775b.h();
    }

    public final boolean n() {
        return this.f23778e.c();
    }

    public final long q() {
        if (!this.f23776c) {
            g2.a.a("measureIteration should be only used during the measure/layout pass");
        }
        return this.f23780g;
    }

    public final boolean r(dn.a aVar) {
        boolean z10;
        n nVar;
        if (!this.f23774a.K0()) {
            g2.a.a("performMeasureAndLayout called with unattached root");
        }
        if (!this.f23774a.q()) {
            g2.a.a("performMeasureAndLayout called with unplaced root");
        }
        if (!(!this.f23776c)) {
            g2.a.a("performMeasureAndLayout called during measure layout");
        }
        boolean z11 = false;
        if (this.f23782i != null) {
            this.f23776c = true;
            this.f23777d = true;
            try {
                if (this.f23775b.h()) {
                    o oVar = this.f23775b;
                    z10 = false;
                    while (oVar.h()) {
                        nVar = oVar.f23754a;
                        boolean z12 = !nVar.d();
                        g0 e10 = (z12 ? oVar.f23754a : oVar.f23755b).e();
                        boolean y10 = y(this, e10, z12, false, 4, null);
                        if (e10 == this.f23774a && y10) {
                            z10 = true;
                        }
                    }
                    if (aVar != null) {
                        aVar.invoke();
                    }
                } else {
                    z10 = false;
                }
                this.f23776c = false;
                this.f23777d = false;
                n0 n0Var = this.f23783j;
                if (n0Var != null) {
                    n0Var.a();
                }
                z11 = z10;
            } catch (Throwable th2) {
                this.f23776c = false;
                this.f23777d = false;
                throw th2;
            }
        }
        b();
        return z11;
    }

    public final void s(g0 g0Var, long j10) {
        if (g0Var.L0()) {
            return;
        }
        if (!(!kotlin.jvm.internal.t.b(g0Var, this.f23774a))) {
            g2.a.a("measureAndLayout called on root");
        }
        if (!this.f23774a.K0()) {
            g2.a.a("performMeasureAndLayout called with unattached root");
        }
        if (!this.f23774a.q()) {
            g2.a.a("performMeasureAndLayout called with unplaced root");
        }
        if (!(!this.f23776c)) {
            g2.a.a("performMeasureAndLayout called during measure layout");
        }
        if (this.f23782i != null) {
            this.f23776c = true;
            this.f23777d = false;
            try {
                this.f23775b.i(g0Var);
                if ((e(g0Var, c3.b.a(j10)) || g0Var.Y()) && kotlin.jvm.internal.t.b(g0Var.N0(), Boolean.TRUE)) {
                    g0Var.R0();
                }
                h(g0Var);
                f(g0Var, c3.b.a(j10));
                if (g0Var.V() && g0Var.q()) {
                    g0Var.o1();
                    this.f23778e.d(g0Var);
                }
                g();
                this.f23776c = false;
                this.f23777d = false;
                n0 n0Var = this.f23783j;
                if (n0Var != null) {
                    n0Var.a();
                }
            } catch (Throwable th2) {
                this.f23776c = false;
                this.f23777d = false;
                throw th2;
            }
        }
        b();
    }

    public final void t() {
        if (this.f23775b.h()) {
            if (!this.f23774a.K0()) {
                g2.a.a("performMeasureAndLayout called with unattached root");
            }
            if (!this.f23774a.q()) {
                g2.a.a("performMeasureAndLayout called with unplaced root");
            }
            if (!(!this.f23776c)) {
                g2.a.a("performMeasureAndLayout called during measure layout");
            }
            if (this.f23782i != null) {
                this.f23776c = true;
                this.f23777d = false;
                try {
                    if (!this.f23775b.g(true)) {
                        if (this.f23774a.b0() != null) {
                            A(this.f23774a, true);
                        } else {
                            z(this.f23774a);
                        }
                    }
                    A(this.f23774a, false);
                    this.f23776c = false;
                    this.f23777d = false;
                    n0 n0Var = this.f23783j;
                    if (n0Var != null) {
                        n0Var.a();
                    }
                } catch (Throwable th2) {
                    this.f23776c = false;
                    this.f23777d = false;
                    throw th2;
                }
            }
        }
    }

    public final void v(g0 g0Var) {
        this.f23775b.i(g0Var);
        this.f23778e.f(g0Var);
    }
}
