package h.b.p;

import g.h0.c.b0;
import h.b.m.d;
import h.b.o.e1;
import h.b.o.f1;
import h.b.o.y1;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/* JADX INFO: compiled from: JsonElementSerializers.kt */
/* JADX INFO: loaded from: classes.dex */
@g.i
public final class s implements h.b.b<r> {
    public static final s a = new s();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final h.b.m.e f4581b;

    static {
        int length;
        Comparable comparable;
        d.i iVar = d.i.a;
        g.h0.c.l.f("kotlinx.serialization.json.JsonLiteral", "serialName");
        g.h0.c.l.f(iVar, "kind");
        if (!(!g.m0.f.o("kotlinx.serialization.json.JsonLiteral"))) {
            throw new IllegalArgumentException("Blank serial names are prohibited".toString());
        }
        Map<g.k0.c<? extends Object>, h.b.b<? extends Object>> map = f1.a;
        g.h0.c.l.f("kotlinx.serialization.json.JsonLiteral", "serialName");
        g.h0.c.l.f(iVar, "kind");
        Iterator<g.k0.c<? extends Object>> it = f1.a.keySet().iterator();
        while (it.hasNext()) {
            String strA = it.next().a();
            g.h0.c.l.c(strA);
            String strA2 = f1.a(strA);
            if (g.m0.f.e("kotlinx.serialization.json.JsonLiteral", "kotlin." + strA2, true) || g.m0.f.e("kotlinx.serialization.json.JsonLiteral", strA2, true)) {
                StringBuilder sbE = d.b.a.a.a.E("\n                The name of serial descriptor should uniquely identify associated serializer.\n                For serial name ", "kotlinx.serialization.json.JsonLiteral", " there already exist ");
                sbE.append(f1.a(strA2));
                sbE.append("Serializer.\n                Please refer to SerialDescriptor documentation for additional information.\n            ");
                String string = sbE.toString();
                g.h0.c.l.f(string, "<this>");
                g.h0.c.l.f(string, "<this>");
                g.h0.c.l.f("", "newIndent");
                List<String> listR = g.m0.f.r(string);
                ArrayList arrayList = new ArrayList();
                for (Object obj : listR) {
                    if (!g.m0.f.o((String) obj)) {
                        arrayList.add(obj);
                    }
                }
                ArrayList arrayList2 = new ArrayList(f.a.y.a.C(arrayList, 10));
                Iterator it2 = arrayList.iterator();
                while (true) {
                    length = 0;
                    if (!it2.hasNext()) {
                        break;
                    }
                    String str = (String) it2.next();
                    int length2 = str.length();
                    while (true) {
                        if (length >= length2) {
                            length = -1;
                            break;
                        } else if (!f.a.y.a.q0(str.charAt(length))) {
                            break;
                        } else {
                            length++;
                        }
                    }
                    if (length == -1) {
                        length = str.length();
                    }
                    arrayList2.add(Integer.valueOf(length));
                }
                g.h0.c.l.f(arrayList2, "<this>");
                Iterator it3 = arrayList2.iterator();
                if (it3.hasNext()) {
                    comparable = (Comparable) it3.next();
                    while (it3.hasNext()) {
                        Comparable comparable2 = (Comparable) it3.next();
                        if (comparable.compareTo(comparable2) > 0) {
                            comparable = comparable2;
                        }
                    }
                } else {
                    comparable = null;
                }
                Integer num = (Integer) comparable;
                int iIntValue = num != null ? num.intValue() : 0;
                int size = (listR.size() * 0) + string.length();
                g.h0.b.l<String, String> lVarG = g.m0.f.g("");
                int iM = g.c0.g.m(listR);
                ArrayList arrayList3 = new ArrayList();
                for (Object obj2 : listR) {
                    int i2 = length + 1;
                    if (length < 0) {
                        g.c0.g.D();
                        throw null;
                    }
                    String str2 = (String) obj2;
                    if ((length == 0 || length == iM) && g.m0.f.o(str2)) {
                        str2 = null;
                    } else {
                        String strInvoke = lVarG.invoke(f.a.y.a.O(str2, iIntValue));
                        if (strInvoke != null) {
                            str2 = strInvoke;
                        }
                    }
                    if (str2 != null) {
                        arrayList3.add(str2);
                    }
                    length = i2;
                }
                StringBuilder sb = new StringBuilder(size);
                g.c0.g.q(arrayList3, sb, "\n", null, null, 0, null, null, 124);
                String string2 = sb.toString();
                g.h0.c.l.e(string2, "mapIndexedNotNull { inde…\"\\n\")\n        .toString()");
                throw new IllegalArgumentException(string2);
            }
        }
        f4581b = new e1("kotlinx.serialization.json.JsonLiteral", iVar);
    }

    @Override // h.b.b, h.b.j, h.b.a
    public h.b.m.e a() {
        return f4581b;
    }

    @Override // h.b.a
    public Object c(h.b.n.e eVar) {
        g.h0.c.l.f(eVar, "decoder");
        h hVarI = f.a.y.a.q(eVar).i();
        if (hVarI instanceof r) {
            return (r) hVarI;
        }
        StringBuilder sbB = d.b.a.a.a.B("Unexpected JSON element, expected JsonLiteral, had ");
        sbB.append(b0.a(hVarI.getClass()));
        throw f.a.y.a.f(-1, sbB.toString(), hVarI.toString());
    }

    @Override // h.b.j
    public void d(h.b.n.f fVar, Object obj) {
        r rVar = (r) obj;
        g.h0.c.l.f(fVar, "encoder");
        g.h0.c.l.f(rVar, "value");
        f.a.y.a.l(fVar);
        if (rVar.a) {
            fVar.F(rVar.f4580b);
            return;
        }
        g.h0.c.l.f(rVar, "<this>");
        Long lO = g.m0.f.O(rVar.b());
        if (lO != null) {
            fVar.C(lO.longValue());
            return;
        }
        g.u uVarQ = g.m0.f.Q(rVar.f4580b);
        if (uVarQ != null) {
            long j2 = uVarQ.f4197e;
            f.a.y.a.I0(g.u.f4196b);
            y1 y1Var = y1.a;
            fVar.y(y1.f4468b).C(j2);
            return;
        }
        g.h0.c.l.f(rVar, "<this>");
        String strB = rVar.b();
        g.h0.c.l.f(strB, "<this>");
        Double dValueOf = null;
        try {
            if (g.m0.d.a.a(strB)) {
                dValueOf = Double.valueOf(Double.parseDouble(strB));
            }
        } catch (NumberFormatException unused) {
        }
        if (dValueOf != null) {
            fVar.i(dValueOf.doubleValue());
            return;
        }
        Boolean boolZ = f.a.y.a.Z(rVar);
        if (boolZ != null) {
            fVar.l(boolZ.booleanValue());
        } else {
            fVar.F(rVar.f4580b);
        }
    }
}
