package androidx.compose.ui.platform;

import android.os.Binder;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.Size;
import android.util.SizeF;
import android.util.SparseArray;
import android.view.View;
import i5.d;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/* loaded from: classes.dex */
public abstract class i1 {

    /* renamed from: a, reason: collision with root package name */
    private static final Class[] f2452a = {Serializable.class, Parcelable.class, String.class, SparseArray.class, Binder.class, Size.class, SizeF.class};

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class a extends kotlin.jvm.internal.v implements dn.a {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ boolean f2453p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ i5.d f2454q;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ String f2455r;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        a(boolean z10, i5.d dVar, String str) {
            super(0);
            this.f2453p = z10;
            this.f2454q = dVar;
            this.f2455r = str;
        }

        @Override // dn.a
        public /* bridge */ /* synthetic */ Object invoke() {
            m15invoke();
            return rm.n0.f34904a;
        }

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m15invoke() {
            if (this.f2453p) {
                this.f2454q.j(this.f2455r);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class b extends kotlin.jvm.internal.v implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        public static final b f2456p = new b();

        b() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Boolean invoke(Object obj) {
            return Boolean.valueOf(i1.f(obj));
        }
    }

    public static final g1 b(View view, i5.f fVar) {
        Object parent = view.getParent();
        kotlin.jvm.internal.t.e(parent, "null cannot be cast to non-null type android.view.View");
        View view2 = (View) parent;
        Object tag = view2.getTag(l1.m.H);
        String str = tag instanceof String ? (String) tag : null;
        if (str == null) {
            str = String.valueOf(view2.getId());
        }
        return c(str, fVar);
    }

    public static final g1 c(String str, i5.f fVar) {
        boolean z10;
        String str2 = i1.g.class.getSimpleName() + ':' + str;
        i5.d savedStateRegistry = fVar.getSavedStateRegistry();
        Bundle b10 = savedStateRegistry.b(str2);
        final i1.g a10 = i1.i.a(b10 != null ? h(b10) : null, b.f2456p);
        try {
            savedStateRegistry.h(str2, new d.c() { // from class: androidx.compose.ui.platform.h1
                @Override // i5.d.c
                public final Bundle a() {
                    Bundle d10;
                    d10 = i1.d(i1.g.this);
                    return d10;
                }
            });
            z10 = true;
        } catch (IllegalArgumentException unused) {
            z10 = false;
        }
        return new g1(a10, new a(z10, savedStateRegistry, str2));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final Bundle d(i1.g gVar) {
        return g(gVar.c());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final boolean f(Object obj) {
        if (obj instanceof j1.q) {
            j1.q qVar = (j1.q) obj;
            if (qVar.c() != y0.n3.j() && qVar.c() != y0.n3.q() && qVar.c() != y0.n3.n()) {
                return false;
            }
            Object value = qVar.getValue();
            if (value == null) {
                return true;
            }
            return f(value);
        }
        if ((obj instanceof rm.i) && (obj instanceof Serializable)) {
            return false;
        }
        for (Class cls : f2452a) {
            if (cls.isInstance(obj)) {
                return true;
            }
        }
        return false;
    }

    private static final Bundle g(Map map) {
        Bundle bundle = new Bundle();
        for (Map.Entry entry : map.entrySet()) {
            String str = (String) entry.getKey();
            List list = (List) entry.getValue();
            bundle.putParcelableArrayList(str, list instanceof ArrayList ? (ArrayList) list : new ArrayList<>(list));
        }
        return bundle;
    }

    private static final Map h(Bundle bundle) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        for (String str : bundle.keySet()) {
            ArrayList parcelableArrayList = bundle.getParcelableArrayList(str);
            kotlin.jvm.internal.t.e(parcelableArrayList, "null cannot be cast to non-null type java.util.ArrayList<kotlin.Any?>{ kotlin.collections.TypeAliasesKt.ArrayList<kotlin.Any?> }");
            linkedHashMap.put(str, parcelableArrayList);
        }
        return linkedHashMap;
    }
}
