package androidx.lifecycle;

import android.app.Application;
import android.os.Bundle;
import d2.AbstractC1866c;
import d2.C1867d;
import java.lang.reflect.Constructor;
import n2.C2616g;
import n2.InterfaceC2618i;

/* JADX INFO: loaded from: classes.dex */
public final class Z extends g0 implements d0 {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Bundle f12150c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final r f12151d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final C2616g f12152e;

    public Z(Application application, InterfaceC2618i owner, Bundle bundle) {
        c0 c0Var;
        kotlin.jvm.internal.o.h(owner, "owner");
        this.f12152e = owner.getSavedStateRegistry();
        this.f12151d = owner.getLifecycle();
        this.f12150c = bundle;
        this.f12148a = application;
        if (application != null) {
            if (c0.f12160b == null) {
                c0.f12160b = new c0(application);
            }
            c0Var = c0.f12160b;
            kotlin.jvm.internal.o.e(c0Var);
        } else {
            c0Var = new c0(null);
        }
        this.f12149b = c0Var;
    }

    @Override // androidx.lifecycle.g0
    public final void a(b0 b0Var) {
        r rVar = this.f12151d;
        if (rVar != null) {
            C2616g c2616g = this.f12152e;
            kotlin.jvm.internal.o.e(c2616g);
            X.a(b0Var, c2616g, rVar);
        }
    }

    public final b0 b(Class cls, String str) {
        r rVar = this.f12151d;
        if (rVar == null) {
            throw new UnsupportedOperationException("SavedStateViewModelFactory constructed with empty constructor supports only calls to create(modelClass: Class<T>, extras: CreationExtras).");
        }
        boolean zIsAssignableFrom = AndroidViewModel.class.isAssignableFrom(cls);
        Application application = this.f12148a;
        Constructor constructorA = (!zIsAssignableFrom || application == null) ? a0.a(cls, a0.f12157b) : a0.a(cls, a0.f12156a);
        if (constructorA != null) {
            C2616g c2616g = this.f12152e;
            kotlin.jvm.internal.o.e(c2616g);
            V vB = X.b(c2616g, rVar, str, this.f12150c);
            U u6 = vB.f12138b;
            b0 b0VarB = (!zIsAssignableFrom || application == null) ? a0.b(cls, constructorA, u6) : a0.b(cls, constructorA, application, u6);
            b0VarB.addCloseable("androidx.lifecycle.savedstate.vm.tag", vB);
            return b0VarB;
        }
        if (application != null) {
            return this.f12149b.create(cls);
        }
        f0.Companion.getClass();
        if (f0._instance == null) {
            f0._instance = new f0();
        }
        f0 f0Var = f0._instance;
        kotlin.jvm.internal.o.e(f0Var);
        return f0Var.create(cls);
    }

    @Override // androidx.lifecycle.d0
    public final b0 create(Q4.c cVar, AbstractC1866c abstractC1866c) {
        return create(e4.C.D(cVar), abstractC1866c);
    }

    @Override // androidx.lifecycle.d0
    public final b0 create(Class cls, AbstractC1866c abstractC1866c) {
        String str = (String) abstractC1866c.a(h0.f12174b);
        if (str == null) {
            throw new IllegalStateException("VIEW_MODEL_KEY must always be provided by ViewModelProvider");
        }
        if (abstractC1866c.a(X.f12140a) == null || abstractC1866c.a(X.f12141b) == null) {
            if (this.f12151d != null) {
                return b(cls, str);
            }
            throw new IllegalStateException("SAVED_STATE_REGISTRY_OWNER_KEY andVIEW_MODEL_STORE_OWNER_KEY must be provided in the creation extras tosuccessfully create a ViewModel.");
        }
        Application application = (Application) abstractC1866c.a(c0.f12161c);
        boolean zIsAssignableFrom = AndroidViewModel.class.isAssignableFrom(cls);
        Constructor constructorA = (!zIsAssignableFrom || application == null) ? a0.a(cls, a0.f12157b) : a0.a(cls, a0.f12156a);
        return constructorA == null ? this.f12149b.create(cls, abstractC1866c) : (!zIsAssignableFrom || application == null) ? a0.b(cls, constructorA, X.c((C1867d) abstractC1866c)) : a0.b(cls, constructorA, application, X.c((C1867d) abstractC1866c));
    }

    @Override // androidx.lifecycle.d0
    public final b0 create(Class cls) {
        String canonicalName = cls.getCanonicalName();
        if (canonicalName != null) {
            return b(cls, canonicalName);
        }
        throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels");
    }
}
