package z0;

import dn.l;
import java.util.List;
import kotlin.jvm.internal.k;
import y0.a3;
import y0.k1;
import y0.l1;
import y0.n;
import y0.p;
import y0.q;
import y0.r;
import y0.s2;
import y0.v0;
import y0.x3;
import y0.z2;

/* loaded from: classes.dex */
public final class b {

    /* renamed from: m, reason: collision with root package name */
    public static final a f53080m = new a(null);

    /* renamed from: n, reason: collision with root package name */
    public static final int f53081n = 8;

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

    /* renamed from: b, reason: collision with root package name */
    private z0.a f53083b;

    /* renamed from: c, reason: collision with root package name */
    private boolean f53084c;

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

    /* renamed from: g, reason: collision with root package name */
    private int f53088g;

    /* renamed from: l, reason: collision with root package name */
    private int f53093l;

    /* renamed from: d, reason: collision with root package name */
    private final v0 f53085d = new v0();

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

    /* renamed from: h, reason: collision with root package name */
    private x3 f53089h = new x3();

    /* renamed from: i, reason: collision with root package name */
    private int f53090i = -1;

    /* renamed from: j, reason: collision with root package name */
    private int f53091j = -1;

    /* renamed from: k, reason: collision with root package name */
    private int f53092k = -1;

    /* loaded from: classes.dex */
    public static final class a {
        private a() {
        }

        public /* synthetic */ a(k kVar) {
            this();
        }
    }

    public b(n nVar, z0.a aVar) {
        this.f53082a = nVar;
        this.f53083b = aVar;
    }

    private final void A() {
        B();
    }

    private final void B() {
        int i10 = this.f53088g;
        if (i10 > 0) {
            this.f53083b.G(i10);
            this.f53088g = 0;
        }
        if (this.f53089h.d()) {
            this.f53083b.k(this.f53089h.i());
            this.f53089h.a();
        }
    }

    private final void C() {
        I(this, false, 1, null);
        K();
    }

    private final void D(boolean z10) {
        H(z10);
    }

    static /* synthetic */ void E(b bVar, boolean z10, int i10, Object obj) {
        if ((i10 & 1) != 0) {
            z10 = false;
        }
        bVar.D(z10);
    }

    private final void F(int i10, int i11, int i12) {
        A();
        this.f53083b.u(i10, i11, i12);
    }

    private final void G() {
        int i10 = this.f53093l;
        if (i10 > 0) {
            int i11 = this.f53090i;
            if (i11 >= 0) {
                J(i11, i10);
                this.f53090i = -1;
            } else {
                F(this.f53092k, this.f53091j, i10);
                this.f53091j = -1;
                this.f53092k = -1;
            }
            this.f53093l = 0;
        }
    }

    private final void H(boolean z10) {
        int u10 = z10 ? q().u() : q().k();
        int i10 = u10 - this.f53087f;
        if (!(i10 >= 0)) {
            p.r("Tried to seek backward");
        }
        if (i10 > 0) {
            this.f53083b.e(i10);
            this.f53087f = u10;
        }
    }

    static /* synthetic */ void I(b bVar, boolean z10, int i10, Object obj) {
        if ((i10 & 1) != 0) {
            z10 = false;
        }
        bVar.H(z10);
    }

    private final void J(int i10, int i11) {
        A();
        this.f53083b.x(i10, i11);
    }

    private final void k(y0.d dVar) {
        E(this, false, 1, null);
        this.f53083b.o(dVar);
        this.f53084c = true;
    }

    private final void l() {
        if (this.f53084c || !this.f53086e) {
            return;
        }
        E(this, false, 1, null);
        this.f53083b.p();
        this.f53084c = true;
    }

    private final z2 q() {
        return this.f53082a.G0();
    }

    public final void K() {
        z2 q10;
        int u10;
        if (q().x() <= 0 || this.f53085d.h(-2) == (u10 = (q10 = q()).u())) {
            return;
        }
        l();
        if (u10 > 0) {
            y0.d a10 = q10.a(u10);
            this.f53085d.j(u10);
            k(a10);
        }
    }

    public final void L() {
        B();
        if (this.f53084c) {
            U();
            j();
        }
    }

    public final void M(s2 s2Var) {
        this.f53083b.v(s2Var);
    }

    public final void N() {
        C();
        this.f53083b.w();
        this.f53087f += q().p();
    }

    public final void O(int i10, int i11) {
        if (i11 > 0) {
            if (!(i10 >= 0)) {
                p.r("Invalid remove index " + i10);
            }
            if (this.f53090i == i10) {
                this.f53093l += i11;
                return;
            }
            G();
            this.f53090i = i10;
            this.f53093l = i11;
        }
    }

    public final void P() {
        this.f53083b.y();
    }

    public final void Q() {
        this.f53084c = false;
        this.f53085d.a();
        this.f53087f = 0;
    }

    public final void R(z0.a aVar) {
        this.f53083b = aVar;
    }

    public final void S(boolean z10) {
        this.f53086e = z10;
    }

    public final void T(dn.a aVar) {
        this.f53083b.z(aVar);
    }

    public final void U() {
        this.f53083b.A();
    }

    public final void V(int i10) {
        if (i10 > 0) {
            C();
            this.f53083b.B(i10);
        }
    }

    public final void W(Object obj, y0.d dVar, int i10) {
        this.f53083b.C(obj, dVar, i10);
    }

    public final void X(Object obj) {
        E(this, false, 1, null);
        this.f53083b.D(obj);
    }

    public final void Y(Object obj, dn.p pVar) {
        A();
        this.f53083b.E(obj, pVar);
    }

    public final void Z(Object obj, int i10) {
        D(true);
        this.f53083b.F(obj, i10);
    }

    public final void a(y0.d dVar, Object obj) {
        this.f53083b.f(dVar, obj);
    }

    public final void a0(Object obj) {
        A();
        this.f53083b.H(obj);
    }

    public final void b(List list, g1.d dVar) {
        this.f53083b.g(list, dVar);
    }

    public final void c(k1 k1Var, r rVar, l1 l1Var, l1 l1Var2) {
        this.f53083b.h(k1Var, rVar, l1Var, l1Var2);
    }

    public final void d() {
        E(this, false, 1, null);
        this.f53083b.i();
    }

    public final void e(g1.d dVar, y0.d dVar2) {
        B();
        this.f53083b.j(dVar, dVar2);
    }

    public final void f(l lVar, q qVar) {
        this.f53083b.l(lVar, qVar);
    }

    public final void g() {
        int u10 = q().u();
        if (!(this.f53085d.h(-1) <= u10)) {
            p.r("Missed recording an endGroup");
        }
        if (this.f53085d.h(-1) == u10) {
            E(this, false, 1, null);
            this.f53085d.i();
            this.f53083b.m();
        }
    }

    public final void h() {
        this.f53083b.n();
        this.f53087f = 0;
    }

    public final void i() {
        G();
    }

    public final void j() {
        if (this.f53084c) {
            E(this, false, 1, null);
            E(this, false, 1, null);
            this.f53083b.m();
            this.f53084c = false;
        }
    }

    public final void m() {
        B();
        if (this.f53085d.d()) {
            return;
        }
        p.r("Missed recording an endGroup()");
    }

    public final z0.a n() {
        return this.f53083b;
    }

    public final boolean o() {
        return this.f53086e;
    }

    public final boolean p() {
        return q().u() - this.f53087f < 0;
    }

    public final void r(z0.a aVar, g1.d dVar) {
        this.f53083b.q(aVar, dVar);
    }

    public final void s(y0.d dVar, a3 a3Var) {
        B();
        C();
        G();
        this.f53083b.r(dVar, a3Var);
    }

    public final void t(y0.d dVar, a3 a3Var, c cVar) {
        B();
        C();
        G();
        this.f53083b.s(dVar, a3Var, cVar);
    }

    public final void u(int i10) {
        C();
        this.f53083b.t(i10);
    }

    public final void v(Object obj) {
        G();
        this.f53089h.h(obj);
    }

    public final void w(int i10, int i11, int i12) {
        if (i12 > 0) {
            int i13 = this.f53093l;
            if (i13 > 0 && this.f53091j == i10 - i13 && this.f53092k == i11 - i13) {
                this.f53093l = i13 + i12;
                return;
            }
            G();
            this.f53091j = i10;
            this.f53092k = i11;
            this.f53093l = i12;
        }
    }

    public final void x(int i10) {
        this.f53087f += i10 - q().k();
    }

    public final void y(int i10) {
        this.f53087f = i10;
    }

    public final void z() {
        G();
        if (this.f53089h.d()) {
            this.f53089h.g();
        } else {
            this.f53088g++;
        }
    }
}
