package i3;

import android.os.Bundle;
import androidx.lifecycle.i;
import e.n;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

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

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

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

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

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final n.g f26528a = new n.g();

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

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

    public final e b() {
        String str;
        e eVar;
        Iterator it = this.f26528a.iterator();
        do {
            n.e eVar2 = (n.e) it;
            if (!eVar2.hasNext()) {
                return null;
            }
            Map.Entry entry = (Map.Entry) eVar2.next();
            nb.g.h(entry, "components");
            str = (String) entry.getKey();
            eVar = (e) entry.getValue();
        } while (!nb.g.c(str, "androidx.lifecycle.internal.SavedStateHandlesProvider"));
        return eVar;
    }

    public final void c(String str, e eVar) {
        Object obj;
        nb.g.i(str, "key");
        nb.g.i(eVar, "provider");
        n.g gVar = this.f26528a;
        n.c cVar = gVar.get(str);
        if (cVar != null) {
            obj = cVar.f30705b;
        } else {
            n.c cVar2 = new n.c(str, eVar);
            gVar.f30716d++;
            n.c cVar3 = gVar.f30714b;
            if (cVar3 == null) {
                gVar.f30713a = cVar2;
                gVar.f30714b = cVar2;
            } else {
                cVar3.f30706c = cVar2;
                cVar2.f30707d = cVar3;
                gVar.f30714b = cVar2;
            }
            obj = null;
        }
        if (((e) obj) != null) {
            throw new IllegalArgumentException("SavedStateProvider with the given key is already registered".toString());
        }
    }

    public final void d() {
        if (!this.f26533f) {
            throw new IllegalStateException("Can not perform this action after onSaveInstanceState".toString());
        }
        n nVar = this.f26532e;
        if (nVar == null) {
            nVar = new n(this);
        }
        this.f26532e = nVar;
        try {
            i.class.getDeclaredConstructor(new Class[0]);
            n nVar2 = this.f26532e;
            if (nVar2 != null) {
                ((Set) nVar2.f25304b).add(i.class.getName());
            }
        } catch (NoSuchMethodException e10) {
            throw new IllegalArgumentException("Class " + i.class.getSimpleName() + " must have default constructor in order to be automatically recreated", e10);
        }
    }
}
