package androidx.core.view;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;

/* JADX INFO: loaded from: classes.dex */
public final class y0 implements Iterator, td.a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final sd.l f1863a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ArrayList f1864b = new ArrayList();

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

    public y0(Iterator it, sd.l lVar) {
        this.f1863a = lVar;
        this.f1865c = it;
    }

    @Override // java.util.Iterator
    public final boolean hasNext() {
        return this.f1865c.hasNext();
    }

    @Override // java.util.Iterator
    public final Object next() {
        Object next = this.f1865c.next();
        Iterator it = (Iterator) this.f1863a.invoke(next);
        ArrayList arrayList = this.f1864b;
        if (it == null || !it.hasNext()) {
            while (!this.f1865c.hasNext() && (!arrayList.isEmpty())) {
                this.f1865c = (Iterator) kotlin.collections.n.k1(arrayList);
                if (arrayList.isEmpty()) {
                    throw new NoSuchElementException("List is empty.");
                }
                arrayList.remove(hb.a.b0(arrayList));
            }
        } else {
            arrayList.add(this.f1865c);
            this.f1865c = it;
        }
        return next;
    }

    @Override // java.util.Iterator
    public final void remove() {
        throw new UnsupportedOperationException("Operation is not supported for read-only collection");
    }
}
