package C1;

import I2.Q;
import I2.S;
import I2.V;
import J0.C0374n0;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.LinearGradient;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.graphics.SweepGradient;
import android.util.AttributeSet;
import android.util.Xml;
import com.google.android.gms.internal.play_billing.zzc;
import com.google.android.gms.internal.play_billing.zzie;
import com.google.android.gms.internal.play_billing.zzp;
import com.google.android.gms.internal.play_billing.zzr;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import kotlin.jvm.internal.F;
import l5.C;
import l5.s;
import l5.v;
import m3.AbstractC2467b;
import m5.t;
import m5.u;
import m5.y;
import org.xmlpull.v1.XmlPullParserException;
import w1.AbstractC3135a;
import w4.AbstractC3139a;
import w4.C3137A;
import w4.C3140b;
import x4.C3249o;

/* JADX INFO: loaded from: classes.dex */
public final class k implements zzr {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f689a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f690b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Object f691c;

    public /* synthetic */ k(int i6, boolean z6) {
        this.f689a = i6;
    }

    /* JADX WARN: Removed duplicated region for block: B:30:0x009f  */
    /* JADX WARN: Removed duplicated region for block: B:31:0x00a3  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object a(k kVar, C3140b c3140b, C4.a aVar) {
        u uVar;
        byte bF;
        LinkedHashMap linkedHashMap;
        k kVar2;
        byte bE;
        LinkedHashMap linkedHashMap2;
        if (aVar instanceof u) {
            uVar = (u) aVar;
            int i6 = uVar.f21286j;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                uVar.f21286j = i6 - Integer.MIN_VALUE;
            } else {
                uVar = new u(kVar, aVar);
            }
        }
        Object obj = uVar.f21284e;
        B4.a aVar2 = B4.a.f492a;
        int i7 = uVar.f21286j;
        if (i7 == 0) {
            AbstractC2467b.l(obj);
            y yVar = (y) kVar.f691c;
            bF = yVar.f((byte) 6);
            if (yVar.q() == 4) {
                y.m(yVar, "Unexpected leading comma", 0, null, 6);
                throw null;
            }
            linkedHashMap = new LinkedHashMap();
        } else {
            if (i7 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            String str = uVar.f21283d;
            linkedHashMap2 = uVar.f21282c;
            kVar2 = uVar.f21281b;
            C3140b c3140b2 = uVar.f21280a;
            AbstractC2467b.l(obj);
            linkedHashMap2.put(str, (l5.m) obj);
            bE = ((y) kVar2.f691c).e();
            if (bE != 4) {
                if (bE != 7) {
                    y.m((y) kVar2.f691c, "Expected end of the object or comma", 0, null, 6);
                    throw null;
                }
                y yVar2 = (y) kVar2.f691c;
                if (bE != 6) {
                    yVar2.f((byte) 7);
                } else if (bE == 4) {
                    m5.l.l(yVar2, "object");
                    throw null;
                }
                return new l5.y(linkedHashMap2);
            }
            bF = bE;
            kVar = kVar2;
            linkedHashMap = linkedHashMap2;
            c3140b = c3140b2;
        }
        y yVar3 = (y) kVar.f691c;
        if (!yVar3.b()) {
            byte b5 = bF;
            kVar2 = kVar;
            bE = b5;
            linkedHashMap2 = linkedHashMap;
            y yVar22 = (y) kVar2.f691c;
            if (bE != 6) {
            }
            return new l5.y(linkedHashMap2);
        }
        String strI = yVar3.i();
        yVar3.f((byte) 5);
        uVar.f21280a = c3140b;
        uVar.f21281b = kVar;
        uVar.f21282c = linkedHashMap;
        uVar.f21283d = strI;
        uVar.f21286j = 1;
        c3140b.getClass();
        c3140b.f25458b = uVar;
        return aVar2;
    }

    /* JADX WARN: Code restructure failed: missing block: B:100:0x01df, code lost:
    
        throw new org.xmlpull.v1.XmlPullParserException(r3.getPositionDescription() + ": <item> tag requires a 'color' attribute and a 'offset' attribute!");
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static k d(Resources resources, int i6, Resources.Theme theme) throws XmlPullParserException, IOException {
        int next;
        float f6;
        int i7;
        float f7;
        float f8;
        Shader radialGradient;
        XmlResourceParser xml = resources.getXml(i6);
        AttributeSet attributeSetAsAttributeSet = Xml.asAttributeSet(xml);
        do {
            next = xml.next();
            if (next == 2) {
                break;
            }
        } while (next != 1);
        if (next != 2) {
            throw new XmlPullParserException("No start tag found");
        }
        String name = xml.getName();
        name.getClass();
        if (!name.equals("gradient")) {
            if (name.equals("selector")) {
                ColorStateList colorStateListB = y1.c.b(theme, resources, xml, attributeSetAsAttributeSet);
                return new k(null, colorStateListB, colorStateListB.getDefaultColor());
            }
            throw new XmlPullParserException(xml.getPositionDescription() + ": unsupported complex color tag " + name);
        }
        String name2 = xml.getName();
        if (!name2.equals("gradient")) {
            throw new XmlPullParserException(xml.getPositionDescription() + ": invalid gradient color tag " + name2);
        }
        TypedArray typedArrayE = y1.b.e(resources, theme, attributeSetAsAttributeSet, AbstractC3135a.f25445d);
        float f9 = !(xml.getAttributeValue("http://schemas.android.com/apk/res/android", "startX") != null) ? 0.0f : typedArrayE.getFloat(8, 0.0f);
        float f10 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "startY") != null ? typedArrayE.getFloat(9, 0.0f) : 0.0f;
        float f11 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "endX") != null ? typedArrayE.getFloat(10, 0.0f) : 0.0f;
        float f12 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "endY") != null ? typedArrayE.getFloat(11, 0.0f) : 0.0f;
        float f13 = !(xml.getAttributeValue("http://schemas.android.com/apk/res/android", "centerX") != null) ? 0.0f : typedArrayE.getFloat(3, 0.0f);
        float f14 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "centerY") != null ? typedArrayE.getFloat(4, 0.0f) : 0.0f;
        int i8 = !(xml.getAttributeValue("http://schemas.android.com/apk/res/android", "type") != null) ? 0 : typedArrayE.getInt(2, 0);
        int color = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "startColor") != null ? typedArrayE.getColor(0, 0) : 0;
        boolean z6 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "centerColor") != null;
        int color2 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "centerColor") != null ? typedArrayE.getColor(7, 0) : 0;
        int color3 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "endColor") != null ? typedArrayE.getColor(1, 0) : 0;
        if (xml.getAttributeValue("http://schemas.android.com/apk/res/android", "tileMode") != null) {
            f6 = f9;
            i7 = typedArrayE.getInt(6, 0);
        } else {
            f6 = f9;
            i7 = 0;
        }
        float f15 = xml.getAttributeValue("http://schemas.android.com/apk/res/android", "gradientRadius") != null ? typedArrayE.getFloat(5, 0.0f) : 0.0f;
        typedArrayE.recycle();
        int depth = xml.getDepth() + 1;
        ArrayList arrayList = new ArrayList(20);
        float f16 = f15;
        ArrayList arrayList2 = new ArrayList(20);
        while (true) {
            int next2 = xml.next();
            f7 = f10;
            if (next2 == 1) {
                f8 = f11;
                break;
            }
            int depth2 = xml.getDepth();
            f8 = f11;
            if (depth2 < depth && next2 == 3) {
                break;
            }
            if (next2 == 2 && depth2 <= depth && xml.getName().equals("item")) {
                TypedArray typedArrayE2 = y1.b.e(resources, theme, attributeSetAsAttributeSet, AbstractC3135a.f25446e);
                boolean zHasValue = typedArrayE2.hasValue(0);
                boolean zHasValue2 = typedArrayE2.hasValue(1);
                if (!zHasValue || !zHasValue2) {
                    break;
                }
                int color4 = typedArrayE2.getColor(0, 0);
                float f17 = typedArrayE2.getFloat(1, 0.0f);
                typedArrayE2.recycle();
                arrayList2.add(Integer.valueOf(color4));
                arrayList.add(Float.valueOf(f17));
            }
            f10 = f7;
            f11 = f8;
        }
        C0374n0 c0374n0 = arrayList2.size() > 0 ? new C0374n0(arrayList2, arrayList) : null;
        if (c0374n0 == null) {
            c0374n0 = z6 ? new C0374n0(color, color2, color3) : new C0374n0(color, color3);
        }
        if (i8 != 1) {
            if (i8 != 2) {
                radialGradient = new LinearGradient(f6, f7, f8, f12, c0374n0.f3037a, c0374n0.f3038b, i7 != 1 ? i7 != 2 ? Shader.TileMode.CLAMP : Shader.TileMode.MIRROR : Shader.TileMode.REPEAT);
            } else {
                radialGradient = new SweepGradient(f13, f14, c0374n0.f3037a, c0374n0.f3038b);
            }
        } else {
            if (f16 <= 0.0f) {
                throw new XmlPullParserException("<gradient> tag requires 'gradientRadius' attribute with radial type");
            }
            radialGradient = new RadialGradient(f13, f14, f16, c0374n0.f3037a, c0374n0.f3038b, i7 != 1 ? i7 != 2 ? Shader.TileMode.CLAMP : Shader.TileMode.MIRROR : Shader.TileMode.REPEAT);
        }
        return new k(radialGradient, null, 0);
    }

    public void b(long j4) {
        if (c(j4)) {
            return;
        }
        int i6 = this.f690b;
        long[] jArrCopyOf = (long[]) this.f691c;
        if (i6 >= jArrCopyOf.length) {
            jArrCopyOf = Arrays.copyOf(jArrCopyOf, Math.max(i6 + 1, jArrCopyOf.length * 2));
            kotlin.jvm.internal.o.g(jArrCopyOf, "copyOf(...)");
            this.f691c = jArrCopyOf;
        }
        jArrCopyOf[i6] = j4;
        if (i6 >= this.f690b) {
            this.f690b = i6 + 1;
        }
    }

    public boolean c(long j4) {
        int i6 = this.f690b;
        for (int i7 = 0; i7 < i6; i7++) {
            if (((long[]) this.f691c)[i7] == j4) {
                return true;
            }
        }
        return false;
    }

    public void e(int i6, int i7) {
        int i8 = i7 + i6;
        char[] cArr = (char[]) this.f691c;
        if (cArr.length <= i8) {
            int i9 = i6 * 2;
            if (i8 < i9) {
                i8 = i9;
            }
            char[] cArrCopyOf = Arrays.copyOf(cArr, i8);
            kotlin.jvm.internal.o.g(cArrCopyOf, "copyOf(...)");
            this.f691c = cArrCopyOf;
        }
    }

    public l5.m f() {
        l5.m yVar;
        Object obj;
        y yVar2 = (y) this.f691c;
        byte bQ = yVar2.q();
        if (bQ == 1) {
            return h(true);
        }
        if (bQ == 0) {
            return h(false);
        }
        if (bQ != 6) {
            if (bQ == 8) {
                return g();
            }
            y.m(yVar2, "Cannot read Json element because of unexpected ".concat(m5.l.r(bQ)), 0, null, 6);
            throw null;
        }
        int i6 = this.f690b + 1;
        this.f690b = i6;
        if (i6 == 200) {
            t tVar = new t(this, null);
            B4.a aVar = AbstractC3139a.f25456a;
            C3140b c3140b = new C3140b();
            c3140b.f25457a = tVar;
            c3140b.f25458b = c3140b;
            B4.a aVar2 = AbstractC3139a.f25456a;
            c3140b.f25459c = aVar2;
            while (true) {
                obj = c3140b.f25459c;
                A4.d dVar = c3140b.f25458b;
                if (dVar == null) {
                    break;
                }
                if (kotlin.jvm.internal.o.c(aVar2, obj)) {
                    try {
                        t tVar2 = c3140b.f25457a;
                        F.c(3, tVar2);
                        t tVar3 = new t(tVar2.f21279c, dVar);
                        tVar3.f21278b = c3140b;
                        Object objInvokeSuspend = tVar3.invokeSuspend(C3137A.f25453a);
                        if (objInvokeSuspend != B4.a.f492a) {
                            dVar.resumeWith(objInvokeSuspend);
                        }
                    } catch (Throwable th) {
                        dVar.resumeWith(AbstractC2467b.d(th));
                    }
                } else {
                    c3140b.f25459c = aVar2;
                    dVar.resumeWith(obj);
                }
            }
            AbstractC2467b.l(obj);
            yVar = (l5.m) obj;
        } else {
            byte bF = yVar2.f((byte) 6);
            if (yVar2.q() == 4) {
                y.m(yVar2, "Unexpected leading comma", 0, null, 6);
                throw null;
            }
            LinkedHashMap linkedHashMap = new LinkedHashMap();
            while (true) {
                if (!yVar2.b()) {
                    break;
                }
                String strI = yVar2.i();
                yVar2.f((byte) 5);
                linkedHashMap.put(strI, f());
                bF = yVar2.e();
                if (bF != 4) {
                    if (bF != 7) {
                        y.m(yVar2, "Expected end of the object or comma", 0, null, 6);
                        throw null;
                    }
                }
            }
            if (bF == 6) {
                yVar2.f((byte) 7);
            } else if (bF == 4) {
                m5.l.l(yVar2, "object");
                throw null;
            }
            yVar = new l5.y(linkedHashMap);
        }
        this.f690b--;
        return yVar;
    }

    public l5.e g() {
        y yVar = (y) this.f691c;
        byte bE = yVar.e();
        if (yVar.q() == 4) {
            y.m(yVar, "Unexpected leading comma", 0, null, 6);
            throw null;
        }
        ArrayList arrayList = new ArrayList();
        while (yVar.b()) {
            arrayList.add(f());
            bE = yVar.e();
            if (bE != 4) {
                boolean z6 = bE == 9;
                int i6 = yVar.f21304b;
                if (!z6) {
                    y.m(yVar, "Expected end of the array or comma", i6, null, 4);
                    throw null;
                }
            }
        }
        if (bE == 8) {
            yVar.f((byte) 9);
        } else if (bE == 4) {
            m5.l.l(yVar, "array");
            throw null;
        }
        return new l5.e(arrayList);
    }

    public C h(boolean z6) {
        y yVar = (y) this.f691c;
        String strJ = !z6 ? yVar.j() : yVar.i();
        return (z6 || !kotlin.jvm.internal.o.c(strJ, "null")) ? new s(strJ, z6, null) : v.INSTANCE;
    }

    public void i() {
        m5.d dVar = m5.d.f21245c;
        char[] array = (char[]) this.f691c;
        dVar.getClass();
        kotlin.jvm.internal.o.h(array, "array");
        synchronized (dVar) {
            int i6 = dVar.f1378a;
            if (array.length + i6 < m5.c.f21244a) {
                dVar.f1378a = i6 + array.length;
                ((C3249o) dVar.f1379b).addLast(array);
            }
        }
    }

    public void j(long j4) {
        int i6 = this.f690b;
        int i7 = 0;
        while (i7 < i6) {
            if (j4 == ((long[]) this.f691c)[i7]) {
                int i8 = this.f690b - 1;
                while (i7 < i8) {
                    long[] jArr = (long[]) this.f691c;
                    int i9 = i7 + 1;
                    jArr[i7] = jArr[i9];
                    i7 = i9;
                }
                this.f690b--;
                return;
            }
            i7++;
        }
    }

    public void k(String text) {
        kotlin.jvm.internal.o.h(text, "text");
        int length = text.length();
        if (length == 0) {
            return;
        }
        e(this.f690b, length);
        text.getChars(0, text.length(), (char[]) this.f691c, this.f690b);
        this.f690b += length;
    }

    public String toString() {
        switch (this.f689a) {
            case 5:
                return new String((char[]) this.f691c, 0, this.f690b);
            default:
                return super.toString();
        }
    }

    @Override // com.google.android.gms.internal.play_billing.zzr
    public Object zza(zzp zzpVar) {
        S s6 = (S) this.f691c;
        int i6 = this.f690b;
        try {
            if (s6.f2532J == null) {
                throw null;
            }
            s6.f2532J.zza(s6.f2530H.getPackageName(), i6 != 2 ? i6 != 3 ? i6 != 4 ? i6 != 5 ? i6 != 6 ? "QUERY_PRODUCT_DETAILS_ASYNC" : "START_CONNECTION" : "IS_FEATURE_SUPPORTED" : "CONSUME_ASYNC" : "ACKNOWLEDGE_PURCHASE" : "LAUNCH_BILLING_FLOW", new Q(zzpVar));
            return "billingOverrideService.getBillingOverride";
        } catch (Exception e6) {
            s6.P(28, V.f2541E, zzie.BILLING_OVERRIDE_SERVICE_CALL_EXCEPTION);
            zzc.zzo("BillingClientTesting", "An error occurred while retrieving billing override.", e6);
            zzpVar.zzb(0);
            return "billingOverrideService.getBillingOverride";
        }
    }

    public /* synthetic */ k(S s6, int i6) {
        this.f689a = 4;
        this.f691c = s6;
        this.f690b = i6;
    }

    public k(l5.j jVar, y yVar) {
        this.f689a = 6;
        this.f691c = yVar;
    }

    public k(int i6, List list) {
        this.f689a = 2;
        this.f690b = i6;
        this.f691c = list;
    }

    public k(Shader shader, ColorStateList colorStateList, int i6) {
        this.f689a = 8;
        this.f691c = shader;
        this.f690b = i6;
    }

    public k(int i6) {
        this.f689a = i6;
        switch (i6) {
            case 7:
                this.f690b = 0;
                this.f691c = new StringBuilder();
                break;
            default:
                this.f690b = 1;
                this.f691c = Collections.singletonList(null);
                break;
        }
    }

    public k(ArrayList arrayList) {
        this.f689a = 0;
        this.f690b = 0;
        this.f691c = arrayList;
    }
}
