package o;

import android.content.Intent;
import android.os.Bundle;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.NoSuchElementException;
import java.util.Objects;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public abstract class E1 {
    public final LinkedHashMap a = new LinkedHashMap();
    public final LinkedHashMap b = new LinkedHashMap();
    public final LinkedHashMap c = new LinkedHashMap();
    public final ArrayList d = new ArrayList();
    public final transient LinkedHashMap e = new LinkedHashMap();
    public final LinkedHashMap f = new LinkedHashMap();
    public final Bundle g = new Bundle();

    public final boolean a(int i, int i2, Intent intent) {
        String str = (String) this.a.get(Integer.valueOf(i));
        if (str == null) {
            return false;
        }
        B1 b1 = (B1) this.e.get(str);
        if ((b1 != null ? b1.a : null) != null) {
            ArrayList arrayList = this.d;
            if (arrayList.contains(str)) {
                b1.a.c(b1.b.c(intent, i2));
                arrayList.remove(str);
                return true;
            }
        }
        this.f.remove(str);
        this.g.putParcelable(str, new C2582u1(intent, i2));
        return true;
    }

    public abstract void b(int i, AbstractC2772w1 abstractC2772w1, Object obj);

    public final D1 c(String str, AbstractC2772w1 abstractC2772w1, InterfaceC2677v1 interfaceC2677v1) {
        e(str);
        this.e.put(str, new B1(abstractC2772w1, interfaceC2677v1));
        LinkedHashMap linkedHashMap = this.f;
        if (linkedHashMap.containsKey(str)) {
            Object obj = linkedHashMap.get(str);
            linkedHashMap.remove(str);
            interfaceC2677v1.c(obj);
        }
        Bundle bundle = this.g;
        C2582u1 c2582u1 = (C2582u1) AbstractC2841wm0.w(str, bundle);
        if (c2582u1 != null) {
            bundle.remove(str);
            interfaceC2677v1.c(abstractC2772w1.c(c2582u1.m, c2582u1.l));
        }
        return new D1(this, str, abstractC2772w1, 1);
    }

    public final D1 d(final String str, InterfaceC0898cL interfaceC0898cL, final AbstractC2772w1 abstractC2772w1, final InterfaceC2677v1 interfaceC2677v1) {
        WK lifecycle = interfaceC0898cL.getLifecycle();
        if (lifecycle.b().a(VK.f372o)) {
            throw new IllegalStateException(("LifecycleOwner " + interfaceC0898cL + " is attempting to register while current state is " + lifecycle.b() + ". LifecycleOwners must call register before they are STARTED.").toString());
        }
        e(str);
        LinkedHashMap linkedHashMap = this.c;
        C1 c1 = (C1) linkedHashMap.get(str);
        if (c1 == null) {
            c1 = new C1(lifecycle);
        }
        InterfaceC0707aL interfaceC0707aL = new InterfaceC0707aL() { // from class: o.A1
            @Override // o.InterfaceC0707aL
            public final void f(InterfaceC0898cL interfaceC0898cL2, UK uk) {
                E1 e1 = this.l;
                LinkedHashMap linkedHashMap2 = e1.e;
                UK uk2 = UK.ON_START;
                String str2 = str;
                if (uk2 != uk) {
                    if (UK.ON_STOP == uk) {
                        linkedHashMap2.remove(str2);
                        return;
                    } else {
                        if (UK.ON_DESTROY == uk) {
                            e1.f(str2);
                            return;
                        }
                        return;
                    }
                }
                Bundle bundle = e1.g;
                LinkedHashMap linkedHashMap3 = e1.f;
                AbstractC2772w1 abstractC2772w12 = abstractC2772w1;
                InterfaceC2677v1 interfaceC2677v12 = interfaceC2677v1;
                linkedHashMap2.put(str2, new B1(abstractC2772w12, interfaceC2677v12));
                if (linkedHashMap3.containsKey(str2)) {
                    Object obj = linkedHashMap3.get(str2);
                    linkedHashMap3.remove(str2);
                    interfaceC2677v12.c(obj);
                }
                C2582u1 c2582u1 = (C2582u1) AbstractC2841wm0.w(str2, bundle);
                if (c2582u1 != null) {
                    bundle.remove(str2);
                    interfaceC2677v12.c(abstractC2772w12.c(c2582u1.m, c2582u1.l));
                }
            }
        };
        c1.a.a(interfaceC0707aL);
        c1.b.add(interfaceC0707aL);
        linkedHashMap.put(str, c1);
        return new D1(this, str, abstractC2772w1, 0);
    }

    public final void e(String str) {
        LinkedHashMap linkedHashMap = this.b;
        if (((Integer) linkedHashMap.get(str)) != null) {
            return;
        }
        K0 k0 = new K0(6);
        Iterator it = new C3028yl(new GD(k0, new C2769w(28, k0))).iterator();
        while (it.hasNext()) {
            Number number = (Number) it.next();
            Integer numValueOf = Integer.valueOf(number.intValue());
            LinkedHashMap linkedHashMap2 = this.a;
            if (!linkedHashMap2.containsKey(numValueOf)) {
                int iIntValue = number.intValue();
                linkedHashMap2.put(Integer.valueOf(iIntValue), str);
                linkedHashMap.put(str, Integer.valueOf(iIntValue));
                return;
            }
        }
        throw new NoSuchElementException("Sequence contains no element matching the predicate.");
    }

    public final void f(String str) {
        Integer num;
        if (!this.d.contains(str) && (num = (Integer) this.b.remove(str)) != null) {
            this.a.remove(num);
        }
        this.e.remove(str);
        LinkedHashMap linkedHashMap = this.f;
        if (linkedHashMap.containsKey(str)) {
            Objects.toString(linkedHashMap.get(str));
            linkedHashMap.remove(str);
        }
        Bundle bundle = this.g;
        if (bundle.containsKey(str)) {
            Objects.toString((C2582u1) AbstractC2841wm0.w(str, bundle));
            bundle.remove(str);
        }
        LinkedHashMap linkedHashMap2 = this.c;
        C1 c1 = (C1) linkedHashMap2.get(str);
        if (c1 != null) {
            ArrayList arrayList = c1.b;
            int size = arrayList.size();
            int i = 0;
            while (i < size) {
                Object obj = arrayList.get(i);
                i++;
                c1.a.c((InterfaceC0707aL) obj);
            }
            arrayList.clear();
            linkedHashMap2.remove(str);
        }
    }
}
