package com.revenuecat.purchases.utils;

import S4.v;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import kotlin.jvm.internal.o;
import l5.C;
import l5.e;
import l5.m;
import l5.n;
import l5.y;
import m5.i;
import x4.AbstractC3229F;
import x4.AbstractC3253s;

/* JADX INFO: loaded from: classes3.dex */
public final class JsonElementExtensionsKt {
    public static final Map<String, Object> asMap(m mVar) {
        o.h(mVar, "<this>");
        if (!(mVar instanceof y)) {
            return null;
        }
        Set<Map.Entry> setEntrySet = n.g(mVar).f20366a.entrySet();
        int iU = AbstractC3229F.u(AbstractC3253s.G(setEntrySet, 10));
        if (iU < 16) {
            iU = 16;
        }
        LinkedHashMap linkedHashMap = new LinkedHashMap(iU);
        for (Map.Entry entry : setEntrySet) {
            linkedHashMap.put(entry.getKey(), getExtractedContent((m) entry.getValue()));
        }
        return linkedHashMap;
    }

    /* JADX WARN: Removed duplicated region for block: B:19:0x0047  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private static final Object getExtractedContent(m mVar) {
        Long lValueOf;
        Integer numValueOf;
        Long lValueOf2;
        LinkedHashMap linkedHashMap = null;
        if (!(mVar instanceof C)) {
            if (mVar instanceof e) {
                e eVarF = n.f(mVar);
                ArrayList arrayList = new ArrayList(AbstractC3253s.G(eVarF, 10));
                Iterator it = eVarF.f20336a.iterator();
                while (it.hasNext()) {
                    arrayList.add(getExtractedContent((m) it.next()));
                }
                return arrayList;
            }
            if (mVar instanceof y) {
                Set<Map.Entry> setEntrySet = n.g(mVar).f20366a.entrySet();
                int iU = AbstractC3229F.u(AbstractC3253s.G(setEntrySet, 10));
                if (iU < 16) {
                    iU = 16;
                }
                linkedHashMap = new LinkedHashMap(iU);
                for (Map.Entry entry : setEntrySet) {
                    linkedHashMap.put(entry.getKey(), getExtractedContent((m) entry.getValue()));
                }
            }
            return linkedHashMap;
        }
        C cH = n.h(mVar);
        if (cH.h()) {
            return cH.g();
        }
        Boolean boolD = n.d(cH);
        if (boolD != null) {
            return boolD;
        }
        try {
            lValueOf = Long.valueOf(new m5.y(cH.g()).h());
        } catch (i unused) {
            lValueOf = null;
        }
        if (lValueOf != null) {
            long jLongValue = lValueOf.longValue();
            numValueOf = (-2147483648L > jLongValue || jLongValue > 2147483647L) ? null : Integer.valueOf((int) jLongValue);
        }
        if (numValueOf != null) {
            return numValueOf;
        }
        try {
            lValueOf2 = Long.valueOf(new m5.y(cH.g()).h());
        } catch (i unused2) {
            lValueOf2 = null;
        }
        if (lValueOf2 != null) {
            return lValueOf2;
        }
        String strG = cH.g();
        o.h(strG, "<this>");
        Float fValueOf = S4.o.f6291a.d(strG) ? Float.valueOf(Float.parseFloat(strG)) : null;
        if (fValueOf != null) {
            return fValueOf;
        }
        Double dR0 = v.r0(cH.g());
        if (dR0 == null) {
            return cH instanceof l5.v ? null : cH.g();
        }
        return dR0;
    }
}
