package j2;

import j2.y0;
import l1.i;

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

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

    /* renamed from: b */
    private final w f23813b;

    /* renamed from: c */
    private z0 f23814c;

    /* renamed from: d */
    private final i.c f23815d;

    /* renamed from: e */
    private i.c f23816e;

    /* renamed from: f */
    private a1.b f23817f;

    /* renamed from: g */
    private a1.b f23818g;

    /* renamed from: h */
    private a f23819h;

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

        /* renamed from: a */
        private i.c f23820a;

        /* renamed from: b */
        private int f23821b;

        /* renamed from: c */
        private a1.b f23822c;

        /* renamed from: d */
        private a1.b f23823d;

        /* renamed from: e */
        private boolean f23824e;

        public a(i.c cVar, int i10, a1.b bVar, a1.b bVar2, boolean z10) {
            this.f23820a = cVar;
            this.f23821b = i10;
            this.f23822c = bVar;
            this.f23823d = bVar2;
            this.f23824e = z10;
        }

        @Override // j2.p
        public void a(int i10, int i11) {
            i.c F1 = this.f23820a.F1();
            kotlin.jvm.internal.t.d(F1);
            x0.d(x0.this);
            if ((b1.a(2) & F1.J1()) != 0) {
                z0 G1 = F1.G1();
                kotlin.jvm.internal.t.d(G1);
                z0 B2 = G1.B2();
                z0 A2 = G1.A2();
                kotlin.jvm.internal.t.d(A2);
                if (B2 != null) {
                    B2.e3(A2);
                }
                A2.f3(B2);
                x0.this.v(this.f23820a, A2);
            }
            this.f23820a = x0.this.h(F1);
        }

        @Override // j2.p
        public boolean b(int i10, int i11) {
            return y0.d((i.b) this.f23822c.p()[this.f23821b + i10], (i.b) this.f23823d.p()[this.f23821b + i11]) != 0;
        }

        @Override // j2.p
        public void c(int i10, int i11) {
            i.c F1 = this.f23820a.F1();
            kotlin.jvm.internal.t.d(F1);
            this.f23820a = F1;
            a1.b bVar = this.f23822c;
            i.b bVar2 = (i.b) bVar.p()[this.f23821b + i10];
            a1.b bVar3 = this.f23823d;
            i.b bVar4 = (i.b) bVar3.p()[this.f23821b + i11];
            if (kotlin.jvm.internal.t.b(bVar2, bVar4)) {
                x0.d(x0.this);
            } else {
                x0.this.F(bVar2, bVar4, this.f23820a);
                x0.d(x0.this);
            }
        }

        @Override // j2.p
        public void d(int i10) {
            int i11 = this.f23821b + i10;
            this.f23820a = x0.this.g((i.b) this.f23823d.p()[i11], this.f23820a);
            x0.d(x0.this);
            if (!this.f23824e) {
                this.f23820a.a2(true);
                return;
            }
            i.c F1 = this.f23820a.F1();
            kotlin.jvm.internal.t.d(F1);
            z0 G1 = F1.G1();
            kotlin.jvm.internal.t.d(G1);
            b0 d10 = k.d(this.f23820a);
            if (d10 != null) {
                c0 c0Var = new c0(x0.this.m(), d10);
                this.f23820a.g2(c0Var);
                x0.this.v(this.f23820a, c0Var);
                c0Var.f3(G1.B2());
                c0Var.e3(G1);
                G1.f3(c0Var);
            } else {
                this.f23820a.g2(G1);
            }
            this.f23820a.P1();
            this.f23820a.V1();
            c1.a(this.f23820a);
        }

        public final void e(a1.b bVar) {
            this.f23823d = bVar;
        }

        public final void f(a1.b bVar) {
            this.f23822c = bVar;
        }

        public final void g(i.c cVar) {
            this.f23820a = cVar;
        }

        public final void h(int i10) {
            this.f23821b = i10;
        }

        public final void i(boolean z10) {
            this.f23824e = z10;
        }
    }

    /* loaded from: classes.dex */
    public interface b {
    }

    public x0(g0 g0Var) {
        this.f23812a = g0Var;
        w wVar = new w(g0Var);
        this.f23813b = wVar;
        this.f23814c = wVar;
        v1 z22 = wVar.z2();
        this.f23815d = z22;
        this.f23816e = z22;
    }

    private final void A(int i10, a1.b bVar, a1.b bVar2, i.c cVar, boolean z10) {
        v0.e(bVar.q() - i10, bVar2.q() - i10, j(cVar, i10, bVar, bVar2, z10));
        B();
    }

    private final void B() {
        y0.a aVar;
        int i10 = 0;
        for (i.c L1 = this.f23815d.L1(); L1 != null; L1 = L1.L1()) {
            aVar = y0.f23828a;
            if (L1 == aVar) {
                return;
            }
            i10 |= L1.J1();
            L1.X1(i10);
        }
    }

    private final i.c D(i.c cVar) {
        y0.a aVar;
        y0.a aVar2;
        y0.a aVar3;
        y0.a aVar4;
        y0.a aVar5;
        y0.a aVar6;
        aVar = y0.f23828a;
        if (!(cVar == aVar)) {
            g2.a.b("trimChain called on already trimmed chain");
        }
        aVar2 = y0.f23828a;
        i.c F1 = aVar2.F1();
        if (F1 == null) {
            F1 = this.f23815d;
        }
        F1.d2(null);
        aVar3 = y0.f23828a;
        aVar3.Z1(null);
        aVar4 = y0.f23828a;
        aVar4.X1(-1);
        aVar5 = y0.f23828a;
        aVar5.g2(null);
        aVar6 = y0.f23828a;
        if (!(F1 != aVar6)) {
            g2.a.b("trimChain did not update the head");
        }
        return F1;
    }

    public final void F(i.b bVar, i.b bVar2, i.c cVar) {
        if ((bVar instanceof s0) && (bVar2 instanceof s0)) {
            y0.f((s0) bVar2, cVar);
            if (cVar.O1()) {
                c1.e(cVar);
                return;
            } else {
                cVar.e2(true);
                return;
            }
        }
        if (!(cVar instanceof c)) {
            throw new IllegalStateException("Unknown Modifier.Node type".toString());
        }
        ((c) cVar).l2(bVar2);
        if (cVar.O1()) {
            c1.e(cVar);
        } else {
            cVar.e2(true);
        }
    }

    public static final /* synthetic */ b d(x0 x0Var) {
        x0Var.getClass();
        return null;
    }

    public final i.c g(i.b bVar, i.c cVar) {
        i.c cVar2;
        if (bVar instanceof s0) {
            cVar2 = ((s0) bVar).c();
            cVar2.b2(c1.h(cVar2));
        } else {
            cVar2 = new c(bVar);
        }
        if (!(!cVar2.O1())) {
            g2.a.b("A ModifierNodeElement cannot return an already attached node from create() ");
        }
        cVar2.a2(true);
        return r(cVar2, cVar);
    }

    public final i.c h(i.c cVar) {
        if (cVar.O1()) {
            c1.d(cVar);
            cVar.W1();
            cVar.Q1();
        }
        return w(cVar);
    }

    public final int i() {
        return this.f23816e.E1();
    }

    private final a j(i.c cVar, int i10, a1.b bVar, a1.b bVar2, boolean z10) {
        a aVar = this.f23819h;
        if (aVar == null) {
            a aVar2 = new a(cVar, i10, bVar, bVar2, z10);
            this.f23819h = aVar2;
            return aVar2;
        }
        aVar.g(cVar);
        aVar.h(i10);
        aVar.f(bVar);
        aVar.e(bVar2);
        aVar.i(z10);
        return aVar;
    }

    private final i.c r(i.c cVar, i.c cVar2) {
        i.c F1 = cVar2.F1();
        if (F1 != null) {
            F1.d2(cVar);
            cVar.Z1(F1);
        }
        cVar2.Z1(cVar);
        cVar.d2(cVar2);
        return cVar;
    }

    private final i.c u() {
        y0.a aVar;
        y0.a aVar2;
        y0.a aVar3;
        y0.a aVar4;
        i.c cVar = this.f23816e;
        aVar = y0.f23828a;
        if (!(cVar != aVar)) {
            g2.a.b("padChain called on already padded chain");
        }
        i.c cVar2 = this.f23816e;
        aVar2 = y0.f23828a;
        cVar2.d2(aVar2);
        aVar3 = y0.f23828a;
        aVar3.Z1(cVar2);
        aVar4 = y0.f23828a;
        return aVar4;
    }

    public final void v(i.c cVar, z0 z0Var) {
        y0.a aVar;
        for (i.c L1 = cVar.L1(); L1 != null; L1 = L1.L1()) {
            aVar = y0.f23828a;
            if (L1 == aVar) {
                g0 o02 = this.f23812a.o0();
                z0Var.f3(o02 != null ? o02.P() : null);
                this.f23814c = z0Var;
                return;
            } else {
                if ((b1.a(2) & L1.J1()) != 0) {
                    return;
                }
                L1.g2(z0Var);
            }
        }
    }

    private final i.c w(i.c cVar) {
        i.c F1 = cVar.F1();
        i.c L1 = cVar.L1();
        if (F1 != null) {
            F1.d2(L1);
            cVar.Z1(null);
        }
        if (L1 != null) {
            L1.Z1(F1);
            cVar.d2(null);
        }
        kotlin.jvm.internal.t.d(L1);
        return L1;
    }

    public final void C() {
        z0 c0Var;
        z0 z0Var = this.f23813b;
        for (i.c L1 = this.f23815d.L1(); L1 != null; L1 = L1.L1()) {
            b0 d10 = k.d(L1);
            if (d10 != null) {
                if (L1.G1() != null) {
                    z0 G1 = L1.G1();
                    kotlin.jvm.internal.t.e(G1, "null cannot be cast to non-null type androidx.compose.ui.node.LayoutModifierNodeCoordinator");
                    c0Var = (c0) G1;
                    b0 u32 = c0Var.u3();
                    c0Var.x3(d10);
                    if (u32 != L1) {
                        c0Var.P2();
                    }
                } else {
                    c0Var = new c0(this.f23812a, d10);
                    L1.g2(c0Var);
                }
                z0Var.f3(c0Var);
                c0Var.e3(z0Var);
                z0Var = c0Var;
            } else {
                L1.g2(z0Var);
            }
        }
        g0 o02 = this.f23812a.o0();
        z0Var.f3(o02 != null ? o02.P() : null);
        this.f23814c = z0Var;
    }

    /* JADX WARN: Removed duplicated region for block: B:36:0x011a  */
    /* JADX WARN: Removed duplicated region for block: B:39:0x0128  */
    /* JADX WARN: Removed duplicated region for block: B:41:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void E(l1.i iVar) {
        a1.b e10;
        i.c u10 = u();
        a1.b bVar = this.f23817f;
        int i10 = 0;
        int q10 = bVar != null ? bVar.q() : 0;
        a1.b bVar2 = this.f23818g;
        if (bVar2 == null) {
            bVar2 = new a1.b(new i.b[16], 0);
        }
        e10 = y0.e(iVar, bVar2);
        a1.b bVar3 = null;
        if (e10.q() == q10) {
            i.c F1 = u10.F1();
            int i11 = 0;
            while (true) {
                if (F1 == null || i11 >= q10) {
                    break;
                }
                if (bVar == null) {
                    g2.a.c("expected prior modifier list to be non-empty");
                    throw new rm.k();
                }
                i.b bVar4 = (i.b) bVar.p()[i11];
                i.b bVar5 = (i.b) e10.p()[i11];
                int d10 = y0.d(bVar4, bVar5);
                if (d10 == 0) {
                    F1 = F1.L1();
                    break;
                }
                if (d10 == 1) {
                    F(bVar4, bVar5, F1);
                }
                F1 = F1.F1();
                i11++;
            }
            i.c cVar = F1;
            if (i11 < q10) {
                if (bVar == null) {
                    g2.a.c("expected prior modifier list to be non-empty");
                    throw new rm.k();
                }
                if (cVar == null) {
                    g2.a.c("structuralUpdate requires a non-null tail");
                    throw new rm.k();
                }
                A(i11, bVar, e10, cVar, !this.f23812a.D());
                i10 = 1;
            }
            this.f23817f = e10;
            if (bVar != null) {
                bVar.k();
                bVar3 = bVar;
            }
            this.f23818g = bVar3;
            this.f23816e = D(u10);
            if (i10 != 0) {
                C();
                return;
            }
            return;
        }
        if (this.f23812a.D() && q10 == 0) {
            i.c cVar2 = u10;
            while (i10 < e10.q()) {
                cVar2 = g((i.b) e10.p()[i10], cVar2);
                i10++;
            }
            B();
        } else if (e10.q() != 0) {
            if (bVar == null) {
                bVar = new a1.b(new i.b[16], 0);
            }
            A(0, bVar, e10, u10, !this.f23812a.D());
        } else {
            if (bVar == null) {
                g2.a.c("expected prior modifier list to be non-empty");
                throw new rm.k();
            }
            i.c F12 = u10.F1();
            for (int i12 = 0; F12 != null && i12 < bVar.q(); i12++) {
                F12 = h(F12).F1();
            }
            w wVar = this.f23813b;
            g0 o02 = this.f23812a.o0();
            wVar.f3(o02 != null ? o02.P() : null);
            this.f23814c = this.f23813b;
            this.f23817f = e10;
            if (bVar != null) {
            }
            this.f23818g = bVar3;
            this.f23816e = D(u10);
            if (i10 != 0) {
            }
        }
        i10 = 1;
        this.f23817f = e10;
        if (bVar != null) {
        }
        this.f23818g = bVar3;
        this.f23816e = D(u10);
        if (i10 != 0) {
        }
    }

    public final i.c k() {
        return this.f23816e;
    }

    public final w l() {
        return this.f23813b;
    }

    public final g0 m() {
        return this.f23812a;
    }

    public final z0 n() {
        return this.f23814c;
    }

    public final i.c o() {
        return this.f23815d;
    }

    public final boolean p(int i10) {
        return (i() & i10) != 0;
    }

    public final boolean q(int i10) {
        return (i() & i10) != 0;
    }

    public final void s() {
        for (i.c k10 = k(); k10 != null; k10 = k10.F1()) {
            k10.P1();
        }
    }

    public final void t() {
        for (i.c o10 = o(); o10 != null; o10 = o10.L1()) {
            if (o10.O1()) {
                o10.Q1();
            }
        }
    }

    public String toString() {
        StringBuilder sb2 = new StringBuilder();
        sb2.append("[");
        if (this.f23816e != this.f23815d) {
            i.c k10 = k();
            while (true) {
                if (k10 == null || k10 == o()) {
                    break;
                }
                sb2.append(String.valueOf(k10));
                if (k10.F1() == this.f23815d) {
                    sb2.append("]");
                    break;
                }
                sb2.append(",");
                k10 = k10.F1();
            }
        } else {
            sb2.append("]");
        }
        String sb3 = sb2.toString();
        kotlin.jvm.internal.t.f(sb3, "StringBuilder().apply(builderAction).toString()");
        return sb3;
    }

    public final void x() {
        for (i.c o10 = o(); o10 != null; o10 = o10.L1()) {
            if (o10.O1()) {
                o10.U1();
            }
        }
        z();
        t();
    }

    public final void y() {
        for (i.c k10 = k(); k10 != null; k10 = k10.F1()) {
            k10.V1();
            if (k10.I1()) {
                c1.a(k10);
            }
            if (k10.N1()) {
                c1.e(k10);
            }
            k10.a2(false);
            k10.e2(false);
        }
    }

    public final void z() {
        for (i.c o10 = o(); o10 != null; o10 = o10.L1()) {
            if (o10.O1()) {
                o10.W1();
            }
        }
    }
}
