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

import dn.p;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import kotlin.jvm.internal.v;
import kotlin.text.b0;
import kotlin.text.y;

/* loaded from: classes4.dex */
public final class b {

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

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

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        a(boolean z10) {
            super(2);
            this.f12311p = z10;
        }

        @Override // dn.p
        public final Object invoke(Object obj, Object obj2) {
            return ((obj instanceof Map) && (obj2 instanceof Map)) ? b.f12310a.g((Map) obj, (Map) obj2, this.f12311p) : !this.f12311p ? obj2 : ((obj instanceof Collection) && (obj2 instanceof Collection)) ? b.f12310a.f((Collection) obj, (Collection) obj2) : obj;
        }
    }

    /* renamed from: com.adobe.marketing.mobile.internal.util.b$b, reason: collision with other inner class name */
    /* loaded from: classes4.dex */
    public static final class C0288b extends ArrayList {

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

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

        C0288b(Collection collection, Collection collection2) {
            this.f12312p = collection;
            this.f12313q = collection2;
            if (collection != null) {
                addAll(collection);
            }
            if (collection2 != null) {
                addAll(collection2);
            }
        }

        public /* bridge */ int i() {
            return super.size();
        }

        public /* bridge */ Object k(int i10) {
            return super.remove(i10);
        }

        @Override // java.util.ArrayList, java.util.AbstractList, java.util.List
        public final /* bridge */ Object remove(int i10) {
            return k(i10);
        }

        @Override // java.util.ArrayList, java.util.AbstractCollection, java.util.Collection, java.util.List
        public final /* bridge */ int size() {
            return i();
        }
    }

    private b() {
    }

    private final void c(HashMap hashMap, String str, Map map, boolean z10) {
        String k12;
        k12 = b0.k1(str, 3);
        Object obj = hashMap.get(k12);
        if (obj instanceof Collection) {
            ArrayList arrayList = new ArrayList();
            for (Object obj2 : (Iterable) obj) {
                Map map2 = (Map) (!(obj2 instanceof Map) ? null : obj2);
                if (map2 != null) {
                    arrayList.add(f12310a.g(map, map2, z10));
                } else {
                    arrayList.add(obj2);
                }
            }
            hashMap.put(k12, arrayList);
        }
    }

    private final Map d(Map map, Map map2, boolean z10, p pVar) {
        boolean y10;
        HashMap hashMap = new HashMap();
        if (map2 != null) {
            hashMap.putAll(map2);
        }
        if (map != null) {
            for (Map.Entry entry : map.entrySet()) {
                String str = (String) entry.getKey();
                Object value = entry.getValue();
                if (hashMap.containsKey(str)) {
                    Object invoke = pVar.invoke(value, hashMap.get(str));
                    if (invoke != null) {
                        hashMap.put(str, invoke);
                    } else {
                        hashMap.remove(str);
                    }
                } else {
                    y10 = y.y(str, "[*]", false, 2, null);
                    if (!y10) {
                        hashMap.put(str, value);
                    } else if (value instanceof Map) {
                        f12310a.c(hashMap, str, (Map) value, z10);
                    }
                }
            }
        }
        return hashMap;
    }

    public static final Map e(Map map, Map map2, boolean z10) {
        return f12310a.d(map, map2, z10, new a(z10));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Collection f(Collection collection, Collection collection2) {
        return new C0288b(collection, collection2);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Map g(Map map, Map map2, boolean z10) {
        if (map != null && !h.a(map.keySet())) {
            return map2;
        }
        if (map2 != null && !h.a(map2.keySet())) {
            return map2;
        }
        try {
            Map map3 = null;
            if (!(map instanceof Map)) {
                map = null;
            }
            if (map2 instanceof Map) {
                map3 = map2;
            }
            return e(map, map3, z10);
        } catch (Exception unused) {
            return map2;
        }
    }
}
