package c.l;

import android.app.Application;
import c.l.i0.a;
import java.lang.reflect.InvocationTargetException;
import java.util.Objects;

/* JADX INFO: compiled from: ViewModelProvider.kt */
/* JADX INFO: loaded from: classes.dex */
@g.i
public class f0 {
    public final g0 a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final c.l.i0.a f1771c;

    /* JADX INFO: compiled from: ViewModelProvider.kt */
    @g.i
    public interface b {
        default <T extends e0> T a(Class<T> cls) {
            g.h0.c.l.f(cls, "modelClass");
            throw new UnsupportedOperationException("Factory.create(String) is unsupported.  This Factory requires `CreationExtras` to be passed into `create` method.");
        }

        default <T extends e0> T b(Class<T> cls, c.l.i0.a aVar) {
            g.h0.c.l.f(cls, "modelClass");
            g.h0.c.l.f(aVar, "extras");
            return (T) a(cls);
        }
    }

    /* JADX INFO: compiled from: ViewModelProvider.kt */
    @g.i
    public static class c implements b {
        public static final a a = new a(null);

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public static c f1775b;

        /* JADX INFO: compiled from: ViewModelProvider.kt */
        @g.i
        public static final class a {

            /* JADX INFO: renamed from: c.l.f0$c$a$a, reason: collision with other inner class name */
            /* JADX INFO: compiled from: ViewModelProvider.kt */
            @g.i
            public static final class C0019a implements a.b<String> {
                public static final C0019a a = new C0019a();
            }

            public a(g.h0.c.g gVar) {
            }
        }

        @Override // c.l.f0.b
        public <T extends e0> T a(Class<T> cls) {
            g.h0.c.l.f(cls, "modelClass");
            try {
                T tNewInstance = cls.newInstance();
                g.h0.c.l.e(tNewInstance, "{\n                modelC…wInstance()\n            }");
                return tNewInstance;
            } catch (IllegalAccessException e2) {
                throw new RuntimeException("Cannot create an instance of " + cls, e2);
            } catch (InstantiationException e3) {
                throw new RuntimeException("Cannot create an instance of " + cls, e3);
            }
        }
    }

    /* JADX INFO: compiled from: ViewModelProvider.kt */
    @g.i
    public static class d {
        public void c(e0 e0Var) {
            g.h0.c.l.f(e0Var, "viewModel");
        }
    }

    public f0(g0 g0Var, b bVar, c.l.i0.a aVar) {
        g.h0.c.l.f(g0Var, "store");
        g.h0.c.l.f(bVar, "factory");
        g.h0.c.l.f(aVar, "defaultCreationExtras");
        this.a = g0Var;
        this.f1770b = bVar;
        this.f1771c = aVar;
    }

    public <T extends e0> T a(Class<T> cls) {
        g.h0.c.l.f(cls, "modelClass");
        String canonicalName = cls.getCanonicalName();
        if (canonicalName == null) {
            throw new IllegalArgumentException("Local and anonymous classes can not be ViewModels");
        }
        return (T) b("androidx.lifecycle.ViewModelProvider.DefaultKey:" + canonicalName, cls);
    }

    /* JADX WARN: Type inference incomplete: some casts might be missing */
    public <T extends e0> T b(String str, Class<T> cls) {
        T t;
        g.h0.c.l.f(str, "key");
        g.h0.c.l.f(cls, "modelClass");
        T t2 = (T) this.a.a.get(str);
        if (cls.isInstance(t2)) {
            Object obj = this.f1770b;
            d dVar = obj instanceof d ? (d) obj : null;
            if (dVar != null) {
                g.h0.c.l.e(t2, "viewModel");
                dVar.c(t2);
            }
            Objects.requireNonNull(t2, "null cannot be cast to non-null type T of androidx.lifecycle.ViewModelProvider.get");
            return t2;
        }
        c.l.i0.c cVar = new c.l.i0.c(this.f1771c);
        c.a aVar = c.a;
        cVar.b(c.a.C0019a.a, str);
        try {
            t = (T) this.f1770b.b(cls, cVar);
        } catch (AbstractMethodError unused) {
            t = (T) this.f1770b.a(cls);
        }
        e0 e0VarPut = this.a.a.put(str, t);
        if (e0VarPut != null) {
            e0VarPut.b();
        }
        return t;
    }

    /* JADX INFO: compiled from: ViewModelProvider.kt */
    @g.i
    public static class a extends c {

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public static final C0017a f1772c = new C0017a(null);

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public static a f1773d;

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

        /* JADX INFO: renamed from: c.l.f0$a$a, reason: collision with other inner class name */
        /* JADX INFO: compiled from: ViewModelProvider.kt */
        @g.i
        public static final class C0017a {

            /* JADX INFO: renamed from: c.l.f0$a$a$a, reason: collision with other inner class name */
            /* JADX INFO: compiled from: ViewModelProvider.kt */
            @g.i
            public static final class C0018a implements a.b<Application> {
                public static final C0018a a = new C0018a();
            }

            public C0017a(g.h0.c.g gVar) {
            }
        }

        public a() {
            this.f1774e = null;
        }

        @Override // c.l.f0.c, c.l.f0.b
        public <T extends e0> T a(Class<T> cls) {
            g.h0.c.l.f(cls, "modelClass");
            Application application = this.f1774e;
            if (application != null) {
                return (T) c(cls, application);
            }
            throw new UnsupportedOperationException("AndroidViewModelFactory constructed with empty constructor works only with create(modelClass: Class<T>, extras: CreationExtras).");
        }

        @Override // c.l.f0.b
        public <T extends e0> T b(Class<T> cls, c.l.i0.a aVar) {
            g.h0.c.l.f(cls, "modelClass");
            g.h0.c.l.f(aVar, "extras");
            if (this.f1774e != null) {
                return (T) a(cls);
            }
            Application application = (Application) aVar.a(C0017a.C0018a.a);
            if (application != null) {
                return (T) c(cls, application);
            }
            if (c.l.b.class.isAssignableFrom(cls)) {
                throw new IllegalArgumentException("CreationExtras must have an application by `APPLICATION_KEY`");
            }
            return (T) super.a(cls);
        }

        public final <T extends e0> T c(Class<T> cls, Application application) {
            if (!c.l.b.class.isAssignableFrom(cls)) {
                return (T) super.a(cls);
            }
            try {
                T tNewInstance = cls.getConstructor(Application.class).newInstance(application);
                g.h0.c.l.e(tNewInstance, "{\n                try {\n…          }\n            }");
                return tNewInstance;
            } catch (IllegalAccessException e2) {
                throw new RuntimeException("Cannot create an instance of " + cls, e2);
            } catch (InstantiationException e3) {
                throw new RuntimeException("Cannot create an instance of " + cls, e3);
            } catch (NoSuchMethodException e4) {
                throw new RuntimeException("Cannot create an instance of " + cls, e4);
            } catch (InvocationTargetException e5) {
                throw new RuntimeException("Cannot create an instance of " + cls, e5);
            }
        }

        public a(Application application) {
            g.h0.c.l.f(application, "application");
            this.f1774e = application;
        }
    }
}
