package androidx.lifecycle;

import android.os.Bundle;
import androidx.lifecycle.n;
import i5.d;
import java.util.Iterator;

/* loaded from: classes.dex */
public final class m {

    /* renamed from: a, reason: collision with root package name */
    public static final m f4859a = new m();

    /* loaded from: classes.dex */
    public static final class a implements d.a {
        @Override // i5.d.a
        public void a(i5.f owner) {
            kotlin.jvm.internal.t.g(owner, "owner");
            if (!(owner instanceof e1)) {
                throw new IllegalStateException("Internal error: OnRecreation should be registered only on components that implement ViewModelStoreOwner".toString());
            }
            d1 viewModelStore = ((e1) owner).getViewModelStore();
            i5.d savedStateRegistry = owner.getSavedStateRegistry();
            Iterator it = viewModelStore.c().iterator();
            while (it.hasNext()) {
                z0 b10 = viewModelStore.b((String) it.next());
                kotlin.jvm.internal.t.d(b10);
                m.a(b10, savedStateRegistry, owner.getLifecycle());
            }
            if (!viewModelStore.c().isEmpty()) {
                savedStateRegistry.i(a.class);
            }
        }
    }

    /* loaded from: classes.dex */
    public static final class b implements r {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ n f4860p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ i5.d f4861q;

        b(n nVar, i5.d dVar) {
            this.f4860p = nVar;
            this.f4861q = dVar;
        }

        @Override // androidx.lifecycle.r
        public void f(u source, n.a event) {
            kotlin.jvm.internal.t.g(source, "source");
            kotlin.jvm.internal.t.g(event, "event");
            if (event == n.a.ON_START) {
                this.f4860p.d(this);
                this.f4861q.i(a.class);
            }
        }
    }

    private m() {
    }

    public static final void a(z0 viewModel, i5.d registry, n lifecycle) {
        kotlin.jvm.internal.t.g(viewModel, "viewModel");
        kotlin.jvm.internal.t.g(registry, "registry");
        kotlin.jvm.internal.t.g(lifecycle, "lifecycle");
        q0 q0Var = (q0) viewModel.N("androidx.lifecycle.savedstate.vm.tag");
        if (q0Var == null || q0Var.e()) {
            return;
        }
        q0Var.a(registry, lifecycle);
        f4859a.c(registry, lifecycle);
    }

    public static final q0 b(i5.d registry, n lifecycle, String str, Bundle bundle) {
        kotlin.jvm.internal.t.g(registry, "registry");
        kotlin.jvm.internal.t.g(lifecycle, "lifecycle");
        kotlin.jvm.internal.t.d(str);
        q0 q0Var = new q0(str, o0.f4868f.a(registry.b(str), bundle));
        q0Var.a(registry, lifecycle);
        f4859a.c(registry, lifecycle);
        return q0Var;
    }

    private final void c(i5.d dVar, n nVar) {
        n.b b10 = nVar.b();
        if (b10 == n.b.INITIALIZED || b10.isAtLeast(n.b.STARTED)) {
            dVar.i(a.class);
        } else {
            nVar.a(new b(nVar, dVar));
        }
    }
}
