package bn;

import com.google.android.gms.common.api.Api;
import dn.p;
import java.io.File;
import java.util.ArrayDeque;
import java.util.Iterator;
import kotlin.jvm.internal.t;

/* loaded from: classes3.dex */
public final class g implements rp.h {

    /* renamed from: a, reason: collision with root package name */
    private final File f7024a;

    /* renamed from: b, reason: collision with root package name */
    private final h f7025b;

    /* renamed from: c, reason: collision with root package name */
    private final dn.l f7026c;

    /* renamed from: d, reason: collision with root package name */
    private final dn.l f7027d;

    /* renamed from: e, reason: collision with root package name */
    private final p f7028e;

    /* renamed from: f, reason: collision with root package name */
    private final int f7029f;

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes3.dex */
    public static abstract class a extends c {
        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public a(File rootDir) {
            super(rootDir);
            t.g(rootDir, "rootDir");
        }
    }

    /* loaded from: classes3.dex */
    private final class b extends sm.b {

        /* renamed from: r, reason: collision with root package name */
        private final ArrayDeque f7030r;

        /* JADX INFO: Access modifiers changed from: private */
        /* loaded from: classes3.dex */
        public final class a extends a {

            /* renamed from: b, reason: collision with root package name */
            private boolean f7032b;

            /* renamed from: c, reason: collision with root package name */
            private File[] f7033c;

            /* renamed from: d, reason: collision with root package name */
            private int f7034d;

            /* renamed from: e, reason: collision with root package name */
            private boolean f7035e;

            /* renamed from: f, reason: collision with root package name */
            final /* synthetic */ b f7036f;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            public a(b bVar, File rootDir) {
                super(rootDir);
                t.g(rootDir, "rootDir");
                this.f7036f = bVar;
            }

            @Override // bn.g.c
            public File b() {
                if (!this.f7035e && this.f7033c == null) {
                    dn.l lVar = g.this.f7026c;
                    boolean z10 = false;
                    if (lVar != null && !((Boolean) lVar.invoke(a())).booleanValue()) {
                        z10 = true;
                    }
                    if (z10) {
                        return null;
                    }
                    File[] listFiles = a().listFiles();
                    this.f7033c = listFiles;
                    if (listFiles == null) {
                        p pVar = g.this.f7028e;
                        if (pVar != null) {
                            pVar.invoke(a(), new bn.a(a(), null, "Cannot list files in a directory", 2, null));
                        }
                        this.f7035e = true;
                    }
                }
                File[] fileArr = this.f7033c;
                if (fileArr != null) {
                    int i10 = this.f7034d;
                    t.d(fileArr);
                    if (i10 < fileArr.length) {
                        File[] fileArr2 = this.f7033c;
                        t.d(fileArr2);
                        int i11 = this.f7034d;
                        this.f7034d = i11 + 1;
                        return fileArr2[i11];
                    }
                }
                if (!this.f7032b) {
                    this.f7032b = true;
                    return a();
                }
                dn.l lVar2 = g.this.f7027d;
                if (lVar2 != null) {
                    lVar2.invoke(a());
                }
                return null;
            }
        }

        /* renamed from: bn.g$b$b, reason: collision with other inner class name */
        /* loaded from: classes3.dex */
        private final class C0183b extends c {

            /* renamed from: b, reason: collision with root package name */
            private boolean f7037b;

            /* renamed from: c, reason: collision with root package name */
            final /* synthetic */ b f7038c;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            public C0183b(b bVar, File rootFile) {
                super(rootFile);
                t.g(rootFile, "rootFile");
                this.f7038c = bVar;
            }

            @Override // bn.g.c
            public File b() {
                if (this.f7037b) {
                    return null;
                }
                this.f7037b = true;
                return a();
            }
        }

        /* JADX INFO: Access modifiers changed from: private */
        /* loaded from: classes3.dex */
        public final class c extends a {

            /* renamed from: b, reason: collision with root package name */
            private boolean f7039b;

            /* renamed from: c, reason: collision with root package name */
            private File[] f7040c;

            /* renamed from: d, reason: collision with root package name */
            private int f7041d;

            /* renamed from: e, reason: collision with root package name */
            final /* synthetic */ b f7042e;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            public c(b bVar, File rootDir) {
                super(rootDir);
                t.g(rootDir, "rootDir");
                this.f7042e = bVar;
            }

            /* JADX WARN: Code restructure failed: missing block: B:31:0x0083, code lost:
            
                if (r0.length == 0) goto L33;
             */
            @Override // bn.g.c
            /*
                Code decompiled incorrectly, please refer to instructions dump.
            */
            public File b() {
                p pVar;
                if (!this.f7039b) {
                    dn.l lVar = g.this.f7026c;
                    boolean z10 = false;
                    if (lVar != null && !((Boolean) lVar.invoke(a())).booleanValue()) {
                        z10 = true;
                    }
                    if (z10) {
                        return null;
                    }
                    this.f7039b = true;
                    return a();
                }
                File[] fileArr = this.f7040c;
                if (fileArr != null) {
                    int i10 = this.f7041d;
                    t.d(fileArr);
                    if (i10 >= fileArr.length) {
                        dn.l lVar2 = g.this.f7027d;
                        if (lVar2 != null) {
                            lVar2.invoke(a());
                        }
                        return null;
                    }
                }
                if (this.f7040c == null) {
                    File[] listFiles = a().listFiles();
                    this.f7040c = listFiles;
                    if (listFiles == null && (pVar = g.this.f7028e) != null) {
                        pVar.invoke(a(), new bn.a(a(), null, "Cannot list files in a directory", 2, null));
                    }
                    File[] fileArr2 = this.f7040c;
                    if (fileArr2 != null) {
                        t.d(fileArr2);
                    }
                    dn.l lVar3 = g.this.f7027d;
                    if (lVar3 != null) {
                        lVar3.invoke(a());
                    }
                    return null;
                }
                File[] fileArr3 = this.f7040c;
                t.d(fileArr3);
                int i11 = this.f7041d;
                this.f7041d = i11 + 1;
                return fileArr3[i11];
            }
        }

        /* loaded from: classes3.dex */
        public /* synthetic */ class d {

            /* renamed from: a, reason: collision with root package name */
            public static final /* synthetic */ int[] f7043a;

            static {
                int[] iArr = new int[h.values().length];
                try {
                    iArr[h.TOP_DOWN.ordinal()] = 1;
                } catch (NoSuchFieldError unused) {
                }
                try {
                    iArr[h.BOTTOM_UP.ordinal()] = 2;
                } catch (NoSuchFieldError unused2) {
                }
                f7043a = iArr;
            }
        }

        public b() {
            ArrayDeque arrayDeque = new ArrayDeque();
            this.f7030r = arrayDeque;
            if (g.this.f7024a.isDirectory()) {
                arrayDeque.push(e(g.this.f7024a));
            } else if (g.this.f7024a.isFile()) {
                arrayDeque.push(new C0183b(this, g.this.f7024a));
            } else {
                b();
            }
        }

        private final a e(File file) {
            int i10 = d.f7043a[g.this.f7025b.ordinal()];
            if (i10 == 1) {
                return new c(this, file);
            }
            if (i10 == 2) {
                return new a(this, file);
            }
            throw new rm.t();
        }

        private final File f() {
            File b10;
            while (true) {
                c cVar = (c) this.f7030r.peek();
                if (cVar == null) {
                    return null;
                }
                b10 = cVar.b();
                if (b10 == null) {
                    this.f7030r.pop();
                } else {
                    if (t.b(b10, cVar.a()) || !b10.isDirectory() || this.f7030r.size() >= g.this.f7029f) {
                        break;
                    }
                    this.f7030r.push(e(b10));
                }
            }
            return b10;
        }

        @Override // sm.b
        protected void a() {
            File f10 = f();
            if (f10 != null) {
                c(f10);
            } else {
                b();
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes3.dex */
    public static abstract class c {

        /* renamed from: a, reason: collision with root package name */
        private final File f7044a;

        public c(File root) {
            t.g(root, "root");
            this.f7044a = root;
        }

        public final File a() {
            return this.f7044a;
        }

        public abstract File b();
    }

    private g(File file, h hVar, dn.l lVar, dn.l lVar2, p pVar, int i10) {
        this.f7024a = file;
        this.f7025b = hVar;
        this.f7026c = lVar;
        this.f7027d = lVar2;
        this.f7028e = pVar;
        this.f7029f = i10;
    }

    @Override // rp.h
    public Iterator iterator() {
        return new b();
    }

    /* synthetic */ g(File file, h hVar, dn.l lVar, dn.l lVar2, p pVar, int i10, int i11, kotlin.jvm.internal.k kVar) {
        this(file, (i11 & 2) != 0 ? h.TOP_DOWN : hVar, lVar, lVar2, pVar, (i11 & 32) != 0 ? Api.BaseClientBuilder.API_PRIORITY_OTHER : i10);
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public g(File start, h direction) {
        this(start, direction, null, null, null, 0, 32, null);
        t.g(start, "start");
        t.g(direction, "direction");
    }
}
