package n2;

import android.os.Bundle;
import androidx.lifecycle.EnumC1107p;
import androidx.lifecycle.InterfaceC1111u;
import androidx.lifecycle.InterfaceC1113w;
import androidx.lifecycle.X;
import androidx.lifecycle.b0;
import androidx.lifecycle.i0;
import androidx.lifecycle.j0;
import d.AbstractActivityC1833l;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import kotlin.jvm.internal.o;

/* JADX INFO: renamed from: n2.b, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C2611b implements InterfaceC1111u {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final InterfaceC2618i f21609b;

    public /* synthetic */ C2611b(InterfaceC2618i interfaceC2618i, int i6) {
        this.f21608a = i6;
        this.f21609b = interfaceC2618i;
    }

    @Override // androidx.lifecycle.InterfaceC1111u
    public final void a(InterfaceC1113w interfaceC1113w, EnumC1107p enumC1107p) {
        switch (this.f21608a) {
            case 0:
                if (enumC1107p != EnumC1107p.ON_CREATE) {
                    throw new AssertionError("Next event must be ON_CREATE");
                }
                interfaceC1113w.getLifecycle().removeObserver(this);
                InterfaceC2618i interfaceC2618i = this.f21609b;
                Bundle bundleA = interfaceC2618i.getSavedStateRegistry().a("androidx.savedstate.Restarter");
                if (bundleA == null) {
                    return;
                }
                ArrayList<String> stringArrayList = bundleA.getStringArrayList("classes_to_restore");
                if (stringArrayList == null) {
                    throw new IllegalStateException("SavedState 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, C2611b.class.getClassLoader()).asSubclass(InterfaceC2614e.class);
                        o.e(clsAsSubclass);
                        try {
                            Constructor declaredConstructor = clsAsSubclass.getDeclaredConstructor(new Class[0]);
                            declaredConstructor.setAccessible(true);
                            try {
                                Object objNewInstance = declaredConstructor.newInstance(new Object[0]);
                                o.e(objNewInstance);
                                if (!(interfaceC2618i instanceof j0)) {
                                    throw new IllegalStateException(("Internal error: OnRecreation should be registered only on components that implement ViewModelStoreOwner. Received owner: " + interfaceC2618i).toString());
                                }
                                i0 viewModelStore = ((j0) interfaceC2618i).getViewModelStore();
                                C2616g savedStateRegistry = interfaceC2618i.getSavedStateRegistry();
                                viewModelStore.getClass();
                                LinkedHashMap linkedHashMap = viewModelStore.f12176a;
                                for (String key : new HashSet(linkedHashMap.keySet())) {
                                    o.h(key, "key");
                                    b0 b0Var = (b0) linkedHashMap.get(key);
                                    if (b0Var != null) {
                                        X.a(b0Var, savedStateRegistry, interfaceC2618i.getLifecycle());
                                    }
                                }
                                if (!new HashSet(linkedHashMap.keySet()).isEmpty()) {
                                    savedStateRegistry.d();
                                }
                            } catch (Exception e6) {
                                throw new RuntimeException(A0.a.n("Failed to instantiate ", str), e6);
                            }
                        } catch (NoSuchMethodException e7) {
                            throw new IllegalStateException("Class " + clsAsSubclass.getSimpleName() + " must have default constructor in order to be automatically recreated", e7);
                        }
                    } catch (ClassNotFoundException e8) {
                        throw new RuntimeException(Z0.o.o("Class ", str, " wasn't found"), e8);
                    }
                }
                return;
            default:
                AbstractActivityC1833l abstractActivityC1833l = (AbstractActivityC1833l) this.f21609b;
                AbstractActivityC1833l.access$ensureViewModelStore(abstractActivityC1833l);
                abstractActivityC1833l.getLifecycle().removeObserver(this);
                return;
        }
    }
}
