package v0;

import android.os.Bundle;
import androidx.lifecycle.C0304k;
import java.util.Iterator;
import java.util.Map;
import o.C0919b;
import r4.AbstractC0983h;

/* JADX INFO: loaded from: classes.dex */
public final class e {

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Bundle f10398c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f10399d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public C1073a f10400e;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final o.f f10396a = new o.f();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public boolean f10401f = true;

    public final Bundle a(String str) {
        if (!this.f10399d) {
            throw new IllegalStateException("You can consumeRestoredStateForKey only after super.onCreate of corresponding component");
        }
        Bundle bundle = this.f10398c;
        if (bundle == null) {
            return null;
        }
        Bundle bundle2 = bundle.getBundle(str);
        Bundle bundle3 = this.f10398c;
        if (bundle3 != null) {
            bundle3.remove(str);
        }
        Bundle bundle4 = this.f10398c;
        if (bundle4 != null && !bundle4.isEmpty()) {
            return bundle2;
        }
        this.f10398c = null;
        return bundle2;
    }

    public final d b() {
        String str;
        d dVar;
        Iterator it = this.f10396a.iterator();
        do {
            C0919b c0919b = (C0919b) it;
            if (!c0919b.hasNext()) {
                return null;
            }
            Map.Entry entry = (Map.Entry) c0919b.next();
            AbstractC0983h.d("components", entry);
            str = (String) entry.getKey();
            dVar = (d) entry.getValue();
        } while (!AbstractC0983h.a(str, "androidx.lifecycle.internal.SavedStateHandlesProvider"));
        return dVar;
    }

    public final void c(String str, d dVar) {
        AbstractC0983h.e("provider", dVar);
        if (((d) this.f10396a.b(str, dVar)) != null) {
            throw new IllegalArgumentException("SavedStateProvider with the given key is already registered");
        }
    }

    public final void d() {
        if (!this.f10401f) {
            throw new IllegalStateException("Can not perform this action after onSaveInstanceState");
        }
        C1073a c1073a = this.f10400e;
        if (c1073a == null) {
            c1073a = new C1073a(this);
        }
        this.f10400e = c1073a;
        try {
            C0304k.class.getDeclaredConstructor(new Class[0]);
            C1073a c1073a2 = this.f10400e;
            if (c1073a2 != null) {
                c1073a2.f10393a.add(C0304k.class.getName());
            }
        } catch (NoSuchMethodException e2) {
            throw new IllegalArgumentException("Class " + C0304k.class.getSimpleName() + " must have default constructor in order to be automatically recreated", e2);
        }
    }
}
