package androidx.lifecycle;

import android.os.Bundle;
import java.util.LinkedHashMap;
import kotlin.coroutines.Continuation;
import kotlin.jvm.functions.Function2;
import org.jetbrains.annotations.NotNull;

/* JADX INFO: loaded from: classes.dex */
public abstract class z {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final eb.e f2722a = new eb.e();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final eb.e f2723b = new eb.e();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final eb.e f2724c = new eb.e();

    public static final void a(s0 s0Var, i3.f fVar, l lVar) {
        nb.g.i(fVar, "registry");
        nb.g.i(lVar, "lifecycle");
        SavedStateHandleController savedStateHandleController = (SavedStateHandleController) s0Var.getCloseable("androidx.lifecycle.savedstate.vm.tag");
        if (savedStateHandleController == null || savedStateHandleController.getIsAttached()) {
            return;
        }
        savedStateHandleController.attachToLifecycle(fVar, lVar);
        e(fVar, lVar);
    }

    public static final l0 b(n1.c cVar) {
        eb.e eVar = f2722a;
        LinkedHashMap linkedHashMap = cVar.f30758a;
        i3.h hVar = (i3.h) linkedHashMap.get(eVar);
        if (hVar == null) {
            throw new IllegalArgumentException("CreationExtras must have a value by `SAVED_STATE_REGISTRY_OWNER_KEY`");
        }
        z0 z0Var = (z0) linkedHashMap.get(f2723b);
        if (z0Var == null) {
            throw new IllegalArgumentException("CreationExtras must have a value by `VIEW_MODEL_STORE_OWNER_KEY`");
        }
        Bundle bundle = (Bundle) linkedHashMap.get(f2724c);
        String str = (String) linkedHashMap.get(o1.c.f31288a);
        if (str == null) {
            throw new IllegalArgumentException("CreationExtras must have a value by `VIEW_MODEL_KEY`");
        }
        i3.e eVarB = hVar.getSavedStateRegistry().b();
        n0 n0Var = eVarB instanceof n0 ? (n0) eVarB : null;
        if (n0Var == null) {
            throw new IllegalStateException("enableSavedStateHandles() wasn't called prior to createSavedStateHandle() call");
        }
        SavedStateHandlesVM savedStateHandlesVMD = d(z0Var);
        l0 l0Var = savedStateHandlesVMD.getHandles().get(str);
        if (l0Var != null) {
            return l0Var;
        }
        Class[] clsArr = l0.f2662f;
        n0Var.b();
        Bundle bundle2 = n0Var.f2674c;
        Bundle bundle3 = bundle2 != null ? bundle2.getBundle(str) : null;
        Bundle bundle4 = n0Var.f2674c;
        if (bundle4 != null) {
            bundle4.remove(str);
        }
        Bundle bundle5 = n0Var.f2674c;
        if (bundle5 != null && bundle5.isEmpty()) {
            n0Var.f2674c = null;
        }
        l0 l0VarA = k0.a(bundle3, bundle);
        savedStateHandlesVMD.getHandles().put(str, l0VarA);
        return l0VarA;
    }

    public static final void c(i3.h hVar) {
        nb.g.i(hVar, "<this>");
        Lifecycle$State lifecycle$State = ((r) hVar.getLifecycle()).f2692c;
        if (lifecycle$State != Lifecycle$State.f2632b && lifecycle$State != Lifecycle$State.f2633c) {
            throw new IllegalArgumentException("Failed requirement.".toString());
        }
        if (hVar.getSavedStateRegistry().b() == null) {
            n0 n0Var = new n0(hVar.getSavedStateRegistry(), (z0) hVar);
            hVar.getSavedStateRegistry().c("androidx.lifecycle.internal.SavedStateHandlesProvider", n0Var);
            hVar.getLifecycle().a(new SavedStateHandleAttacher(n0Var));
        }
    }

    public static final SavedStateHandlesVM d(z0 z0Var) {
        nb.g.i(z0Var, "<this>");
        return (SavedStateHandlesVM) new x0(z0Var.getViewModelStore(), new m0(), z0Var instanceof h ? ((h) z0Var).getDefaultViewModelCreationExtras() : n1.a.f30757b).f2719a.q(kotlin.jvm.internal.g.a(SavedStateHandlesVM.class), "androidx.lifecycle.internal.SavedStateHandlesVM");
    }

    public static void e(final i3.f fVar, final l lVar) {
        Lifecycle$State lifecycle$State = ((r) lVar).f2692c;
        if (lifecycle$State == Lifecycle$State.f2632b || lifecycle$State.compareTo(Lifecycle$State.f2634d) >= 0) {
            fVar.d();
        } else {
            lVar.a(new LifecycleEventObserver() { // from class: androidx.lifecycle.LegacySavedStateHandleController$tryToAddRecreator$1
                @Override // androidx.lifecycle.LifecycleEventObserver
                public void onStateChanged(@NotNull p pVar, @NotNull Lifecycle$Event lifecycle$Event) {
                    nb.g.i(pVar, "source");
                    nb.g.i(lifecycle$Event, "event");
                    if (lifecycle$Event == Lifecycle$Event.ON_START) {
                        lVar.b(this);
                        fVar.d();
                    }
                }
            });
        }
    }

    public static final Object f(l lVar, Lifecycle$State lifecycle$State, Function2 function2, Continuation continuation) {
        be.d dVar = kotlinx.coroutines.h0.f29440a;
        return hb.a.G0(continuation, ((ae.d) kotlinx.coroutines.internal.n.f29483a).f453f, new PausingDispatcherKt$whenStateAtLeast$2(lVar, lifecycle$State, function2, null));
    }
}
