package androidx.lifecycle;

import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcelable;
import android.util.Size;
import android.util.SizeF;
import android.util.SparseArray;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import kotlin.Pair;

/* JADX INFO: loaded from: classes.dex */
public final class l0 {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final Class[] f2662f = {Boolean.TYPE, boolean[].class, Double.TYPE, double[].class, Integer.TYPE, int[].class, Long.TYPE, long[].class, String.class, String[].class, Binder.class, Bundle.class, Byte.TYPE, byte[].class, Character.TYPE, char[].class, CharSequence.class, CharSequence[].class, ArrayList.class, Float.TYPE, float[].class, Parcelable.class, Parcelable[].class, Serializable.class, Short.TYPE, short[].class, SparseArray.class, Size.class, SizeF.class};

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

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

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

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

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

    public l0(HashMap map) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        this.f2663a = linkedHashMap;
        this.f2664b = new LinkedHashMap();
        this.f2665c = new LinkedHashMap();
        this.f2666d = new LinkedHashMap();
        this.f2667e = new j0(this, 0);
        linkedHashMap.putAll(map);
    }

    public static Bundle a(l0 l0Var) {
        nb.g.i(l0Var, "this$0");
        Iterator it = kotlin.collections.q.e0(l0Var.f2664b).entrySet().iterator();
        while (true) {
            boolean zHasNext = it.hasNext();
            LinkedHashMap linkedHashMap = l0Var.f2663a;
            int i10 = 0;
            if (!zHasNext) {
                Set<String> setKeySet = linkedHashMap.keySet();
                ArrayList arrayList = new ArrayList(setKeySet.size());
                ArrayList arrayList2 = new ArrayList(arrayList.size());
                for (String str : setKeySet) {
                    arrayList.add(str);
                    arrayList2.add(linkedHashMap.get(str));
                }
                Pair[] pairArr = {new Pair("keys", arrayList), new Pair("values", arrayList2)};
                Bundle bundle = new Bundle(2);
                while (i10 < 2) {
                    Pair pair = pairArr[i10];
                    String str2 = (String) pair.getFirst();
                    Object second = pair.getSecond();
                    if (second == null) {
                        bundle.putString(str2, null);
                    } else if (second instanceof Boolean) {
                        bundle.putBoolean(str2, ((Boolean) second).booleanValue());
                    } else if (second instanceof Byte) {
                        bundle.putByte(str2, ((Number) second).byteValue());
                    } else if (second instanceof Character) {
                        bundle.putChar(str2, ((Character) second).charValue());
                    } else if (second instanceof Double) {
                        bundle.putDouble(str2, ((Number) second).doubleValue());
                    } else if (second instanceof Float) {
                        bundle.putFloat(str2, ((Number) second).floatValue());
                    } else if (second instanceof Integer) {
                        bundle.putInt(str2, ((Number) second).intValue());
                    } else if (second instanceof Long) {
                        bundle.putLong(str2, ((Number) second).longValue());
                    } else if (second instanceof Short) {
                        bundle.putShort(str2, ((Number) second).shortValue());
                    } else if (second instanceof Bundle) {
                        bundle.putBundle(str2, (Bundle) second);
                    } else if (second instanceof CharSequence) {
                        bundle.putCharSequence(str2, (CharSequence) second);
                    } else if (second instanceof Parcelable) {
                        bundle.putParcelable(str2, (Parcelable) second);
                    } else if (second instanceof boolean[]) {
                        bundle.putBooleanArray(str2, (boolean[]) second);
                    } else if (second instanceof byte[]) {
                        bundle.putByteArray(str2, (byte[]) second);
                    } else if (second instanceof char[]) {
                        bundle.putCharArray(str2, (char[]) second);
                    } else if (second instanceof double[]) {
                        bundle.putDoubleArray(str2, (double[]) second);
                    } else if (second instanceof float[]) {
                        bundle.putFloatArray(str2, (float[]) second);
                    } else if (second instanceof int[]) {
                        bundle.putIntArray(str2, (int[]) second);
                    } else if (second instanceof long[]) {
                        bundle.putLongArray(str2, (long[]) second);
                    } else if (second instanceof short[]) {
                        bundle.putShortArray(str2, (short[]) second);
                    } else if (second instanceof Object[]) {
                        Class<?> componentType = second.getClass().getComponentType();
                        nb.g.f(componentType);
                        if (Parcelable.class.isAssignableFrom(componentType)) {
                            bundle.putParcelableArray(str2, (Parcelable[]) second);
                        } else if (String.class.isAssignableFrom(componentType)) {
                            bundle.putStringArray(str2, (String[]) second);
                        } else if (CharSequence.class.isAssignableFrom(componentType)) {
                            bundle.putCharSequenceArray(str2, (CharSequence[]) second);
                        } else {
                            if (!Serializable.class.isAssignableFrom(componentType)) {
                                throw new IllegalArgumentException("Illegal value array type " + componentType.getCanonicalName() + " for key \"" + str2 + '\"');
                            }
                            bundle.putSerializable(str2, (Serializable) second);
                        }
                    } else if (second instanceof Serializable) {
                        bundle.putSerializable(str2, (Serializable) second);
                    } else if (second instanceof IBinder) {
                        bundle.putBinder(str2, (IBinder) second);
                    } else if (second instanceof Size) {
                        bundle.putSize(str2, (Size) second);
                    } else {
                        if (!(second instanceof SizeF)) {
                            throw new IllegalArgumentException("Illegal value type " + second.getClass().getCanonicalName() + " for key \"" + str2 + '\"');
                        }
                        bundle.putSizeF(str2, (SizeF) second);
                    }
                    i10++;
                }
                return bundle;
            }
            Map.Entry entry = (Map.Entry) it.next();
            String str3 = (String) entry.getKey();
            Object objA = ((i3.e) entry.getValue()).a();
            nb.g.i(str3, "key");
            if (objA != null) {
                Class[] clsArr = f2662f;
                while (i10 < 29) {
                    Class cls = clsArr[i10];
                    nb.g.f(cls);
                    if (!cls.isInstance(objA)) {
                        i10++;
                    }
                }
                throw new IllegalArgumentException("Can't put value with type " + objA.getClass() + " into saved state");
            }
            Object obj = l0Var.f2665c.get(str3);
            w wVar = obj instanceof w ? (w) obj : null;
            if (wVar != null) {
                wVar.i(objA);
            } else {
                linkedHashMap.put(str3, objA);
            }
            kotlinx.coroutines.flow.p pVar = (kotlinx.coroutines.flow.p) l0Var.f2666d.get(str3);
            if (pVar != null) {
                kotlinx.coroutines.flow.v vVar = (kotlinx.coroutines.flow.v) pVar;
                if (objA == null) {
                    objA = kotlinx.coroutines.flow.internal.b.f29385b;
                }
                vVar.h(null, objA);
            }
        }
    }

    public l0() {
        this.f2663a = new LinkedHashMap();
        this.f2664b = new LinkedHashMap();
        this.f2665c = new LinkedHashMap();
        this.f2666d = new LinkedHashMap();
        this.f2667e = new j0(this, 1);
    }
}
