package c.l;

import android.os.Bundle;
import c.l.f0;
import c.l.i0.a;
import c.l.y;
import c.o.b;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;

/* JADX INFO: compiled from: SavedStateHandleSupport.kt */
/* JADX INFO: loaded from: classes.dex */
@g.i
public final class z {
    public static final a.b<c.o.d> a = new b();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final a.b<h0> f1805b = new c();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final a.b<Bundle> f1806c = new a();

    /* JADX INFO: compiled from: SavedStateHandleSupport.kt */
    @g.i
    public static final class a implements a.b<Bundle> {
    }

    /* JADX INFO: compiled from: SavedStateHandleSupport.kt */
    @g.i
    public static final class b implements a.b<c.o.d> {
    }

    /* JADX INFO: compiled from: SavedStateHandleSupport.kt */
    @g.i
    public static final class c implements a.b<h0> {
    }

    /* JADX INFO: compiled from: SavedStateHandleSupport.kt */
    @g.i
    public static final class d extends g.h0.c.m implements g.h0.b.l<c.l.i0.a, b0> {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public static final d f1807b = new d();

        public d() {
            super(1);
        }

        @Override // g.h0.b.l
        public b0 invoke(c.l.i0.a aVar) {
            g.h0.c.l.f(aVar, "$this$initializer");
            return new b0();
        }
    }

    public static final y a(c.l.i0.a aVar) {
        g.h0.c.l.f(aVar, "<this>");
        c.o.d dVar = (c.o.d) aVar.a(a);
        if (dVar == null) {
            throw new IllegalArgumentException("CreationExtras must have a value by `SAVED_STATE_REGISTRY_OWNER_KEY`");
        }
        h0 h0Var = (h0) aVar.a(f1805b);
        if (h0Var == null) {
            throw new IllegalArgumentException("CreationExtras must have a value by `VIEW_MODEL_STORE_OWNER_KEY`");
        }
        Bundle bundle = (Bundle) aVar.a(f1806c);
        String str = (String) aVar.a(f0.c.a.C0019a.a);
        if (str == null) {
            throw new IllegalArgumentException("CreationExtras must have a value by `VIEW_MODEL_KEY`");
        }
        g.h0.c.l.f(dVar, "<this>");
        b.InterfaceC0024b interfaceC0024bB = dVar.getSavedStateRegistry().b("androidx.lifecycle.internal.SavedStateHandlesProvider");
        a0 a0Var = interfaceC0024bB instanceof a0 ? (a0) interfaceC0024bB : null;
        if (a0Var == null) {
            throw new IllegalStateException("enableSavedStateHandles() wasn't called prior to createSavedStateHandle() call");
        }
        b0 b0VarB = b(h0Var);
        y yVar = b0VarB.f1758d.get(str);
        if (yVar != null) {
            return yVar;
        }
        y.a aVar2 = y.a;
        g.h0.c.l.f(str, "key");
        a0Var.b();
        Bundle bundle2 = a0Var.f1755c;
        Bundle bundle3 = bundle2 != null ? bundle2.getBundle(str) : null;
        Bundle bundle4 = a0Var.f1755c;
        if (bundle4 != null) {
            bundle4.remove(str);
        }
        Bundle bundle5 = a0Var.f1755c;
        if (bundle5 != null && bundle5.isEmpty()) {
            a0Var.f1755c = null;
        }
        y yVarA = y.a.a(bundle3, bundle);
        b0VarB.f1758d.put(str, yVarA);
        return yVarA;
    }

    public static final b0 b(h0 h0Var) {
        c.l.i0.a defaultViewModelCreationExtras;
        g.h0.c.l.f(h0Var, "<this>");
        ArrayList arrayList = new ArrayList();
        d dVar = d.f1807b;
        g.k0.c cVarA = g.h0.c.b0.a(b0.class);
        g.h0.c.l.f(cVarA, "clazz");
        g.h0.c.l.f(dVar, "initializer");
        g.h0.c.l.f(cVarA, "<this>");
        Class<?> clsB = ((g.h0.c.d) cVarA).b();
        g.h0.c.l.d(clsB, "null cannot be cast to non-null type java.lang.Class<T of kotlin.jvm.JvmClassMappingKt.<get-java>>");
        arrayList.add(new c.l.i0.d(clsB, dVar));
        Object[] array = arrayList.toArray(new c.l.i0.d[0]);
        Objects.requireNonNull(array, "null cannot be cast to non-null type kotlin.Array<T of kotlin.collections.ArraysKt__ArraysJVMKt.toTypedArray>");
        c.l.i0.d[] dVarArr = (c.l.i0.d[]) array;
        c.l.i0.b bVar = new c.l.i0.b((c.l.i0.d[]) Arrays.copyOf(dVarArr, dVarArr.length));
        g.h0.c.l.f(h0Var, "owner");
        g.h0.c.l.f(bVar, "factory");
        g0 viewModelStore = h0Var.getViewModelStore();
        g.h0.c.l.e(viewModelStore, "owner.viewModelStore");
        g.h0.c.l.f(h0Var, "owner");
        if (h0Var instanceof h) {
            defaultViewModelCreationExtras = ((h) h0Var).getDefaultViewModelCreationExtras();
            g.h0.c.l.e(defaultViewModelCreationExtras, "{\n        owner.defaultV…ModelCreationExtras\n    }");
        } else {
            defaultViewModelCreationExtras = a.C0020a.f1776b;
        }
        return (b0) new f0(viewModelStore, bVar, defaultViewModelCreationExtras).b("androidx.lifecycle.internal.SavedStateHandlesVM", b0.class);
    }
}
