package o;

import android.os.Looper;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.eL, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C1089eL extends WK {
    public final boolean b = true;
    public C0127Ex c = new C0127Ex();
    public VK d;
    public final WeakReference e;
    public int f;
    public boolean g;
    public boolean h;
    public final ArrayList i;
    public final Ba0 j;

    public C1089eL(InterfaceC0898cL interfaceC0898cL) {
        VK vk = VK.m;
        this.d = vk;
        this.i = new ArrayList();
        this.e = new WeakReference(interfaceC0898cL);
        this.j = AbstractC0752ap.h(vk);
    }

    @Override // o.WK
    public final void a(InterfaceC0803bL interfaceC0803bL) {
        InterfaceC0707aL c2184pq;
        Object obj;
        InterfaceC0898cL interfaceC0898cL;
        e("addObserver");
        VK vk = this.d;
        VK vk2 = VK.l;
        if (vk != vk2) {
            vk2 = VK.m;
        }
        C0994dL c0994dL = new C0994dL();
        HashMap map = AbstractC1185fL.a;
        boolean z = interfaceC0803bL instanceof InterfaceC0707aL;
        boolean z2 = interfaceC0803bL instanceof InterfaceC1994nq;
        int i = 2;
        Object obj2 = null;
        if (z && z2) {
            c2184pq = new C2184pq(i, (InterfaceC1994nq) interfaceC0803bL, (InterfaceC0707aL) interfaceC0803bL);
        } else if (z2) {
            c2184pq = new C2184pq(i, (InterfaceC1994nq) interfaceC0803bL, obj2);
        } else if (z) {
            c2184pq = (InterfaceC0707aL) interfaceC0803bL;
        } else {
            Class<?> cls = interfaceC0803bL.getClass();
            if (AbstractC1185fL.b(cls) == 2) {
                List list = (List) AbstractC1185fL.b.get(cls);
                if (list.size() == 1) {
                    AbstractC1185fL.a((Constructor) list.get(0), interfaceC0803bL);
                    c2184pq = new L80();
                } else {
                    int size = list.size();
                    InterfaceC3078zD[] interfaceC3078zDArr = new InterfaceC3078zD[size];
                    for (int i2 = 0; i2 < size; i2++) {
                        AbstractC1185fL.a((Constructor) list.get(i2), interfaceC0803bL);
                        interfaceC3078zDArr[i2] = null;
                    }
                    c2184pq = new S00(i, interfaceC3078zDArr);
                }
            } else {
                c2184pq = new C2184pq(interfaceC0803bL);
            }
        }
        c0994dL.b = c2184pq;
        c0994dL.a = vk2;
        C0127Ex c0127Ex = this.c;
        R30 r30A = c0127Ex.a(interfaceC0803bL);
        if (r30A != null) {
            obj = r30A.m;
        } else {
            HashMap map2 = c0127Ex.p;
            R30 r30 = new R30(interfaceC0803bL, c0994dL);
            c0127Ex.f351o++;
            R30 r302 = c0127Ex.m;
            if (r302 == null) {
                c0127Ex.l = r30;
                c0127Ex.m = r30;
            } else {
                r302.n = r30;
                r30.f307o = r302;
                c0127Ex.m = r30;
            }
            map2.put(interfaceC0803bL, r30);
            obj = null;
        }
        if (((C0994dL) obj) == null && (interfaceC0898cL = (InterfaceC0898cL) this.e.get()) != null) {
            i = (this.f != 0 || this.g) ? 1 : 0;
            VK vkD = d(interfaceC0803bL);
            this.f++;
            while (c0994dL.a.compareTo(vkD) < 0 && this.c.p.containsKey(interfaceC0803bL)) {
                VK vk3 = c0994dL.a;
                ArrayList arrayList = this.i;
                arrayList.add(vk3);
                SK sk = UK.Companion;
                VK vk4 = c0994dL.a;
                sk.getClass();
                int iOrdinal = vk4.ordinal();
                UK uk = iOrdinal != 1 ? iOrdinal != 2 ? iOrdinal != 3 ? null : UK.ON_RESUME : UK.ON_START : UK.ON_CREATE;
                if (uk == null) {
                    throw new IllegalStateException("no event up from " + c0994dL.a);
                }
                c0994dL.a(interfaceC0898cL, uk);
                arrayList.remove(arrayList.size() - 1);
                vkD = d(interfaceC0803bL);
            }
            if (i == 0) {
                h();
            }
            this.f--;
        }
    }

    @Override // o.WK
    public final VK b() {
        return this.d;
    }

    @Override // o.WK
    public final void c(InterfaceC0803bL interfaceC0803bL) {
        e("removeObserver");
        this.c.b(interfaceC0803bL);
    }

    public final VK d(InterfaceC0803bL interfaceC0803bL) {
        HashMap map = this.c.p;
        R30 r30 = map.containsKey(interfaceC0803bL) ? ((R30) map.get(interfaceC0803bL)).f307o : null;
        VK vk = r30 != null ? ((C0994dL) r30.m).a : null;
        ArrayList arrayList = this.i;
        VK vk2 = arrayList.isEmpty() ? null : (VK) arrayList.get(arrayList.size() - 1);
        VK vk3 = this.d;
        if (vk == null || vk.compareTo(vk3) >= 0) {
            vk = vk3;
        }
        return (vk2 == null || vk2.compareTo(vk) >= 0) ? vk : vk2;
    }

    public final void e(String str) {
        if (this.b) {
            W8.b0().f.getClass();
            if (Looper.getMainLooper().getThread() != Thread.currentThread()) {
                throw new IllegalStateException(AbstractC2462sn.j("Method ", str, " must be called on the main thread").toString());
            }
        }
    }

    public final void f(UK uk) {
        e("handleLifecycleEvent");
        g(uk.a());
    }

    public final void g(VK vk) {
        if (this.d == vk) {
            return;
        }
        InterfaceC0898cL interfaceC0898cL = (InterfaceC0898cL) this.e.get();
        VK vk2 = this.d;
        VK vk3 = VK.m;
        VK vk4 = VK.l;
        if (vk2 == vk3 && vk == vk4) {
            throw new IllegalStateException(("State must be at least '" + VK.n + "' to be moved to '" + vk + "' in component " + interfaceC0898cL).toString());
        }
        if (vk2 == vk4 && vk2 != vk) {
            throw new IllegalStateException(("State is '" + vk4 + "' and cannot be moved to `" + vk + "` in component " + interfaceC0898cL).toString());
        }
        this.d = vk;
        if (this.g || this.f != 0) {
            this.h = true;
            return;
        }
        this.g = true;
        h();
        this.g = false;
        if (this.d == vk4) {
            this.c = new C0127Ex();
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:11:0x0029, code lost:
    
        r11.h = false;
        r0 = r11.d;
        r1 = r11.j;
        r1.getClass();
     */
    /* JADX WARN: Code restructure failed: missing block: B:12:0x0032, code lost:
    
        if (r0 != null) goto L14;
     */
    /* JADX WARN: Code restructure failed: missing block: B:13:0x0034, code lost:
    
        r0 = o.F3.f;
     */
    /* JADX WARN: Code restructure failed: missing block: B:14:0x0036, code lost:
    
        r1.i(null, r0);
     */
    /* JADX WARN: Code restructure failed: missing block: B:15:0x0039, code lost:
    
        return;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void h() {
        /*
            Method dump skipped, instructions count: 384
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C1089eL.h():void");
    }
}
