package G0;

import J0.E1;
import android.os.Handler;
import android.view.ViewGroup;
import androidx.compose.runtime.ComposeNodeLifecycleCallback;
import androidx.compose.runtime.CompositionContext;
import androidx.compose.runtime.CompositionKt;
import androidx.compose.runtime.PausableComposition;
import androidx.compose.runtime.PausableCompositionKt;
import androidx.compose.runtime.PausedComposition;
import androidx.compose.runtime.ReusableComposition;
import androidx.compose.runtime.SnapshotStateKt__SnapshotStateKt;
import androidx.compose.runtime.collection.MutableVector;
import androidx.compose.runtime.internal.ComposableLambda;
import androidx.compose.runtime.internal.ComposableLambdaKt;
import androidx.compose.runtime.snapshots.Snapshot;
import java.util.List;
import x4.C3249o;

/* JADX INFO: loaded from: classes.dex */
public final class W implements ComposeNodeLifecycleCallback {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final I0.H f1936a;

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

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final n.N f1941f;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final n.N f1942j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final O f1943k;
    public final L l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final n.N f1944m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final D0 f1945n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final n.N f1946o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public final MutableVector f1947p;

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

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

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public final String f1950s;

    public W(I0.H h5, E0 e0) {
        this.f1936a = h5;
        this.f1938c = e0;
        long[] jArr = n.Y.f21386a;
        this.f1941f = new n.N();
        this.f1942j = new n.N();
        this.f1943k = new O(this);
        this.l = new L(this);
        this.f1944m = new n.N();
        this.f1945n = new D0();
        this.f1946o = new n.N();
        this.f1947p = new MutableVector(new Object[16], 0);
        this.f1950s = "Asking for intrinsic measurements of SubcomposeLayout layouts is not supported. This includes components that are built on top of SubcomposeLayout, such as lazy lists, BoxWithConstraints, TabRow, etc. To mitigate this:\n- if intrinsic measurements are used to achieve 'match parent' sizing, consider replacing the parent of the component with a custom layout which controls the order in which children are measured, making intrinsic measurement not needed\n- adding a size modifier to the component, in order to fast return the queried intrinsic measurement.";
    }

    public static final void a(W w6, Object obj) {
        w6.f();
        I0.H h5 = (I0.H) w6.f1944m.j(obj);
        I0.H h6 = w6.f1936a;
        if (h5 != null) {
            if (w6.f1949r <= 0) {
                F0.a.b("No pre-composed items to dispose");
            }
            int iIndexOf = h6.m().indexOf(h5);
            if (iIndexOf < h6.m().size() - w6.f1949r) {
                F0.a.b("Item is not in pre-composed item range");
            }
            w6.f1948q++;
            w6.f1949r--;
            M m6 = (M) w6.f1941f.d(h5);
            if (m6 != null) {
                c(m6);
            }
            int size = (h6.m().size() - w6.f1949r) - w6.f1948q;
            w6.h(iIndexOf, size);
            w6.e(size);
        }
        if (w6.f1947p.contains(obj)) {
            I0.H.V(h6, true, 6);
        }
    }

    public static void c(M m6) {
        PausedComposition pausedComposition = m6.f1907f;
        if (pausedComposition != null) {
            pausedComposition.cancel();
            m6.f1907f = null;
            ReusableComposition reusableComposition = m6.f1904c;
            if (reusableComposition != null) {
                reusableComposition.dispose();
            }
            m6.f1904c = null;
        }
    }

    public final void b(M m6, boolean z6) {
        PausedComposition pausedComposition = m6.f1907f;
        if (pausedComposition != null) {
            Snapshot.Companion companion = Snapshot.Companion;
            Snapshot currentThreadSnapshot = companion.getCurrentThreadSnapshot();
            J4.c readObserver = currentThreadSnapshot != null ? currentThreadSnapshot.getReadObserver() : null;
            Snapshot snapshotMakeCurrentNonObservable = companion.makeCurrentNonObservable(currentThreadSnapshot);
            try {
                I0.H h5 = this.f1936a;
                h5.f2190u = true;
                if (z6) {
                    while (!pausedComposition.isComplete()) {
                        try {
                            pausedComposition.resume(new K(0));
                        } catch (Throwable th) {
                            throw th;
                        }
                    }
                }
                pausedComposition.apply();
                m6.f1907f = null;
                h5.f2190u = false;
            } finally {
                companion.restoreNonObservable(currentThreadSnapshot, snapshotMakeCurrentNonObservable, readObserver);
            }
        }
    }

    public final z0 d(Object obj) {
        return !this.f1936a.F() ? new S() : new T(this, obj);
    }

    /* JADX WARN: Removed duplicated region for block: B:27:0x00a1  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void e(int i6) {
        boolean z6;
        int i7 = i6;
        boolean z7 = false;
        this.f1948q = 0;
        I0.H h5 = this.f1936a;
        List listM = h5.m();
        boolean z8 = true;
        int size = (listM.size() - this.f1949r) - 1;
        if (i7 <= size) {
            D0 d02 = this.f1945n;
            d02.clear();
            n.N n6 = this.f1941f;
            n.K k6 = (n.K) d02.f1854b;
            if (i7 <= size) {
                int i8 = i7;
                while (true) {
                    Object objD = n6.d((I0.H) listM.get(i8));
                    kotlin.jvm.internal.o.e(objD);
                    k6.a(((M) objD).f1902a);
                    if (i8 == size) {
                        break;
                    } else {
                        i8++;
                    }
                }
            }
            this.f1938c.i(d02);
            Snapshot.Companion companion = Snapshot.Companion;
            Snapshot currentThreadSnapshot = companion.getCurrentThreadSnapshot();
            J4.c readObserver = currentThreadSnapshot != null ? currentThreadSnapshot.getReadObserver() : null;
            Snapshot snapshotMakeCurrentNonObservable = companion.makeCurrentNonObservable(currentThreadSnapshot);
            boolean z9 = false;
            while (size >= i7) {
                try {
                    I0.H h6 = (I0.H) listM.get(size);
                    Object objD2 = n6.d(h6);
                    kotlin.jvm.internal.o.e(objD2);
                    M m6 = (M) objD2;
                    boolean z10 = z8;
                    Object obj = m6.f1902a;
                    if (k6.c(obj)) {
                        this.f1948q++;
                        if (((Boolean) m6.f1908g.getValue()).booleanValue()) {
                            I0.L l = h6.f2163K;
                            I0.Y y6 = l.f2227p;
                            I0.F f6 = I0.F.f2145c;
                            y6.f2318o = f6;
                            I0.U u6 = l.f2228q;
                            if (u6 != null) {
                                u6.f2271m = f6;
                            }
                            j(m6, false);
                            if (m6.f1909h) {
                                z6 = z10;
                                z9 = z6;
                            } else {
                                z6 = z10;
                            }
                        }
                    } else {
                        h5.f2190u = z10;
                        n6.j(h6);
                        ReusableComposition reusableComposition = m6.f1904c;
                        if (reusableComposition != null) {
                            reusableComposition.dispose();
                        }
                        z6 = true;
                        h5.Q(size, 1);
                        h5.f2190u = false;
                    }
                    this.f1942j.j(obj);
                    size--;
                    z8 = z6;
                    i7 = i6;
                } catch (Throwable th) {
                    companion.restoreNonObservable(currentThreadSnapshot, snapshotMakeCurrentNonObservable, readObserver);
                    throw th;
                }
            }
            companion.restoreNonObservable(currentThreadSnapshot, snapshotMakeCurrentNonObservable, readObserver);
            z7 = z9;
        }
        if (z7) {
            Snapshot.Companion.sendApplyNotifications();
        }
        f();
    }

    public final void f() {
        int size = this.f1936a.m().size();
        n.N n6 = this.f1941f;
        if (!(n6.f21385e == size)) {
            F0.a.a("Inconsistency between the count of nodes tracked by the state (" + n6.f21385e + ") and the children count on the SubcomposeLayout (" + size + "). Are you trying to use the state of the disposed SubcomposeLayout?");
        }
        if (!((size - this.f1948q) - this.f1949r >= 0)) {
            StringBuilder sbR = com.google.android.recaptcha.internal.a.r(size, "Incorrect state. Total children ", ". Reusable children ");
            sbR.append(this.f1948q);
            sbR.append(". Precomposed children ");
            sbR.append(this.f1949r);
            F0.a.a(sbR.toString());
        }
        n.N n7 = this.f1944m;
        if (n7.f21385e == this.f1949r) {
            return;
        }
        F0.a.a("Incorrect state. Precomposed children " + this.f1949r + ". Map size " + n7.f21385e);
    }

    public final void g(boolean z6) {
        this.f1949r = 0;
        this.f1944m.f();
        List listM = this.f1936a.m();
        int size = listM.size();
        if (this.f1948q != size) {
            this.f1948q = size;
            Snapshot.Companion companion = Snapshot.Companion;
            Snapshot currentThreadSnapshot = companion.getCurrentThreadSnapshot();
            J4.c readObserver = currentThreadSnapshot != null ? currentThreadSnapshot.getReadObserver() : null;
            Snapshot snapshotMakeCurrentNonObservable = companion.makeCurrentNonObservable(currentThreadSnapshot);
            for (int i6 = 0; i6 < size; i6++) {
                try {
                    I0.H h5 = (I0.H) listM.get(i6);
                    M m6 = (M) this.f1941f.d(h5);
                    if (m6 != null && ((Boolean) m6.f1908g.getValue()).booleanValue()) {
                        I0.L l = h5.f2163K;
                        I0.Y y6 = l.f2227p;
                        I0.F f6 = I0.F.f2145c;
                        y6.f2318o = f6;
                        I0.U u6 = l.f2228q;
                        if (u6 != null) {
                            u6.f2271m = f6;
                        }
                        j(m6, z6);
                        m6.f1902a = B.f1845a;
                    }
                } catch (Throwable th) {
                    companion.restoreNonObservable(currentThreadSnapshot, snapshotMakeCurrentNonObservable, readObserver);
                    throw th;
                }
            }
            companion.restoreNonObservable(currentThreadSnapshot, snapshotMakeCurrentNonObservable, readObserver);
            this.f1942j.f();
        }
        f();
    }

    public final void h(int i6, int i7) {
        I0.H h5 = this.f1936a;
        h5.f2190u = true;
        h5.J(i6, i7, 1);
        h5.f2190u = false;
    }

    public final void i(Object obj, J4.e eVar, boolean z6) {
        I0.H h5 = this.f1936a;
        if (h5.F()) {
            f();
            if (this.f1942j.b(obj)) {
                return;
            }
            this.f1946o.j(obj);
            n.N n6 = this.f1944m;
            Object objD = n6.d(obj);
            if (objD == null) {
                objD = l(obj);
                if (objD != null) {
                    h(h5.m().indexOf(objD), h5.m().size());
                    this.f1949r++;
                } else {
                    int size = h5.m().size();
                    I0.H h6 = new I0.H(2);
                    h5.f2190u = true;
                    h5.z(size, h6);
                    h5.f2190u = false;
                    this.f1949r++;
                    objD = h6;
                }
                n6.l(obj, objD);
            }
            k((I0.H) objD, obj, z6, eVar);
        }
    }

    public final void j(M m6, boolean z6) {
        ReusableComposition reusableComposition;
        if (z6 || !m6.f1909h) {
            m6.f1908g = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(Boolean.FALSE, null, 2, null);
        } else {
            m6.f1908g.setValue(Boolean.FALSE);
        }
        if (m6.f1907f != null) {
            c(m6);
            return;
        }
        if (z6) {
            ReusableComposition reusableComposition2 = m6.f1904c;
            if (reusableComposition2 != null) {
                reusableComposition2.deactivate();
                return;
            }
            return;
        }
        I0.q0 outOfFrameExecutor = ((J0.A) I0.K.a(this.f1936a)).getOutOfFrameExecutor();
        if (outOfFrameExecutor == null) {
            if (m6.f1909h || (reusableComposition = m6.f1904c) == null) {
                return;
            }
            reusableComposition.deactivate();
            return;
        }
        B0.b bVar = new B0.b(m6, 2);
        J0.A a6 = (J0.A) outOfFrameExecutor;
        C3249o c3249o = a6.f2747k;
        boolean zIsEmpty = c3249o.isEmpty();
        c3249o.addLast(bVar);
        if (zIsEmpty) {
            Handler handler = a6.getHandler();
            if (handler == null) {
                throw new IllegalArgumentException("schedule is called when outOfFrameExecutor is not available (view is detached)");
            }
            handler.postAtFrontOfQueue(a6.l);
        }
    }

    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    public final void k(I0.H h5, Object obj, boolean z6, J4.e eVar) {
        int i6 = 0;
        I0.H h6 = this.f1936a;
        n.N n6 = this.f1941f;
        Object objD = n6.d(h5);
        Object obj2 = objD;
        if (objD == null) {
            ComposableLambda composableLambda = AbstractC0256g.f1967a;
            M m6 = new M();
            m6.f1902a = obj;
            m6.f1903b = composableLambda;
            m6.f1904c = null;
            m6.f1908g = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(Boolean.TRUE, null, 2, null);
            n6.l(h5, m6);
            obj2 = m6;
        }
        M m7 = (M) obj2;
        boolean z7 = m7.f1903b != eVar;
        if (m7.f1907f != null) {
            if (z7) {
                c(m7);
            } else if (z6) {
                return;
            } else {
                b(m7, true);
            }
        }
        ReusableComposition reusableComposition = m7.f1904c;
        boolean hasInvalidations = reusableComposition != null ? reusableComposition.getHasInvalidations() : true;
        if (z7 || hasInvalidations || m7.f1905d) {
            m7.f1903b = eVar;
            if (m7.f1907f != null) {
                F0.a.a("new subcompose call while paused composition is still active");
            }
            Snapshot.Companion companion = Snapshot.Companion;
            Snapshot currentThreadSnapshot = companion.getCurrentThreadSnapshot();
            J4.c readObserver = currentThreadSnapshot != null ? currentThreadSnapshot.getReadObserver() : null;
            Snapshot snapshotMakeCurrentNonObservable = companion.makeCurrentNonObservable(currentThreadSnapshot);
            try {
                h6.f2190u = true;
                ReusableComposition ReusableComposition = m7.f1904c;
                CompositionContext compositionContext = this.f1937b;
                if (compositionContext == null) {
                    F0.a.c("parent composition reference not set");
                    throw new E3.v();
                }
                if (ReusableComposition == null || ReusableComposition.isDisposed()) {
                    if (z6) {
                        ViewGroup.LayoutParams layoutParams = E1.f2816a;
                        ReusableComposition = PausableCompositionKt.PausableComposition(new I0.J0(h5), compositionContext);
                    } else {
                        ViewGroup.LayoutParams layoutParams2 = E1.f2816a;
                        ReusableComposition = CompositionKt.ReusableComposition(new I0.J0(h5), compositionContext);
                    }
                }
                m7.f1904c = ReusableComposition;
                J4.e eVarComposableLambdaInstance = m7.f1903b;
                if (((J0.A) I0.K.a(h6)).getOutOfFrameExecutor() != null) {
                    m7.f1909h = false;
                } else {
                    m7.f1909h = true;
                    eVarComposableLambdaInstance = ComposableLambdaKt.composableLambdaInstance(1524156494, true, new V(i6, m7, eVarComposableLambdaInstance));
                }
                if (z6) {
                    kotlin.jvm.internal.o.f(ReusableComposition, "null cannot be cast to non-null type androidx.compose.runtime.PausableComposition");
                    if (m7.f1906e) {
                        m7.f1907f = ((PausableComposition) ReusableComposition).setPausableContentWithReuse(eVarComposableLambdaInstance);
                    } else {
                        m7.f1907f = ((PausableComposition) ReusableComposition).setPausableContent(eVarComposableLambdaInstance);
                    }
                } else if (m7.f1906e) {
                    ReusableComposition.setContentWithReuse(eVarComposableLambdaInstance);
                } else {
                    ReusableComposition.setContent(eVarComposableLambdaInstance);
                }
                m7.f1906e = false;
                h6.f2190u = false;
                companion.restoreNonObservable(currentThreadSnapshot, snapshotMakeCurrentNonObservable, readObserver);
                m7.f1905d = false;
            } catch (Throwable th) {
                companion.restoreNonObservable(currentThreadSnapshot, snapshotMakeCurrentNonObservable, readObserver);
                throw th;
            }
        }
    }

    public final I0.H l(Object obj) {
        n.N n6;
        int i6;
        if (this.f1948q != 0) {
            List listM = this.f1936a.m();
            int size = listM.size() - this.f1949r;
            int i7 = size - this.f1948q;
            int i8 = size - 1;
            int i9 = i8;
            while (true) {
                n6 = this.f1941f;
                if (i9 < i7) {
                    i6 = -1;
                    break;
                }
                Object objD = n6.d((I0.H) listM.get(i9));
                kotlin.jvm.internal.o.e(objD);
                if (kotlin.jvm.internal.o.c(((M) objD).f1902a, obj)) {
                    i6 = i9;
                    break;
                }
                i9--;
            }
            if (i6 == -1) {
                while (i8 >= i7) {
                    Object objD2 = n6.d((I0.H) listM.get(i8));
                    kotlin.jvm.internal.o.e(objD2);
                    M m6 = (M) objD2;
                    Object obj2 = m6.f1902a;
                    if (obj2 == B.f1845a || this.f1938c.a(obj, obj2)) {
                        m6.f1902a = obj;
                        i9 = i8;
                        i6 = i9;
                        break;
                    }
                    i8--;
                }
                i9 = i8;
            }
            if (i6 != -1) {
                if (i9 != i7) {
                    h(i9, i7);
                }
                this.f1948q--;
                I0.H h5 = (I0.H) listM.get(i7);
                Object objD3 = n6.d(h5);
                kotlin.jvm.internal.o.e(objD3);
                M m7 = (M) objD3;
                m7.f1908g = SnapshotStateKt__SnapshotStateKt.mutableStateOf$default(Boolean.TRUE, null, 2, null);
                m7.f1906e = true;
                m7.f1905d = true;
                return h5;
            }
        }
        return null;
    }

    @Override // androidx.compose.runtime.ComposeNodeLifecycleCallback
    public final void onDeactivate() {
        g(true);
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x004d  */
    @Override // androidx.compose.runtime.ComposeNodeLifecycleCallback
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void onRelease() {
        ReusableComposition reusableComposition;
        I0.H h5 = this.f1936a;
        h5.f2190u = true;
        n.N n6 = this.f1941f;
        Object[] objArr = n6.f21383c;
        long[] jArr = n6.f21381a;
        int length = jArr.length - 2;
        if (length >= 0) {
            int i6 = 0;
            while (true) {
                long j4 = jArr[i6];
                if ((((~j4) << 7) & j4 & (-9187201950435737472L)) != -9187201950435737472L) {
                    int i7 = 8 - ((~(i6 - length)) >>> 31);
                    for (int i8 = 0; i8 < i7; i8++) {
                        if ((255 & j4) < 128 && (reusableComposition = ((M) objArr[(i6 << 3) + i8]).f1904c) != null) {
                            reusableComposition.dispose();
                        }
                        j4 >>= 8;
                    }
                    if (i7 != 8) {
                        break;
                    } else if (i6 == length) {
                        break;
                    } else {
                        i6++;
                    }
                }
            }
        }
        h5.P();
        h5.f2190u = false;
        n6.f();
        this.f1942j.f();
        this.f1949r = 0;
        this.f1948q = 0;
        this.f1944m.f();
        f();
    }

    @Override // androidx.compose.runtime.ComposeNodeLifecycleCallback
    public final void onReuse() {
        g(false);
    }
}
