package c.o;

import android.annotation.SuppressLint;
import android.os.Bundle;
import androidx.savedstate.Recreator;
import c.c.a.b.b;
import g.h0.c.l;
import g.i;
import java.util.Iterator;
import java.util.Map;

/* JADX INFO: compiled from: SavedStateRegistry.kt */
/* JADX INFO: loaded from: classes.dex */
@i
@SuppressLint({"RestrictedApi"})
public final class b {

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

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public Recreator.a f1915e;
    public final c.c.a.b.b<String, InterfaceC0024b> a = new c.c.a.b.b<>();

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

    /* JADX INFO: compiled from: SavedStateRegistry.kt */
    @i
    public interface a {
        void a(d dVar);
    }

    /* JADX INFO: renamed from: c.o.b$b, reason: collision with other inner class name */
    /* JADX INFO: compiled from: SavedStateRegistry.kt */
    @i
    public interface InterfaceC0024b {
        Bundle a();
    }

    public final Bundle a(String str) {
        l.f(str, "key");
        if (!this.f1914d) {
            throw new IllegalStateException("You can consumeRestoredStateForKey only after super.onCreate of corresponding component".toString());
        }
        Bundle bundle = this.f1913c;
        if (bundle == null) {
            return null;
        }
        Bundle bundle2 = bundle != null ? bundle.getBundle(str) : null;
        Bundle bundle3 = this.f1913c;
        if (bundle3 != null) {
            bundle3.remove(str);
        }
        Bundle bundle4 = this.f1913c;
        boolean z = false;
        if (bundle4 != null && !bundle4.isEmpty()) {
            z = true;
        }
        if (!z) {
            this.f1913c = null;
        }
        return bundle2;
    }

    public final InterfaceC0024b b(String str) {
        String str2;
        InterfaceC0024b interfaceC0024b;
        l.f(str, "key");
        Iterator<Map.Entry<String, InterfaceC0024b>> it = this.a.iterator();
        do {
            b.e eVar = (b.e) it;
            if (!eVar.hasNext()) {
                return null;
            }
            Map.Entry entry = (Map.Entry) eVar.next();
            l.e(entry, "components");
            str2 = (String) entry.getKey();
            interfaceC0024b = (InterfaceC0024b) entry.getValue();
        } while (!l.a(str2, str));
        return interfaceC0024b;
    }

    public final void c(String str, InterfaceC0024b interfaceC0024b) {
        l.f(str, "key");
        l.f(interfaceC0024b, "provider");
        if (!(this.a.d(str, interfaceC0024b) == null)) {
            throw new IllegalArgumentException("SavedStateProvider with the given key is already registered".toString());
        }
    }

    public final void d(Class<? extends a> cls) {
        l.f(cls, "clazz");
        if (!this.f1916f) {
            throw new IllegalStateException("Can not perform this action after onSaveInstanceState".toString());
        }
        Recreator.a aVar = this.f1915e;
        if (aVar == null) {
            aVar = new Recreator.a(this);
        }
        this.f1915e = aVar;
        try {
            cls.getDeclaredConstructor(new Class[0]);
            Recreator.a aVar2 = this.f1915e;
            if (aVar2 != null) {
                String name = cls.getName();
                l.e(name, "clazz.name");
                l.f(name, "className");
                aVar2.a.add(name);
            }
        } catch (NoSuchMethodException e2) {
            StringBuilder sbB = d.b.a.a.a.B("Class ");
            sbB.append(cls.getSimpleName());
            sbB.append(" must have default constructor in order to be automatically recreated");
            throw new IllegalArgumentException(sbB.toString(), e2);
        }
    }
}
