package Z4;

import B.C0053c;
import V4.E;
import Y4.InterfaceC0844j;
import w4.C3137A;

/* JADX INFO: loaded from: classes3.dex */
public final class x extends C4.c implements InterfaceC0844j {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final InterfaceC0844j f9215a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final A4.j f9216b;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public A4.j f9218d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public A4.d f9219e;

    public x(InterfaceC0844j interfaceC0844j, A4.j jVar) {
        super(A4.k.f106a, v.f9213a);
        this.f9215a = interfaceC0844j;
        this.f9216b = jVar;
        this.f9217c = ((Number) jVar.fold(0, new T0.z(22))).intValue();
    }

    public final Object d(A4.d dVar, Object obj) {
        A4.j context = dVar.getContext();
        E.m(context);
        A4.j jVar = this.f9218d;
        if (jVar != context) {
            if (jVar instanceof t) {
                throw new IllegalStateException(S4.q.p0("\n            Flow exception transparency is violated:\n                Previous 'emit' call has thrown exception " + ((t) jVar).f9212b + ", 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            ").toString());
            }
            if (((Number) context.fold(0, new C0053c(this, 14))).intValue() != this.f9217c) {
                throw new IllegalStateException(("Flow invariant is violated:\n\t\tFlow was collected in " + this.f9216b + ",\n\t\tbut emission happened in " + context + ".\n\t\tPlease refer to 'flow' documentation or use 'flowOn' instead").toString());
            }
            this.f9218d = context;
        }
        this.f9219e = dVar;
        y yVar = z.f9221a;
        InterfaceC0844j interfaceC0844j = this.f9215a;
        kotlin.jvm.internal.o.f(interfaceC0844j, "null cannot be cast to non-null type kotlinx.coroutines.flow.FlowCollector<kotlin.Any?>");
        yVar.getClass();
        Object objEmit = interfaceC0844j.emit(obj, this);
        if (!kotlin.jvm.internal.o.c(objEmit, B4.a.f492a)) {
            this.f9219e = null;
        }
        return objEmit;
    }

    @Override // Y4.InterfaceC0844j
    public final Object emit(Object obj, A4.d dVar) {
        try {
            Object objD = d(dVar, obj);
            return objD == B4.a.f492a ? objD : C3137A.f25453a;
        } catch (Throwable th) {
            this.f9218d = new t(dVar.getContext(), th);
            throw th;
        }
    }

    @Override // C4.a, C4.d
    public final C4.d getCallerFrame() {
        A4.d dVar = this.f9219e;
        if (dVar instanceof C4.d) {
            return (C4.d) dVar;
        }
        return null;
    }

    @Override // C4.c, A4.d
    public final A4.j getContext() {
        A4.j jVar = this.f9218d;
        return jVar == null ? A4.k.f106a : jVar;
    }

    @Override // C4.a
    public final StackTraceElement getStackTraceElement() {
        return null;
    }

    @Override // C4.a
    public final Object invokeSuspend(Object obj) {
        Throwable thA = w4.n.a(obj);
        if (thA != null) {
            this.f9218d = new t(getContext(), thA);
        }
        A4.d dVar = this.f9219e;
        if (dVar != null) {
            dVar.resumeWith(obj);
        }
        return B4.a.f492a;
    }
}
