package v0;

import android.os.Bundle;
import androidx.fragment.app.N;
import androidx.lifecycle.EnumC0307n;
import androidx.lifecycle.InterfaceC0311s;
import androidx.lifecycle.InterfaceC0313u;
import androidx.lifecycle.S;
import androidx.lifecycle.X;
import androidx.lifecycle.c0;
import androidx.lifecycle.d0;
import d.AbstractActivityC0518l;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import p0.AbstractC0928a;
import r4.AbstractC0983h;

/* JADX INFO: loaded from: classes.dex */
public final class b implements InterfaceC0311s {

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final /* synthetic */ int f10394k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final g f10395l;

    public /* synthetic */ b(g gVar, int i) {
        this.f10394k = i;
        this.f10395l = gVar;
    }

    @Override // androidx.lifecycle.InterfaceC0311s
    public final void a(InterfaceC0313u interfaceC0313u, EnumC0307n enumC0307n) {
        switch (this.f10394k) {
            case 0:
                if (enumC0307n != EnumC0307n.ON_CREATE) {
                    throw new AssertionError("Next event must be ON_CREATE");
                }
                interfaceC0313u.getLifecycle().b(this);
                g gVar = this.f10395l;
                Bundle bundleA = gVar.getSavedStateRegistry().a("androidx.savedstate.Restarter");
                if (bundleA == null) {
                    return;
                }
                ArrayList<String> stringArrayList = bundleA.getStringArrayList("classes_to_restore");
                if (stringArrayList == null) {
                    throw new IllegalStateException("Bundle with restored state for the component \"androidx.savedstate.Restarter\" must contain list of strings by the key \"classes_to_restore\"");
                }
                for (String str : stringArrayList) {
                    try {
                        Class<? extends U> clsAsSubclass = Class.forName(str, false, b.class.getClassLoader()).asSubclass(c.class);
                        AbstractC0983h.d("{\n                Class.…class.java)\n            }", clsAsSubclass);
                        try {
                            Constructor declaredConstructor = clsAsSubclass.getDeclaredConstructor(new Class[0]);
                            declaredConstructor.setAccessible(true);
                            try {
                                Object objNewInstance = declaredConstructor.newInstance(new Object[0]);
                                AbstractC0983h.d("{\n                constr…wInstance()\n            }", objNewInstance);
                                if (!(gVar instanceof d0)) {
                                    throw new IllegalStateException("Internal error: OnRecreation should be registered only on components that implement ViewModelStoreOwner");
                                }
                                c0 viewModelStore = ((d0) gVar).getViewModelStore();
                                e savedStateRegistry = gVar.getSavedStateRegistry();
                                viewModelStore.getClass();
                                LinkedHashMap linkedHashMap = viewModelStore.f4466a;
                                for (String str2 : new HashSet(linkedHashMap.keySet())) {
                                    AbstractC0983h.e("key", str2);
                                    X x5 = (X) linkedHashMap.get(str2);
                                    AbstractC0983h.b(x5);
                                    S.a(x5, savedStateRegistry, gVar.getLifecycle());
                                }
                                if (!new HashSet(linkedHashMap.keySet()).isEmpty()) {
                                    savedStateRegistry.d();
                                }
                            } catch (Exception e2) {
                                throw new RuntimeException(s0.c.f("Failed to instantiate ", str), e2);
                            }
                        } catch (NoSuchMethodException e6) {
                            throw new IllegalStateException("Class " + clsAsSubclass.getSimpleName() + " must have default constructor in order to be automatically recreated", e6);
                        }
                    } catch (ClassNotFoundException e7) {
                        throw new RuntimeException(AbstractC0928a.l("Class ", str, " wasn't found"), e7);
                    }
                }
                return;
            default:
                N n5 = (N) this.f10395l;
                AbstractActivityC0518l.access$ensureViewModelStore(n5);
                n5.getLifecycle().b(this);
                return;
        }
    }
}
