package R4;

import java.util.Iterator;
import java.util.NoSuchElementException;
import n.L;
import n.M;
import n.P;
import n.Q;

/* JADX INFO: loaded from: classes3.dex */
public final class i implements Iterator, K4.a {

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

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final /* synthetic */ Object f6106d;

    public i(r rVar) {
        this.f6103a = 1;
        this.f6106d = rVar;
        this.f6105c = rVar.f6117a.iterator();
    }

    public void a() {
        Object objInvoke;
        int i6 = this.f6104b;
        j jVar = (j) this.f6106d;
        if (i6 == -2) {
            objInvoke = ((J4.a) jVar.f6108b).invoke();
        } else {
            J4.c cVar = (J4.c) jVar.f6109c;
            Object obj = this.f6105c;
            kotlin.jvm.internal.o.e(obj);
            objInvoke = cVar.invoke(obj);
        }
        this.f6105c = objInvoke;
        this.f6104b = objInvoke == null ? 0 : 1;
    }

    @Override // java.util.Iterator
    public final boolean hasNext() {
        r rVar;
        Iterator it;
        switch (this.f6103a) {
            case 0:
                if (this.f6104b < 0) {
                    a();
                }
                return this.f6104b == 1;
            case 1:
                break;
            case 2:
                return ((l) this.f6105c).hasNext();
            default:
                return ((l) this.f6105c).hasNext();
        }
        while (true) {
            int i6 = this.f6104b;
            rVar = (r) this.f6106d;
            int i7 = rVar.f6118b;
            it = (Iterator) this.f6105c;
            if (i6 < i7 && it.hasNext()) {
                it.next();
                this.f6104b++;
            }
        }
        return this.f6104b < rVar.f6119c && it.hasNext();
    }

    @Override // java.util.Iterator
    public final Object next() {
        r rVar;
        Iterator it;
        switch (this.f6103a) {
            case 0:
                if (this.f6104b < 0) {
                    a();
                }
                if (this.f6104b == 0) {
                    throw new NoSuchElementException();
                }
                Object obj = this.f6105c;
                kotlin.jvm.internal.o.f(obj, "null cannot be cast to non-null type T of kotlin.sequences.GeneratorSequence");
                this.f6104b = -1;
                return obj;
            case 1:
                break;
            case 2:
                return ((l) this.f6105c).next();
            default:
                return ((l) this.f6105c).next();
        }
        while (true) {
            int i6 = this.f6104b;
            rVar = (r) this.f6106d;
            int i7 = rVar.f6118b;
            it = (Iterator) this.f6105c;
            if (i6 < i7 && it.hasNext()) {
                it.next();
                this.f6104b++;
            }
        }
        int i8 = this.f6104b;
        if (i8 >= rVar.f6119c) {
            throw new NoSuchElementException();
        }
        this.f6104b = i8 + 1;
        return it.next();
    }

    @Override // java.util.Iterator
    public final void remove() {
        switch (this.f6103a) {
            case 0:
                throw new UnsupportedOperationException("Operation is not supported for read-only collection");
            case 1:
                throw new UnsupportedOperationException("Operation is not supported for read-only collection");
            case 2:
                int i6 = this.f6104b;
                if (i6 != -1) {
                    ((M) this.f6106d).f21355b.h(i6);
                    this.f6104b = -1;
                    return;
                }
                return;
            default:
                int i7 = this.f6104b;
                if (i7 != -1) {
                    ((Q) this.f6106d).f21369b.m(i7);
                    this.f6104b = -1;
                    return;
                }
                return;
        }
    }

    public i(j jVar) {
        this.f6103a = 0;
        this.f6106d = jVar;
        this.f6104b = -2;
    }

    public i(Q q6) {
        this.f6103a = 3;
        this.f6106d = q6;
        this.f6104b = -1;
        this.f6105c = A4.g.L(new P(q6, this, null));
    }

    public i(M m6) {
        this.f6103a = 2;
        this.f6106d = m6;
        this.f6104b = -1;
        this.f6105c = A4.g.L(new L(m6, this, null));
    }
}
