package com.adobe.marketing.mobile.internal.util;

import dn.l;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import jn.o;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import org.json.JSONArray;
import org.json.JSONObject;
import rp.n;
import rp.p;
import sm.c0;
import sm.k0;

/* loaded from: classes4.dex */
public abstract class d {

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class a extends v implements l {

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

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ l f12316q;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        a(JSONArray jSONArray, l lVar) {
            super(1);
            this.f12315p = jSONArray;
            this.f12316q = lVar;
        }

        public final Object a(int i10) {
            l lVar = this.f12316q;
            Object obj = this.f12315p.get(i10);
            t.f(obj, "this.get(it)");
            return lVar.invoke(obj);
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            return a(((Number) obj).intValue());
        }
    }

    public static final /* synthetic */ List a(JSONArray map, l transform) {
        jn.i q10;
        rp.h S;
        rp.h x10;
        List E;
        t.g(map, "$this$map");
        t.g(transform, "transform");
        q10 = o.q(0, map.length());
        S = c0.S(q10);
        x10 = p.x(S, new a(map, transform));
        E = p.E(x10);
        return E;
    }

    public static final /* synthetic */ List b(JSONArray toList) {
        jn.i q10;
        t.g(toList, "$this$toList");
        ArrayList arrayList = new ArrayList();
        q10 = o.q(0, toList.length());
        Iterator it = q10.iterator();
        while (it.hasNext()) {
            Object obj = toList.get(((k0) it).a());
            if (obj instanceof JSONObject) {
                arrayList.add(c((JSONObject) obj));
            } else if (obj instanceof JSONArray) {
                arrayList.add(b((JSONArray) obj));
            } else if (t.b(obj, JSONObject.NULL)) {
                arrayList.add(null);
            } else {
                arrayList.add(obj);
            }
        }
        return arrayList;
    }

    public static final /* synthetic */ Map c(JSONObject toMap) {
        rp.h c10;
        t.g(toMap, "$this$toMap");
        Iterator<String> keys = toMap.keys();
        t.f(keys, "this.keys()");
        c10 = n.c(keys);
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        for (Object obj : c10) {
            Object obj2 = toMap.get((String) obj);
            if (obj2 instanceof JSONObject) {
                obj2 = c((JSONObject) obj2);
            } else if (obj2 instanceof JSONArray) {
                obj2 = b((JSONArray) obj2);
            } else if (t.b(obj2, JSONObject.NULL)) {
                obj2 = null;
            }
            linkedHashMap.put(obj, obj2);
        }
        return linkedHashMap;
    }
}
