package androidx.lifecycle;

import E1.C0113u;
import O1.C0225a;
import android.app.Application;
import android.os.Bundle;
import com.google.android.gms.internal.measurement.X1;
import java.lang.reflect.Constructor;
import java.util.LinkedHashMap;
import n4.u0;
import r0.C1484c;

/* JADX INFO: loaded from: classes.dex */
public final class T implements Y {

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

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final O3.e f8810d;

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

    public T(Application application, U1.e eVar, Bundle bundle) {
        X x8;
        P6.g.e(eVar, "owner");
        this.f8811e = eVar.h();
        this.f8810d = eVar.C();
        this.f8809c = bundle;
        this.f8807a = application;
        if (application != null) {
            if (X.f8818d == null) {
                X.f8818d = new X(application);
            }
            x8 = X.f8818d;
            P6.g.b(x8);
        } else {
            x8 = new X(null);
        }
        this.f8808b = x8;
    }

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

    @Override // androidx.lifecycle.Y
    public final W b(Class cls, C1484c c1484c) {
        C4.f fVar = P.f8801e;
        LinkedHashMap linkedHashMap = c1484c.f16348a;
        String str = (String) linkedHashMap.get(fVar);
        if (str == null) {
            throw new IllegalStateException("VIEW_MODEL_KEY must always be provided by ViewModelProvider");
        }
        if (linkedHashMap.get(P.f8797a) == null || linkedHashMap.get(P.f8798b) == null) {
            if (this.f8810d != null) {
                return d(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) linkedHashMap.get(X.f8819e);
        boolean zIsAssignableFrom = AbstractC0496a.class.isAssignableFrom(cls);
        Constructor constructorA = (!zIsAssignableFrom || application == null) ? U.a(cls, U.f8813b) : U.a(cls, U.f8812a);
        return constructorA == null ? this.f8808b.b(cls, c1484c) : (!zIsAssignableFrom || application == null) ? U.b(cls, constructorA, P.d(c1484c)) : U.b(cls, constructorA, application, P.d(c1484c));
    }

    @Override // androidx.lifecycle.Y
    public final W c(P6.d dVar, C1484c c1484c) {
        return b(X1.m(dVar), c1484c);
    }

    public final W d(Class cls, String str) {
        O3.e eVar = this.f8810d;
        if (eVar == null) {
            throw new UnsupportedOperationException("SavedStateViewModelFactory constructed with empty constructor supports only calls to create(modelClass: Class<T>, extras: CreationExtras).");
        }
        boolean zIsAssignableFrom = AbstractC0496a.class.isAssignableFrom(cls);
        Application application = this.f8807a;
        Constructor constructorA = (!zIsAssignableFrom || application == null) ? U.a(cls, U.f8813b) : U.a(cls, U.f8812a);
        if (constructorA == null) {
            if (application != null) {
                return this.f8808b.a(cls);
            }
            if (C0113u.f2132b == null) {
                C0113u.f2132b = new C0113u(2);
            }
            P6.g.b(C0113u.f2132b);
            return u0.j(cls);
        }
        C0225a c0225a = this.f8811e;
        P6.g.b(c0225a);
        O oB = P.b(c0225a, eVar, str, this.f8809c);
        N n8 = oB.f8795r;
        W wB = (!zIsAssignableFrom || application == null) ? U.b(cls, constructorA, n8) : U.b(cls, constructorA, application, n8);
        wB.a("androidx.lifecycle.savedstate.vm.tag", oB);
        return wB;
    }
}
