package o;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class P00 extends AbstractC0425Qk {
    public static final Ba0 x = AbstractC0752ap.h(KW.f192o);
    public static final AtomicReference y = new AtomicReference(Boolean.FALSE);
    public final C0549Ve a;
    public final Object b;
    public TI c;
    public Throwable d;
    public final ArrayList e;
    public Object f;
    public C0713aR g;
    public final C1479iR h;
    public final ArrayList i;
    public final ArrayList j;
    public final ZQ k;
    public final C1390hY l;
    public final ZQ m;
    public final ZQ n;

    /* renamed from: o, reason: collision with root package name */
    public ArrayList f278o;
    public LinkedHashSet p;
    public C2448sg q;
    public WT r;
    public boolean s;
    public final Ba0 t;
    public final VI u;
    public final InterfaceC2747vn v;
    public final BP w;

    public P00(InterfaceC2747vn interfaceC2747vn) {
        C0549Ve c0549Ve = new C0549Ve(new C1164f5(13, this));
        this.a = c0549Ve;
        this.b = new Object();
        this.e = new ArrayList();
        this.g = new C0713aR();
        this.h = new C1479iR(new C0555Vk[16]);
        this.i = new ArrayList();
        this.j = new ArrayList();
        this.k = new ZQ();
        this.l = new C1390hY(8);
        this.m = new ZQ();
        this.n = new ZQ();
        this.t = AbstractC0752ap.h(M00.n);
        new AtomicReference(AbstractC2539te.d);
        VI vi = new VI((TI) interfaceC2747vn.m(C0669Zu.K));
        vi.d(new S1(14, this));
        this.u = vi;
        this.v = interfaceC2747vn.M(c0549Ve).M(vi);
        this.w = new BP(9);
    }

    public static final C0555Vk r(P00 p00, C0555Vk c0555Vk, C0713aR c0713aR) {
        LinkedHashSet linkedHashSet;
        C1095eR c1095eRC;
        if (!c0555Vk.E.E && c0555Vk.F != 3 && ((linkedHashSet = p00.p) == null || !linkedHashSet.contains(c0555Vk))) {
            S1 s1 = new S1(13, c0555Vk);
            C1590je c1590je = new C1590je(11, c0555Vk, c0713aR);
            AbstractC2220q90 abstractC2220q90K = AbstractC2884x90.k();
            C1095eR c1095eR = abstractC2220q90K instanceof C1095eR ? (C1095eR) abstractC2220q90K : null;
            if (c1095eR == null || (c1095eRC = c1095eR.C(s1, c1590je)) == null) {
                throw new IllegalStateException("Cannot create a mutable snapshot of an read-only snapshot");
            }
            try {
                AbstractC2220q90 abstractC2220q90J = c1095eRC.j();
                if (c0713aR != null) {
                    try {
                        if (c0713aR.h()) {
                            C2590u5 c2590u5 = new C2590u5(13, c0713aR, c0555Vk);
                            C0321Mk c0321Mk = c0555Vk.E;
                            if (c0321Mk.E) {
                                AbstractC0373Ok.c("Preparing a composition while composing is not supported");
                            }
                            c0321Mk.E = true;
                            try {
                                c2590u5.a();
                                c0321Mk.E = false;
                            } catch (Throwable th) {
                                c0321Mk.E = false;
                                throw th;
                            }
                        }
                    } catch (Throwable th2) {
                        AbstractC2220q90.q(abstractC2220q90J);
                        throw th2;
                    }
                }
                boolean zS = c0555Vk.s();
                AbstractC2220q90.q(abstractC2220q90J);
                if (zS) {
                    return c0555Vk;
                }
            } finally {
                t(c1095eRC);
            }
        }
        return null;
    }

    public static final boolean s(P00 p00) {
        synchronized (p00.b) {
            boolean z = true;
            if (p00.g.g()) {
                if (p00.h.n == 0 && !p00.w() && !p00.k.j()) {
                    z = false;
                }
                return z;
            }
            List listY = p00.y();
            B40 b40 = new B40(p00.g);
            p00.g = new C0713aR();
            try {
                int size = listY.size();
                for (int i = 0; i < size; i++) {
                    ((C0555Vk) listY.get(i)).t(b40);
                    if (((M00) p00.t.getValue()).compareTo(M00.m) <= 0) {
                        break;
                    }
                }
                synchronized (p00.b) {
                    if (p00.v() != null) {
                        throw new IllegalStateException("called outside of runRecomposeAndApplyChanges");
                    }
                    if (p00.h.n == 0 && !p00.w() && !p00.k.j()) {
                        z = false;
                    }
                }
                return z;
            } catch (Throwable th) {
                synchronized (p00.b) {
                    C0713aR c0713aR = p00.g;
                    int i2 = c0713aR.d;
                    Iterator<E> it = b40.iterator();
                    while (it.hasNext()) {
                        c0713aR.i(it.next());
                    }
                    throw th;
                }
            }
        }
    }

    public static void t(C1095eR c1095eR) {
        try {
            if (c1095eR.w() instanceof C2314r90) {
                throw new IllegalStateException("Unsupported concurrent change during composition. A state object was modified by composition as well as being modified outside composition.");
            }
        } finally {
            c1095eR.c();
        }
    }

    public static final void z(ArrayList arrayList, P00 p00, C0555Vk c0555Vk) {
        arrayList.clear();
        synchronized (p00.b) {
            Iterator it = p00.j.iterator();
            if (it.hasNext()) {
                ((AbstractC2047oQ) it.next()).getClass();
                throw null;
            }
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:52:0x013d, code lost:
    
        r3 = r10.size();
        r4 = 0;
     */
    /* JADX WARN: Code restructure failed: missing block: B:53:0x0142, code lost:
    
        if (r4 >= r3) goto L117;
     */
    /* JADX WARN: Code restructure failed: missing block: B:55:0x014c, code lost:
    
        if (((o.C3001yV) r10.get(r4)).m == null) goto L118;
     */
    /* JADX WARN: Code restructure failed: missing block: B:56:0x014e, code lost:
    
        r4 = r4 + 1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:57:0x0151, code lost:
    
        r3 = new java.util.ArrayList(r10.size());
        r4 = r10.size();
        r8 = 0;
     */
    /* JADX WARN: Code restructure failed: missing block: B:58:0x015f, code lost:
    
        if (r8 >= r4) goto L119;
     */
    /* JADX WARN: Code restructure failed: missing block: B:59:0x0161, code lost:
    
        r11 = (o.C3001yV) r10.get(r8);
     */
    /* JADX WARN: Code restructure failed: missing block: B:60:0x0169, code lost:
    
        if (r11.m != null) goto L120;
     */
    /* JADX WARN: Code restructure failed: missing block: B:61:0x016b, code lost:
    
        r11 = (o.AbstractC2047oQ) r11.l;
     */
    /* JADX WARN: Code restructure failed: missing block: B:64:0x0172, code lost:
    
        r8 = r8 + 1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:65:0x0175, code lost:
    
        r4 = r17.b;
     */
    /* JADX WARN: Code restructure failed: missing block: B:66:0x0177, code lost:
    
        monitor-enter(r4);
     */
    /* JADX WARN: Code restructure failed: missing block: B:67:0x0178, code lost:
    
        o.AbstractC0138Fi.Y(r3, r17.j);
     */
    /* JADX WARN: Code restructure failed: missing block: B:68:0x017d, code lost:
    
        monitor-exit(r4);
     */
    /* JADX WARN: Code restructure failed: missing block: B:69:0x017e, code lost:
    
        r3 = new java.util.ArrayList(r10.size());
        r4 = r10.size();
        r8 = 0;
     */
    /* JADX WARN: Code restructure failed: missing block: B:70:0x018c, code lost:
    
        if (r8 >= r4) goto L122;
     */
    /* JADX WARN: Code restructure failed: missing block: B:71:0x018e, code lost:
    
        r11 = r10.get(r8);
     */
    /* JADX WARN: Code restructure failed: missing block: B:72:0x0197, code lost:
    
        if (((o.C3001yV) r11).m == null) goto L124;
     */
    /* JADX WARN: Code restructure failed: missing block: B:73:0x0199, code lost:
    
        r3.add(r11);
     */
    /* JADX WARN: Code restructure failed: missing block: B:74:0x019c, code lost:
    
        r8 = r8 + 1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:75:0x019f, code lost:
    
        r10 = r3;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final java.util.List A(java.util.List r18, o.C0713aR r19) {
        /*
            Method dump skipped, instructions count: 462
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.P00.A(java.util.List, o.aR):java.util.List");
    }

    public final void B(Throwable th, C0555Vk c0555Vk) throws Throwable {
        if (!((Boolean) y.get()).booleanValue() || (th instanceof C2741vk)) {
            synchronized (this.b) {
                WT wt = this.r;
                if (wt != null) {
                    throw ((Throwable) wt.m);
                }
                this.r = new WT(7, th);
            }
            throw th;
        }
        synchronized (this.b) {
            try {
                this.i.clear();
                this.h.h();
                this.g = new C0713aR();
                this.j.clear();
                this.k.a();
                this.m.a();
                this.r = new WT(7, th);
                if (c0555Vk != null) {
                    C(c0555Vk);
                }
                v();
            } catch (Throwable th2) {
                throw th2;
            }
        }
    }

    public final void C(C0555Vk c0555Vk) {
        ArrayList arrayList = this.f278o;
        if (arrayList == null) {
            arrayList = new ArrayList();
            this.f278o = arrayList;
        }
        if (!arrayList.contains(c0555Vk)) {
            arrayList.add(c0555Vk);
        }
        if (this.e.remove(c0555Vk)) {
            this.f = null;
        }
    }

    @Override // o.AbstractC0425Qk
    public final void a(C0555Vk c0555Vk, C0554Vj c0554Vj) throws Throwable {
        M00 m00;
        boolean zContains;
        C1095eR c1095eRC;
        boolean z = c0555Vk.E.E;
        synchronized (this.b) {
            M00 m002 = (M00) this.t.getValue();
            m00 = M00.m;
            zContains = m002.compareTo(m00) > 0 ? true ^ y().contains(c0555Vk) : true;
        }
        try {
            S1 s1 = new S1(13, c0555Vk);
            C1590je c1590je = new C1590je(11, c0555Vk, (Object) null);
            AbstractC2220q90 abstractC2220q90K = AbstractC2884x90.k();
            C1095eR c1095eR = abstractC2220q90K instanceof C1095eR ? (C1095eR) abstractC2220q90K : null;
            if (c1095eR == null || (c1095eRC = c1095eR.C(s1, c1590je)) == null) {
                throw new IllegalStateException("Cannot create a mutable snapshot of an read-only snapshot");
            }
            try {
                AbstractC2220q90 abstractC2220q90J = c1095eRC.j();
                try {
                    c0555Vk.i(c0554Vj);
                    synchronized (this.b) {
                        if (((M00) this.t.getValue()).compareTo(m00) > 0 && !y().contains(c0555Vk)) {
                            this.e.add(c0555Vk);
                            this.f = null;
                        }
                    }
                    if (!z) {
                        AbstractC2884x90.k().m();
                    }
                    try {
                        synchronized (this.b) {
                            ArrayList arrayList = this.j;
                            if (arrayList.size() > 0) {
                                ((AbstractC2047oQ) arrayList.get(0)).getClass();
                                throw null;
                            }
                        }
                        try {
                            c0555Vk.d();
                            c0555Vk.f();
                            if (z) {
                                return;
                            }
                            AbstractC2884x90.k().m();
                        } catch (Throwable th) {
                            B(th, null);
                        }
                    } catch (Throwable th2) {
                        B(th2, c0555Vk);
                    }
                } finally {
                    AbstractC2220q90.q(abstractC2220q90J);
                }
            } finally {
                t(c1095eRC);
            }
        } catch (Throwable th3) {
            if (zContains) {
                synchronized (this.b) {
                }
            }
            B(th3, c0555Vk);
        }
    }

    @Override // o.AbstractC0425Qk
    public final boolean c() {
        return ((Boolean) y.get()).booleanValue();
    }

    @Override // o.AbstractC0425Qk
    public final boolean d() {
        return false;
    }

    @Override // o.AbstractC0425Qk
    public final boolean e() {
        return false;
    }

    @Override // o.AbstractC0425Qk
    public final long f() {
        return 1000;
    }

    @Override // o.AbstractC0425Qk
    public final InterfaceC0399Pk g() {
        return null;
    }

    @Override // o.AbstractC0425Qk
    public final InterfaceC2747vn i() {
        return this.v;
    }

    @Override // o.AbstractC0425Qk
    public final void j(C0555Vk c0555Vk) {
        InterfaceC2259qg interfaceC2259qgV;
        synchronized (this.b) {
            if (this.h.i(c0555Vk)) {
                interfaceC2259qgV = null;
            } else {
                this.h.b(c0555Vk);
                interfaceC2259qgV = v();
            }
        }
        if (interfaceC2259qgV != null) {
            ((C2448sg) interfaceC2259qgV).resumeWith(Oh0.a);
        }
    }

    @Override // o.AbstractC0425Qk
    public final AbstractC1952nQ k(AbstractC2047oQ abstractC2047oQ) {
        AbstractC1952nQ abstractC1952nQ;
        synchronized (this.b) {
            abstractC1952nQ = (AbstractC1952nQ) this.m.k(abstractC2047oQ);
        }
        return abstractC1952nQ;
    }

    @Override // o.AbstractC0425Qk
    public final void n(C0555Vk c0555Vk) {
        synchronized (this.b) {
            try {
                LinkedHashSet linkedHashSet = this.p;
                if (linkedHashSet == null) {
                    linkedHashSet = new LinkedHashSet();
                    this.p = linkedHashSet;
                }
                linkedHashSet.add(c0555Vk);
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // o.AbstractC0425Qk
    public final void q(C0555Vk c0555Vk) {
        synchronized (this.b) {
            if (this.e.remove(c0555Vk)) {
                this.f = null;
            }
            this.h.j(c0555Vk);
            this.i.remove(c0555Vk);
        }
    }

    public final void u() {
        synchronized (this.b) {
            if (((M00) this.t.getValue()).compareTo(M00.p) >= 0) {
                Ba0 ba0 = this.t;
                M00 m00 = M00.m;
                ba0.getClass();
                ba0.i(null, m00);
            }
        }
        this.u.c(null);
    }

    public final InterfaceC2259qg v() {
        Ba0 ba0 = this.t;
        int iCompareTo = ((M00) ba0.getValue()).compareTo(M00.m);
        ArrayList arrayList = this.j;
        ArrayList arrayList2 = this.i;
        C1479iR c1479iR = this.h;
        if (iCompareTo <= 0) {
            for (C0555Vk c0555Vk : y()) {
            }
            this.e.clear();
            this.f = C0332Mv.l;
            this.g = new C0713aR();
            c1479iR.h();
            arrayList2.clear();
            arrayList.clear();
            this.f278o = null;
            C2448sg c2448sg = this.q;
            if (c2448sg != null) {
                c2448sg.k(null);
            }
            this.q = null;
            this.r = null;
            return null;
        }
        WT wt = this.r;
        M00 m00 = M00.q;
        M00 m002 = M00.n;
        if (wt == null) {
            if (this.c == null) {
                this.g = new C0713aR();
                c1479iR.h();
                if (w()) {
                    m002 = M00.f222o;
                }
            } else {
                m002 = (c1479iR.n == 0 && !this.g.h() && arrayList2.isEmpty() && arrayList.isEmpty() && !w() && !this.k.j()) ? M00.p : m00;
            }
        }
        ba0.getClass();
        ba0.i(null, m002);
        if (m002 != m00) {
            return null;
        }
        C2448sg c2448sg2 = this.q;
        this.q = null;
        return c2448sg2;
    }

    public final boolean w() {
        return !this.s && (this.a.f380o.get() & 134217727) > 0;
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x001d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final boolean x() {
        /*
            r2 = this;
            java.lang.Object r0 = r2.b
            monitor-enter(r0)
            o.aR r1 = r2.g     // Catch: java.lang.Throwable -> L1b
            boolean r1 = r1.h()     // Catch: java.lang.Throwable -> L1b
            if (r1 != 0) goto L1d
            o.iR r1 = r2.h     // Catch: java.lang.Throwable -> L1b
            int r1 = r1.n     // Catch: java.lang.Throwable -> L1b
            if (r1 == 0) goto L12
            goto L1d
        L12:
            boolean r1 = r2.w()     // Catch: java.lang.Throwable -> L1b
            if (r1 == 0) goto L19
            goto L1d
        L19:
            r1 = 0
            goto L1e
        L1b:
            r1 = move-exception
            goto L20
        L1d:
            r1 = 1
        L1e:
            monitor-exit(r0)
            return r1
        L20:
            monitor-exit(r0)
            throw r1
        */
        throw new UnsupportedOperationException("Method not decompiled: o.P00.x():boolean");
    }

    /* JADX WARN: Type inference failed for: r0v0, types: [java.lang.Object, java.util.List] */
    public final List y() {
        ?? r0 = this.f;
        if (r0 != 0) {
            return r0;
        }
        ArrayList arrayList = this.e;
        List arrayList2 = arrayList.isEmpty() ? C0332Mv.l : new ArrayList(arrayList);
        this.f = arrayList2;
        return arrayList2;
    }

    @Override // o.AbstractC0425Qk
    public final void l(Set set) {
    }
}
