package E;

import F.C0154h;
import java.util.ArrayList;
import java.util.List;
import x4.AbstractC3252r;

/* JADX INFO: loaded from: classes.dex */
public final class y {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ArrayList f1102b;

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

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final ArrayList f1107g;

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

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

    public y(j jVar) {
        this.f1101a = jVar;
        ArrayList arrayList = new ArrayList();
        arrayList.add(new w(0, 0));
        this.f1102b = arrayList;
        this.f1106f = -1;
        this.f1107g = new ArrayList();
        this.f1108h = x4.y.f26065a;
    }

    public final int a() {
        return ((int) Math.sqrt((((double) d()) * 1.0d) / ((double) this.f1109i))) + 1;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:33:0x00a0  */
    /* JADX WARN: Type inference failed for: r0v26 */
    /* JADX WARN: Type inference failed for: r0v27, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r0v31 */
    /* JADX WARN: Type inference failed for: r4v15, types: [java.lang.Object, java.util.List] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final C1.k b(int i6) {
        int i7;
        boolean z6;
        int i8;
        int i9;
        ?? r02;
        if (!this.f1101a.f1016d) {
            int i10 = this.f1109i;
            int i11 = i6 * i10;
            int iD = d() - i11;
            if (i10 > iD) {
                i10 = iD;
            }
            if (i10 < 0) {
                i10 = 0;
            }
            if (i10 == this.f1108h.size()) {
                r02 = this.f1108h;
            } else {
                ArrayList arrayList = new ArrayList(i10);
                for (int i12 = 0; i12 < i10; i12++) {
                    arrayList.add(new C0143d(e4.C.a(1)));
                }
                this.f1108h = arrayList;
                r02 = arrayList;
            }
            return new C1.k(i11, (List) r02);
        }
        int iA = i6 / a();
        ArrayList arrayList2 = this.f1102b;
        int iMin = Math.min(iA, arrayList2.size() - 1);
        int iA2 = a() * iMin;
        int iIntValue = ((w) arrayList2.get(iMin)).f1097a;
        int iE = ((w) arrayList2.get(iMin)).f1098b;
        int i13 = this.f1103c;
        ArrayList arrayList3 = this.f1107g;
        if (iA2 <= i13 && i13 <= i6) {
            iIntValue = this.f1104d;
            iE = this.f1105e;
            iA2 = i13;
        } else if (iMin == this.f1106f && (i7 = i6 - iA2) < arrayList3.size()) {
            iIntValue = ((Number) arrayList3.get(i7)).intValue();
            iA2 = i6;
            iE = 0;
        }
        if (iA2 % a() == 0) {
            int i14 = i6 - iA2;
            z6 = 2 <= i14 && i14 < a();
        }
        if (z6) {
            this.f1106f = iMin;
            arrayList3.clear();
        }
        if (iA2 > i6) {
            A.b.c("currentLine (" + iA2 + ") > lineIndex (" + i6 + ')');
        }
        while (iA2 < i6 && iIntValue < d()) {
            if (z6) {
                arrayList3.add(Integer.valueOf(iIntValue));
            }
            int i15 = 0;
            while (i15 < this.f1109i && iIntValue < d()) {
                if (iE == 0) {
                    i9 = iE;
                    iE = e(iIntValue);
                } else {
                    i9 = 0;
                }
                i15 += iE;
                if (i15 > this.f1109i) {
                    break;
                }
                iIntValue++;
                iE = i9;
            }
            iA2++;
            if (iA2 % a() == 0 && iIntValue < d()) {
                if (arrayList2.size() != iA2 / a()) {
                    A.b.c("invalid starting point");
                }
                arrayList2.add(new w(iIntValue, iE));
            }
        }
        this.f1103c = i6;
        this.f1104d = iIntValue;
        this.f1105e = iE;
        ArrayList arrayList4 = new ArrayList();
        int i16 = 0;
        int i17 = iIntValue;
        while (i16 < this.f1109i && i17 < d()) {
            if (iE == 0) {
                int i18 = iE;
                iE = e(i17);
                i8 = i18;
            } else {
                i8 = 0;
            }
            i16 += iE;
            if (i16 > this.f1109i) {
                break;
            }
            i17++;
            arrayList4.add(new C0143d(e4.C.a(iE)));
            iE = i8;
        }
        return new C1.k(iIntValue, arrayList4);
    }

    public final int c(int i6) {
        int i7;
        if (d() <= 0) {
            return 0;
        }
        if (i6 >= d()) {
            A.b.a("ItemIndex > total count");
        }
        if (!this.f1101a.f1016d) {
            return i6 / this.f1109i;
        }
        ArrayList arrayList = this.f1102b;
        int size = arrayList.size();
        AbstractC3252r.E(arrayList.size(), size);
        int i8 = size - 1;
        int i9 = 0;
        while (true) {
            if (i9 > i8) {
                i7 = -(i9 + 1);
                break;
            }
            i7 = (i9 + i8) >>> 1;
            int i10 = ((w) arrayList.get(i7)).f1097a - i6;
            if (i10 >= 0) {
                if (i10 <= 0) {
                    break;
                }
                i8 = i7 - 1;
            } else {
                i9 = i7 + 1;
            }
        }
        if (i7 < 0) {
            i7 = (-i7) - 2;
        }
        int iA = a() * i7;
        int i11 = ((w) arrayList.get(i7)).f1097a;
        if (i11 > i6) {
            A.b.a("currentItemIndex > itemIndex");
        }
        int i12 = 0;
        while (i11 < i6) {
            int i13 = i11 + 1;
            int iE = e(i11);
            i12 += iE;
            int i14 = this.f1109i;
            if (i12 >= i14) {
                if (i12 == i14) {
                    iA++;
                    i12 = 0;
                } else {
                    iA++;
                    i12 = iE;
                }
            }
            if (iA % a() == 0 && iA / a() >= arrayList.size()) {
                arrayList.add(new w(i13 - (i12 > 0 ? 1 : 0), 0));
            }
            i11 = i13;
        }
        return e(i6) + i12 > this.f1109i ? iA + 1 : iA;
    }

    public final int d() {
        return this.f1101a.f1015c.f1279b;
    }

    public final int e(int i6) {
        x xVar = x.f1099a;
        x.f1100b = this.f1109i;
        C0154h c0154hC = this.f1101a.f1015c.c(i6);
        return (int) ((C0143d) ((h) c0154hC.f1287c).f1008b.invoke(xVar, Integer.valueOf(i6 - c0154hC.f1285a))).f989a;
    }
}
