package F4;

import A4.r;
import B4.C0022s;
import B4.C0026w;
import B4.W;
import B4.e0;
import d4.C0547f;
import d4.C0550i;
import e4.AbstractC0565i;
import e4.AbstractC0566j;
import e4.AbstractC0567k;
import e4.C0574r;
import i4.EnumC0643a;
import j4.AbstractC0801c;
import j4.InterfaceC0802d;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import p0.AbstractC0928a;
import r4.AbstractC0983h;

/* JADX INFO: loaded from: classes.dex */
public final class l extends AbstractC0801c implements E4.e {

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final E4.e f744k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final h4.h f745l;

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

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public h4.h f747n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public h4.c f748o;

    public l(E4.e eVar, h4.h hVar) {
        super(j.f742k, h4.i.f6533k);
        this.f744k = eVar;
        this.f745l = hVar;
        this.f746m = ((Number) hVar.n(0, new C0022s(3))).intValue();
    }

    public final Object d(h4.c cVar, Object obj) {
        List listR;
        Comparable comparable;
        String strSubstring;
        h4.h context = cVar.getContext();
        W w5 = (W) context.h(C0026w.f271l);
        if (w5 != null && !w5.a()) {
            throw ((e0) w5).y();
        }
        h4.h hVar = this.f747n;
        if (hVar != context) {
            int i = 0;
            if (hVar instanceof h) {
                String str = "\n            Flow exception transparency is violated:\n                Previous 'emit' call has thrown exception " + ((h) hVar).f741l + ", 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            ";
                AbstractC0983h.e("<this>", str);
                A4.d dVar = new A4.d(str);
                if (dVar.hasNext()) {
                    Object next = dVar.next();
                    if (dVar.hasNext()) {
                        ArrayList arrayList = new ArrayList();
                        arrayList.add(next);
                        while (dVar.hasNext()) {
                            arrayList.add(dVar.next());
                        }
                        listR = arrayList;
                    } else {
                        listR = AbstractC0566j.r(next);
                    }
                } else {
                    listR = C0574r.f6259k;
                }
                ArrayList<String> arrayList2 = new ArrayList();
                for (Object obj2 : listR) {
                    if (!A4.i.P((String) obj2)) {
                        arrayList2.add(obj2);
                    }
                }
                ArrayList arrayList3 = new ArrayList(AbstractC0567k.Z(arrayList2));
                for (String str2 : arrayList2) {
                    int length = str2.length();
                    int length2 = 0;
                    while (true) {
                        if (length2 >= length) {
                            length2 = -1;
                            break;
                        }
                        if (!S4.d.y(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();
                listR.size();
                int iL = AbstractC0566j.l(listR);
                ArrayList arrayList4 = new ArrayList();
                for (Object obj3 : listR) {
                    int i5 = i + 1;
                    if (i < 0) {
                        AbstractC0566j.y();
                        throw null;
                    }
                    String str3 = (String) obj3;
                    if ((i == 0 || i == iL) && A4.i.P(str3)) {
                        strSubstring = null;
                    } else {
                        AbstractC0983h.e("<this>", str3);
                        if (iIntValue < 0) {
                            throw new IllegalArgumentException(AbstractC0928a.j(iIntValue, "Requested character count ", " is less than zero.").toString());
                        }
                        int length4 = str3.length();
                        if (iIntValue <= length4) {
                            length4 = iIntValue;
                        }
                        strSubstring = str3.substring(length4);
                        AbstractC0983h.d("substring(...)", strSubstring);
                    }
                    if (strSubstring != null) {
                        arrayList4.add(strSubstring);
                    }
                    i = i5;
                }
                StringBuilder sb = new StringBuilder(length3);
                AbstractC0565i.h0(arrayList4, sb, "\n", "", "", "...", null);
                throw new IllegalStateException(sb.toString().toString());
            }
            if (((Number) context.n(0, new r(2, this))).intValue() != this.f746m) {
                throw new IllegalStateException(("Flow invariant is violated:\n\t\tFlow was collected in " + this.f745l + ",\n\t\tbut emission happened in " + context + ".\n\t\tPlease refer to 'flow' documentation or use 'flowOn' instead").toString());
            }
            this.f747n = context;
        }
        this.f748o = cVar;
        m mVar = n.f750a;
        E4.e eVar = this.f744k;
        AbstractC0983h.c("null cannot be cast to non-null type kotlinx.coroutines.flow.FlowCollector<kotlin.Any?>", eVar);
        mVar.getClass();
        Object objEmit = eVar.emit(obj, this);
        if (!AbstractC0983h.a(objEmit, EnumC0643a.f6670k)) {
            this.f748o = null;
        }
        return objEmit;
    }

    @Override // E4.e
    public final Object emit(Object obj, h4.c cVar) {
        try {
            Object objD = d(cVar, obj);
            return objD == EnumC0643a.f6670k ? objD : C0550i.f6143a;
        } catch (Throwable th) {
            this.f747n = new h(cVar.getContext(), th);
            throw th;
        }
    }

    @Override // j4.AbstractC0799a, j4.InterfaceC0802d
    public final InterfaceC0802d getCallerFrame() {
        h4.c cVar = this.f748o;
        if (cVar instanceof InterfaceC0802d) {
            return (InterfaceC0802d) cVar;
        }
        return null;
    }

    @Override // j4.AbstractC0801c, h4.c
    public final h4.h getContext() {
        h4.h hVar = this.f747n;
        return hVar == null ? h4.i.f6533k : hVar;
    }

    @Override // j4.AbstractC0799a
    public final StackTraceElement getStackTraceElement() {
        return null;
    }

    @Override // j4.AbstractC0799a
    public final Object invokeSuspend(Object obj) {
        Throwable thA = C0547f.a(obj);
        if (thA != null) {
            this.f747n = new h(getContext(), thA);
        }
        h4.c cVar = this.f748o;
        if (cVar != null) {
            cVar.resumeWith(obj);
        }
        return EnumC0643a.f6670k;
    }
}
