package d7;

import Z6.AbstractC0385z;
import c7.InterfaceC0597e;
import com.google.android.gms.internal.measurement.C1;
import com.google.android.gms.internal.measurement.X1;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public final class w extends G6.c implements InterfaceC0597e {

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final InterfaceC0597e f12388t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public final E6.i f12389u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final int f12390v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public E6.i f12391w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public E6.d f12392x;

    public w(InterfaceC0597e interfaceC0597e, E6.i iVar) {
        super(u.f12386q, E6.j.f2226q);
        this.f12388t = interfaceC0597e;
        this.f12389u = iVar;
        this.f12390v = ((Number) iVar.O(0, new E6.b(5))).intValue();
    }

    @Override // G6.a, G6.d
    public final G6.d f() {
        E6.d dVar = this.f12392x;
        if (dVar instanceof G6.d) {
            return (G6.d) dVar;
        }
        return null;
    }

    @Override // G6.c, E6.d
    public final E6.i h() {
        E6.i iVar = this.f12391w;
        return iVar == null ? E6.j.f2226q : iVar;
    }

    @Override // c7.InterfaceC0597e
    public final Object l(Object obj, E6.d dVar) {
        try {
            Object objR = r(dVar, obj);
            return objR == F6.a.f2580q ? objR : A6.n.f457a;
        } catch (Throwable th) {
            this.f12391w = new q(dVar.h(), th);
            throw th;
        }
    }

    @Override // G6.a
    public final StackTraceElement n() {
        return null;
    }

    @Override // G6.a
    public final Object p(Object obj) {
        Throwable thA = A6.j.a(obj);
        if (thA != null) {
            this.f12391w = new q(h(), thA);
        }
        E6.d dVar = this.f12392x;
        if (dVar != null) {
            dVar.i(obj);
        }
        return F6.a.f2580q;
    }

    public final Object r(E6.d dVar, Object obj) {
        List listC;
        Comparable comparable;
        String strSubstring;
        E6.i iVarH = dVar.h();
        AbstractC0385z.i(iVarH);
        E6.i iVar = this.f12391w;
        if (iVar != iVarH) {
            int i = 0;
            if (iVar instanceof q) {
                String str = "\n            Flow exception transparency is violated:\n                Previous 'emit' call has thrown exception " + ((q) iVar).f12381r + ", but then emission attempt of value '" + obj + "' has been detected.\n                Emissions from 'catch' blocks are prohibited in order to avoid unspecified behaviour, 'Flow.catch' operator can be used instead.\n                For a more detailed explanation, please refer to Flow documentation.\n            ";
                P6.g.e(str, "<this>");
                X6.c cVar = new X6.c(str);
                if (cVar.hasNext()) {
                    Object next = cVar.next();
                    if (cVar.hasNext()) {
                        ArrayList arrayList = new ArrayList();
                        arrayList.add(next);
                        while (cVar.hasNext()) {
                            arrayList.add(cVar.next());
                        }
                        listC = arrayList;
                    } else {
                        listC = C1.C(next);
                    }
                } else {
                    listC = B6.t.f1032q;
                }
                ArrayList arrayList2 = new ArrayList();
                for (Object obj2 : listC) {
                    if (!X6.e.V((String) obj2)) {
                        arrayList2.add(obj2);
                    }
                }
                ArrayList arrayList3 = new ArrayList(B6.m.a0(arrayList2));
                int size = arrayList2.size();
                int i5 = 0;
                while (i5 < size) {
                    Object obj3 = arrayList2.get(i5);
                    i5++;
                    String str2 = (String) obj3;
                    int length = str2.length();
                    int length2 = 0;
                    while (true) {
                        if (length2 >= length) {
                            length2 = -1;
                            break;
                        }
                        if (!X1.s(str2.charAt(length2))) {
                            break;
                        }
                        length2++;
                    }
                    if (length2 == -1) {
                        length2 = str2.length();
                    }
                    arrayList3.add(Integer.valueOf(length2));
                }
                Iterator it = arrayList3.iterator();
                if (it.hasNext()) {
                    comparable = (Comparable) it.next();
                    while (it.hasNext()) {
                        Comparable comparable2 = (Comparable) it.next();
                        if (comparable.compareTo(comparable2) > 0) {
                            comparable = comparable2;
                        }
                    }
                } else {
                    comparable = null;
                }
                Integer num = (Integer) comparable;
                int iIntValue = num != null ? num.intValue() : 0;
                int length3 = str.length();
                listC.size();
                int iV = B6.l.V(listC);
                ArrayList arrayList4 = new ArrayList();
                for (Object obj4 : listC) {
                    int i8 = i + 1;
                    if (i < 0) {
                        B6.l.Z();
                        throw null;
                    }
                    String str3 = (String) obj4;
                    if ((i == 0 || i == iV) && X6.e.V(str3)) {
                        strSubstring = null;
                    } else {
                        P6.g.e(str3, "<this>");
                        if (iIntValue < 0) {
                            throw new IllegalArgumentException(I1.a.k(iIntValue, "Requested character count ", " is less than zero.").toString());
                        }
                        int length4 = str3.length();
                        if (iIntValue <= length4) {
                            length4 = iIntValue;
                        }
                        strSubstring = str3.substring(length4);
                        P6.g.d(strSubstring, "substring(...)");
                    }
                    if (strSubstring != null) {
                        arrayList4.add(strSubstring);
                    }
                    i = i8;
                }
                StringBuilder sb = new StringBuilder(length3);
                B6.k.k0(arrayList4, sb, "\n", "", "", "...", null);
                throw new IllegalStateException(sb.toString().toString());
            }
            if (((Number) iVarH.O(0, new X6.o(2, this))).intValue() != this.f12390v) {
                throw new IllegalStateException(("Flow invariant is violated:\n\t\tFlow was collected in " + this.f12389u + ",\n\t\tbut emission happened in " + iVarH + ".\n\t\tPlease refer to 'flow' documentation or use 'flowOn' instead").toString());
            }
            this.f12391w = iVarH;
        }
        this.f12392x = dVar;
        x xVar = y.f12394a;
        InterfaceC0597e interfaceC0597e = this.f12388t;
        P6.g.c(interfaceC0597e, "null cannot be cast to non-null type kotlinx.coroutines.flow.FlowCollector<kotlin.Any?>");
        xVar.getClass();
        Object objL = interfaceC0597e.l(obj, this);
        if (!P6.g.a(objL, F6.a.f2580q)) {
            this.f12392x = null;
        }
        return objL;
    }
}
