package o;

import java.util.ArrayList;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.Gk, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C0166Gk {
    public final C0321Mk a;
    public C0603Xg b;
    public boolean c;
    public int f;
    public int g;
    public int l;
    public final C1564jI d = new C1564jI();
    public boolean e = true;
    public final ArrayList h = new ArrayList();
    public int i = -1;
    public int j = -1;
    public int k = -1;

    public C0166Gk(C0321Mk c0321Mk, C0603Xg c0603Xg) {
        this.a = c0321Mk;
        this.b = c0603Xg;
    }

    public final void a() {
        c();
        ArrayList arrayList = this.h;
        if (arrayList.isEmpty()) {
            this.g++;
        } else {
            arrayList.remove(arrayList.size() - 1);
        }
    }

    public final void b() {
        int i = this.g;
        if (i > 0) {
            JU ju = this.b.g;
            ju.U(FU.c);
            ju.i[ju.j - ju.g[ju.h - 1].a] = i;
            this.g = 0;
        }
        ArrayList arrayList = this.h;
        if (arrayList.isEmpty()) {
            return;
        }
        C0603Xg c0603Xg = this.b;
        int size = arrayList.size();
        Object[] objArr = new Object[size];
        for (int i2 = 0; i2 < size; i2++) {
            objArr[i2] = arrayList.get(i2);
        }
        c0603Xg.getClass();
        if (size != 0) {
            JU ju2 = c0603Xg.g;
            ju2.U(C1290gU.c);
            As0.R(ju2, 0, objArr);
        }
        arrayList.clear();
    }

    public final void c() {
        int i = this.l;
        if (i > 0) {
            int i2 = this.i;
            if (i2 >= 0) {
                b();
                JU ju = this.b.g;
                ju.U(C2620uU.c);
                int i3 = ju.j - ju.g[ju.h - 1].a;
                int[] iArr = ju.i;
                iArr[i3] = i2;
                iArr[i3 + 1] = i;
                this.i = -1;
            } else {
                int i4 = this.k;
                int i5 = this.j;
                b();
                JU ju2 = this.b.g;
                ju2.U(C2335rU.c);
                int i6 = ju2.j - ju2.g[ju2.h - 1].a;
                int[] iArr2 = ju2.i;
                iArr2[i6 + 1] = i4;
                iArr2[i6] = i5;
                iArr2[i6 + 2] = i;
                this.j = -1;
                this.k = -1;
            }
            this.l = 0;
        }
    }

    public final void d(boolean z) {
        C0321Mk c0321Mk = this.a;
        int i = z ? c0321Mk.F.i : c0321Mk.F.g;
        int i2 = i - this.f;
        if (i2 < 0) {
            AbstractC0373Ok.c("Tried to seek backward");
        }
        if (i2 > 0) {
            JU ju = this.b.g;
            ju.U(C0716aU.c);
            ju.i[ju.j - ju.g[ju.h - 1].a] = i2;
            this.f = i;
        }
    }

    public final void e(int i, int i2) {
        if (i2 > 0) {
            if (!(i >= 0)) {
                AbstractC0373Ok.c("Invalid remove index " + i);
            }
            if (this.i == i) {
                this.l += i2;
                return;
            }
            c();
            this.i = i;
            this.l = i2;
        }
    }
}
