package g;

import M2.C0556x0;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import androidx.lifecycle.EnumC1108q;
import androidx.lifecycle.InterfaceC1111u;
import androidx.lifecycle.InterfaceC1113w;
import androidx.lifecycle.r;
import d3.C1917q0;
import h.AbstractC2068b;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.NoSuchElementException;
import kotlin.jvm.internal.o;

/* JADX INFO: renamed from: g.i, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC2055i {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final LinkedHashMap f16446a = new LinkedHashMap();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final LinkedHashMap f16447b = new LinkedHashMap();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final LinkedHashMap f16448c = new LinkedHashMap();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final ArrayList f16449d = new ArrayList();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final transient LinkedHashMap f16450e = new LinkedHashMap();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final LinkedHashMap f16451f = new LinkedHashMap();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final Bundle f16452g = new Bundle();

    public final boolean a(int i6, int i7, Intent intent) {
        String str = (String) this.f16446a.get(Integer.valueOf(i6));
        if (str == null) {
            return false;
        }
        C2051e c2051e = (C2051e) this.f16450e.get(str);
        if ((c2051e != null ? c2051e.f16437a : null) != null) {
            ArrayList arrayList = this.f16449d;
            if (arrayList.contains(str)) {
                c2051e.f16437a.onActivityResult(c2051e.f16438b.parseResult(i7, intent));
                arrayList.remove(str);
                return true;
            }
        }
        this.f16451f.remove(str);
        this.f16452g.putParcelable(str, new C2047a(i7, intent));
        return true;
    }

    public abstract void b(int i6, AbstractC2068b abstractC2068b, Object obj);

    public final C2054h c(String key, InterfaceC1113w lifecycleOwner, AbstractC2068b contract, InterfaceC2048b callback) {
        o.h(key, "key");
        o.h(lifecycleOwner, "lifecycleOwner");
        o.h(contract, "contract");
        o.h(callback, "callback");
        r lifecycle = lifecycleOwner.getLifecycle();
        if (lifecycle.getCurrentState().compareTo(EnumC1108q.f12183d) >= 0) {
            throw new IllegalStateException(("LifecycleOwner " + lifecycleOwner + " is attempting to register while current state is " + lifecycle.getCurrentState() + ". LifecycleOwners must call register before they are STARTED.").toString());
        }
        e(key);
        LinkedHashMap linkedHashMap = this.f16448c;
        C2052f c2052f = (C2052f) linkedHashMap.get(key);
        if (c2052f == null) {
            c2052f = new C2052f(lifecycle);
        }
        C1917q0 c1917q0 = new C1917q0(this, key, callback, contract, 1);
        c2052f.f16439a.addObserver(c1917q0);
        c2052f.f16440b.add(c1917q0);
        linkedHashMap.put(key, c2052f);
        return new C2054h(this, key, contract, 0);
    }

    public final C2054h d(String key, AbstractC2068b abstractC2068b, InterfaceC2048b interfaceC2048b) {
        o.h(key, "key");
        e(key);
        this.f16450e.put(key, new C2051e(abstractC2068b, interfaceC2048b));
        LinkedHashMap linkedHashMap = this.f16451f;
        if (linkedHashMap.containsKey(key)) {
            Object obj = linkedHashMap.get(key);
            linkedHashMap.remove(key);
            interfaceC2048b.onActivityResult(obj);
        }
        Bundle bundle = this.f16452g;
        C2047a c2047a = (C2047a) android.support.v4.media.session.b.s(bundle, key, C2047a.class);
        if (c2047a != null) {
            bundle.remove(key);
            interfaceC2048b.onActivityResult(abstractC2068b.parseResult(c2047a.f16435a, c2047a.f16436b));
        }
        return new C2054h(this, key, abstractC2068b, 1);
    }

    public final void e(String str) {
        LinkedHashMap linkedHashMap = this.f16447b;
        if (((Integer) linkedHashMap.get(str)) != null) {
            return;
        }
        for (Number number : new R4.a(new R4.j(0, C2053g.f16441a, new C0556x0(27)))) {
            int iIntValue = number.intValue();
            LinkedHashMap linkedHashMap2 = this.f16446a;
            if (!linkedHashMap2.containsKey(Integer.valueOf(iIntValue))) {
                int iIntValue2 = number.intValue();
                linkedHashMap2.put(Integer.valueOf(iIntValue2), str);
                linkedHashMap.put(str, Integer.valueOf(iIntValue2));
                return;
            }
        }
        throw new NoSuchElementException("Sequence contains no element matching the predicate.");
    }

    public final void f(String key) {
        Integer num;
        o.h(key, "key");
        if (!this.f16449d.contains(key) && (num = (Integer) this.f16447b.remove(key)) != null) {
            this.f16446a.remove(num);
        }
        this.f16450e.remove(key);
        LinkedHashMap linkedHashMap = this.f16451f;
        if (linkedHashMap.containsKey(key)) {
            StringBuilder sbS = com.google.android.recaptcha.internal.a.s("Dropping pending result for request ", key, ": ");
            sbS.append(linkedHashMap.get(key));
            Log.w("ActivityResultRegistry", sbS.toString());
            linkedHashMap.remove(key);
        }
        Bundle bundle = this.f16452g;
        if (bundle.containsKey(key)) {
            Log.w("ActivityResultRegistry", "Dropping pending result for request " + key + ": " + ((C2047a) android.support.v4.media.session.b.s(bundle, key, C2047a.class)));
            bundle.remove(key);
        }
        LinkedHashMap linkedHashMap2 = this.f16448c;
        C2052f c2052f = (C2052f) linkedHashMap2.get(key);
        if (c2052f != null) {
            ArrayList arrayList = c2052f.f16440b;
            Iterator it = arrayList.iterator();
            while (it.hasNext()) {
                c2052f.f16439a.removeObserver((InterfaceC1111u) it.next());
            }
            arrayList.clear();
            linkedHashMap2.remove(key);
        }
    }
}
