package i3;

import android.os.Bundle;
import androidx.lifecycle.Lifecycle$Event;
import androidx.lifecycle.Lifecycle$State;
import androidx.lifecycle.LifecycleEventObserver;
import androidx.lifecycle.l;
import androidx.lifecycle.p;
import androidx.lifecycle.r;
import androidx.savedstate.Recreator;
import java.util.Map;

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

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

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

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

    public g(h hVar) {
        this.f26534a = hVar;
    }

    public final void a() {
        h hVar = this.f26534a;
        l lifecycle = hVar.getLifecycle();
        if (((r) lifecycle).f2692c != Lifecycle$State.f2632b) {
            throw new IllegalStateException("Restarter must be created only during owner's initialization stage".toString());
        }
        lifecycle.a(new Recreator(hVar));
        final f fVar = this.f26535b;
        fVar.getClass();
        if (!(!fVar.f26529b)) {
            throw new IllegalStateException("SavedStateRegistry was already attached.".toString());
        }
        lifecycle.a(new LifecycleEventObserver() { // from class: i3.c
            @Override // androidx.lifecycle.LifecycleEventObserver
            public final void onStateChanged(p pVar, Lifecycle$Event lifecycle$Event) {
                f fVar2 = fVar;
                nb.g.i(fVar2, "this$0");
                nb.g.i(pVar, "<anonymous parameter 0>");
                nb.g.i(lifecycle$Event, "event");
                if (lifecycle$Event == Lifecycle$Event.ON_START) {
                    fVar2.f26533f = true;
                } else if (lifecycle$Event == Lifecycle$Event.ON_STOP) {
                    fVar2.f26533f = false;
                }
            }
        });
        fVar.f26529b = true;
        this.f26536c = true;
    }

    public final void b(Bundle bundle) {
        if (!this.f26536c) {
            a();
        }
        r rVar = (r) this.f26534a.getLifecycle();
        if (!(!(rVar.f2692c.compareTo(Lifecycle$State.f2634d) >= 0))) {
            throw new IllegalStateException(("performRestore cannot be called when owner is " + rVar.f2692c).toString());
        }
        f fVar = this.f26535b;
        if (!fVar.f26529b) {
            throw new IllegalStateException("You must call performAttach() before calling performRestore(Bundle).".toString());
        }
        if (!(!fVar.f26531d)) {
            throw new IllegalStateException("SavedStateRegistry was already restored.".toString());
        }
        fVar.f26530c = bundle != null ? bundle.getBundle("androidx.lifecycle.BundlableSavedStateRegistry.key") : null;
        fVar.f26531d = true;
    }

    public final void c(Bundle bundle) {
        nb.g.i(bundle, "outBundle");
        f fVar = this.f26535b;
        fVar.getClass();
        Bundle bundle2 = new Bundle();
        Bundle bundle3 = fVar.f26530c;
        if (bundle3 != null) {
            bundle2.putAll(bundle3);
        }
        n.g gVar = fVar.f26528a;
        gVar.getClass();
        n.d dVar = new n.d(gVar);
        gVar.f30715c.put(dVar, Boolean.FALSE);
        while (dVar.hasNext()) {
            Map.Entry entry = (Map.Entry) dVar.next();
            bundle2.putBundle((String) entry.getKey(), ((e) entry.getValue()).a());
        }
        if (bundle2.isEmpty()) {
            return;
        }
        bundle.putBundle("androidx.lifecycle.BundlableSavedStateRegistry.key", bundle2);
    }
}
