package n2;

import android.os.Bundle;
import androidx.lifecycle.C1103l;
import androidx.navigation.C1134i;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import kotlin.jvm.internal.o;
import p2.C2720a;

/* JADX INFO: renamed from: n2.g, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C2616g {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final C2720a f21612a;

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

    public C2616g(C2720a c2720a) {
        this.f21612a = c2720a;
    }

    public final Bundle a(String key) {
        o.h(key, "key");
        C2720a c2720a = this.f21612a;
        if (!c2720a.f22961b) {
            throw new IllegalStateException("You can 'consumeRestoredStateForKey' only after the corresponding component has moved to the 'CREATED' state");
        }
        Bundle bundle = (Bundle) c2720a.f22967h;
        if (bundle == null) {
            return null;
        }
        Bundle bundleO = bundle.containsKey(key) ? AbstractC2612c.o(bundle, key) : null;
        bundle.remove(key);
        if (bundle.isEmpty()) {
            c2720a.f22967h = null;
        }
        return bundleO;
    }

    public final InterfaceC2615f b() {
        InterfaceC2615f interfaceC2615f;
        C2720a c2720a = this.f21612a;
        synchronized (((C1134i) c2720a.f22965f)) {
            Iterator it = ((LinkedHashMap) c2720a.f22966g).entrySet().iterator();
            do {
                interfaceC2615f = null;
                if (!it.hasNext()) {
                    break;
                }
                Map.Entry entry = (Map.Entry) it.next();
                String str = (String) entry.getKey();
                InterfaceC2615f interfaceC2615f2 = (InterfaceC2615f) entry.getValue();
                if (o.c(str, "androidx.lifecycle.internal.SavedStateHandlesProvider")) {
                    interfaceC2615f = interfaceC2615f2;
                }
            } while (interfaceC2615f == null);
        }
        return interfaceC2615f;
    }

    public final void c(String str, InterfaceC2615f provider) {
        o.h(provider, "provider");
        C2720a c2720a = this.f21612a;
        synchronized (((C1134i) c2720a.f22965f)) {
            if (((LinkedHashMap) c2720a.f22966g).containsKey(str)) {
                throw new IllegalArgumentException("SavedStateProvider with the given key is already registered");
            }
            ((LinkedHashMap) c2720a.f22966g).put(str, provider);
        }
    }

    public final void d() {
        if (!this.f21612a.f22962c) {
            throw new IllegalStateException("Can not perform this action after onSaveInstanceState");
        }
        C2610a c2610a = this.f21613b;
        if (c2610a == null) {
            c2610a = new C2610a(this);
        }
        this.f21613b = c2610a;
        try {
            C1103l.class.getDeclaredConstructor(new Class[0]);
            C2610a c2610a2 = this.f21613b;
            if (c2610a2 != null) {
                c2610a2.f21607a.add(C1103l.class.getName());
            }
        } catch (NoSuchMethodException e6) {
            throw new IllegalArgumentException("Class " + C1103l.class.getSimpleName() + " must have default constructor in order to be automatically recreated", e6);
        }
    }
}
