package f3;

import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.firebase.crashlytics.internal.common.IdManager;
import f3.d;
import f3.i;
import java.util.ArrayList;

/* loaded from: classes.dex */
public class b implements d.a {

    /* renamed from: e, reason: collision with root package name */
    public a f17565e;

    /* renamed from: a, reason: collision with root package name */
    i f17561a = null;

    /* renamed from: b, reason: collision with root package name */
    float f17562b = BitmapDescriptorFactory.HUE_RED;

    /* renamed from: c, reason: collision with root package name */
    boolean f17563c = false;

    /* renamed from: d, reason: collision with root package name */
    ArrayList f17564d = new ArrayList();

    /* renamed from: f, reason: collision with root package name */
    boolean f17566f = false;

    /* loaded from: classes.dex */
    public interface a {
        int a();

        i b(int i10);

        boolean c(i iVar);

        void clear();

        void d();

        float e(int i10);

        void f(i iVar, float f10, boolean z10);

        float g(b bVar, boolean z10);

        void h(i iVar, float f10);

        float i(i iVar, boolean z10);

        float j(i iVar);

        void k(float f10);
    }

    public b() {
    }

    private boolean u(i iVar, d dVar) {
        return iVar.B <= 1;
    }

    private i w(boolean[] zArr, i iVar) {
        i.a aVar;
        int a10 = this.f17565e.a();
        i iVar2 = null;
        float f10 = 0.0f;
        for (int i10 = 0; i10 < a10; i10++) {
            float e10 = this.f17565e.e(i10);
            if (e10 < BitmapDescriptorFactory.HUE_RED) {
                i b10 = this.f17565e.b(i10);
                if ((zArr == null || !zArr[b10.f17611r]) && b10 != iVar && (((aVar = b10.f17618y) == i.a.SLACK || aVar == i.a.ERROR) && e10 < f10)) {
                    f10 = e10;
                    iVar2 = b10;
                }
            }
        }
        return iVar2;
    }

    public void A(d dVar, i iVar, boolean z10) {
        if (iVar == null || !iVar.f17615v) {
            return;
        }
        this.f17562b += iVar.f17614u * this.f17565e.j(iVar);
        this.f17565e.i(iVar, z10);
        if (z10) {
            iVar.m(this);
        }
        if (d.f17573t && this.f17565e.a() == 0) {
            this.f17566f = true;
            dVar.f17579a = true;
        }
    }

    public void B(d dVar, b bVar, boolean z10) {
        this.f17562b += bVar.f17562b * this.f17565e.g(bVar, z10);
        if (z10) {
            bVar.f17561a.m(this);
        }
        if (d.f17573t && this.f17561a != null && this.f17565e.a() == 0) {
            this.f17566f = true;
            dVar.f17579a = true;
        }
    }

    public void C(d dVar, i iVar, boolean z10) {
        if (iVar == null || !iVar.C) {
            return;
        }
        float j10 = this.f17565e.j(iVar);
        this.f17562b += iVar.E * j10;
        this.f17565e.i(iVar, z10);
        if (z10) {
            iVar.m(this);
        }
        this.f17565e.f(dVar.f17592n.f17570d[iVar.D], j10, z10);
        if (d.f17573t && this.f17565e.a() == 0) {
            this.f17566f = true;
            dVar.f17579a = true;
        }
    }

    public void D(d dVar) {
        if (dVar.f17585g.length == 0) {
            return;
        }
        boolean z10 = false;
        while (!z10) {
            int a10 = this.f17565e.a();
            for (int i10 = 0; i10 < a10; i10++) {
                i b10 = this.f17565e.b(i10);
                if (b10.f17612s != -1 || b10.f17615v || b10.C) {
                    this.f17564d.add(b10);
                }
            }
            int size = this.f17564d.size();
            if (size > 0) {
                for (int i11 = 0; i11 < size; i11++) {
                    i iVar = (i) this.f17564d.get(i11);
                    if (iVar.f17615v) {
                        A(dVar, iVar, true);
                    } else if (iVar.C) {
                        C(dVar, iVar, true);
                    } else {
                        B(dVar, dVar.f17585g[iVar.f17612s], true);
                    }
                }
                this.f17564d.clear();
            } else {
                z10 = true;
            }
        }
        if (d.f17573t && this.f17561a != null && this.f17565e.a() == 0) {
            this.f17566f = true;
            dVar.f17579a = true;
        }
    }

    @Override // f3.d.a
    public void a(d.a aVar) {
        if (aVar instanceof b) {
            b bVar = (b) aVar;
            this.f17561a = null;
            this.f17565e.clear();
            for (int i10 = 0; i10 < bVar.f17565e.a(); i10++) {
                this.f17565e.f(bVar.f17565e.b(i10), bVar.f17565e.e(i10), true);
            }
        }
    }

    @Override // f3.d.a
    public void b(i iVar) {
        int i10 = iVar.f17613t;
        float f10 = 1.0f;
        if (i10 != 1) {
            if (i10 == 2) {
                f10 = 1000.0f;
            } else if (i10 == 3) {
                f10 = 1000000.0f;
            } else if (i10 == 4) {
                f10 = 1.0E9f;
            } else if (i10 == 5) {
                f10 = 1.0E12f;
            }
        }
        this.f17565e.h(iVar, f10);
    }

    @Override // f3.d.a
    public i c(d dVar, boolean[] zArr) {
        return w(zArr, null);
    }

    @Override // f3.d.a
    public void clear() {
        this.f17565e.clear();
        this.f17561a = null;
        this.f17562b = BitmapDescriptorFactory.HUE_RED;
    }

    public b d(d dVar, int i10) {
        this.f17565e.h(dVar.o(i10, "ep"), 1.0f);
        this.f17565e.h(dVar.o(i10, "em"), -1.0f);
        return this;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public b e(i iVar, int i10) {
        this.f17565e.h(iVar, i10);
        return this;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean f(d dVar) {
        boolean z10;
        i g10 = g(dVar);
        if (g10 == null) {
            z10 = true;
        } else {
            x(g10);
            z10 = false;
        }
        if (this.f17565e.a() == 0) {
            this.f17566f = true;
        }
        return z10;
    }

    i g(d dVar) {
        boolean u10;
        boolean u11;
        int a10 = this.f17565e.a();
        i iVar = null;
        float f10 = 0.0f;
        float f11 = 0.0f;
        boolean z10 = false;
        boolean z11 = false;
        i iVar2 = null;
        for (int i10 = 0; i10 < a10; i10++) {
            float e10 = this.f17565e.e(i10);
            i b10 = this.f17565e.b(i10);
            if (b10.f17618y == i.a.UNRESTRICTED) {
                if (iVar == null) {
                    u11 = u(b10, dVar);
                } else if (f10 > e10) {
                    u11 = u(b10, dVar);
                } else if (!z10 && u(b10, dVar)) {
                    f10 = e10;
                    iVar = b10;
                    z10 = true;
                }
                z10 = u11;
                f10 = e10;
                iVar = b10;
            } else if (iVar == null && e10 < BitmapDescriptorFactory.HUE_RED) {
                if (iVar2 == null) {
                    u10 = u(b10, dVar);
                } else if (f11 > e10) {
                    u10 = u(b10, dVar);
                } else if (!z11 && u(b10, dVar)) {
                    f11 = e10;
                    iVar2 = b10;
                    z11 = true;
                }
                z11 = u10;
                f11 = e10;
                iVar2 = b10;
            }
        }
        return iVar != null ? iVar : iVar2;
    }

    @Override // f3.d.a
    public i getKey() {
        return this.f17561a;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public b h(i iVar, i iVar2, int i10, float f10, i iVar3, i iVar4, int i11) {
        if (iVar2 == iVar3) {
            this.f17565e.h(iVar, 1.0f);
            this.f17565e.h(iVar4, 1.0f);
            this.f17565e.h(iVar2, -2.0f);
            return this;
        }
        if (f10 == 0.5f) {
            this.f17565e.h(iVar, 1.0f);
            this.f17565e.h(iVar2, -1.0f);
            this.f17565e.h(iVar3, -1.0f);
            this.f17565e.h(iVar4, 1.0f);
            if (i10 > 0 || i11 > 0) {
                this.f17562b = (-i10) + i11;
            }
        } else if (f10 <= BitmapDescriptorFactory.HUE_RED) {
            this.f17565e.h(iVar, -1.0f);
            this.f17565e.h(iVar2, 1.0f);
            this.f17562b = i10;
        } else if (f10 >= 1.0f) {
            this.f17565e.h(iVar4, -1.0f);
            this.f17565e.h(iVar3, 1.0f);
            this.f17562b = -i11;
        } else {
            float f11 = 1.0f - f10;
            this.f17565e.h(iVar, f11 * 1.0f);
            this.f17565e.h(iVar2, f11 * (-1.0f));
            this.f17565e.h(iVar3, (-1.0f) * f10);
            this.f17565e.h(iVar4, 1.0f * f10);
            if (i10 > 0 || i11 > 0) {
                this.f17562b = ((-i10) * f11) + (i11 * f10);
            }
        }
        return this;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public b i(i iVar, int i10) {
        this.f17561a = iVar;
        float f10 = i10;
        iVar.f17614u = f10;
        this.f17562b = f10;
        this.f17566f = true;
        return this;
    }

    @Override // f3.d.a
    public boolean isEmpty() {
        return this.f17561a == null && this.f17562b == BitmapDescriptorFactory.HUE_RED && this.f17565e.a() == 0;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public b j(i iVar, i iVar2, float f10) {
        this.f17565e.h(iVar, -1.0f);
        this.f17565e.h(iVar2, f10);
        return this;
    }

    public b k(i iVar, i iVar2, i iVar3, i iVar4, float f10) {
        this.f17565e.h(iVar, -1.0f);
        this.f17565e.h(iVar2, 1.0f);
        this.f17565e.h(iVar3, f10);
        this.f17565e.h(iVar4, -f10);
        return this;
    }

    public b l(float f10, float f11, float f12, i iVar, i iVar2, i iVar3, i iVar4) {
        this.f17562b = BitmapDescriptorFactory.HUE_RED;
        if (f11 == BitmapDescriptorFactory.HUE_RED || f10 == f12) {
            this.f17565e.h(iVar, 1.0f);
            this.f17565e.h(iVar2, -1.0f);
            this.f17565e.h(iVar4, 1.0f);
            this.f17565e.h(iVar3, -1.0f);
        } else if (f10 == BitmapDescriptorFactory.HUE_RED) {
            this.f17565e.h(iVar, 1.0f);
            this.f17565e.h(iVar2, -1.0f);
        } else if (f12 == BitmapDescriptorFactory.HUE_RED) {
            this.f17565e.h(iVar3, 1.0f);
            this.f17565e.h(iVar4, -1.0f);
        } else {
            float f13 = (f10 / f11) / (f12 / f11);
            this.f17565e.h(iVar, 1.0f);
            this.f17565e.h(iVar2, -1.0f);
            this.f17565e.h(iVar4, f13);
            this.f17565e.h(iVar3, -f13);
        }
        return this;
    }

    public b m(i iVar, int i10) {
        if (i10 < 0) {
            this.f17562b = i10 * (-1);
            this.f17565e.h(iVar, 1.0f);
        } else {
            this.f17562b = i10;
            this.f17565e.h(iVar, -1.0f);
        }
        return this;
    }

    public b n(i iVar, i iVar2, int i10) {
        boolean z10 = false;
        if (i10 != 0) {
            if (i10 < 0) {
                i10 *= -1;
                z10 = true;
            }
            this.f17562b = i10;
        }
        if (z10) {
            this.f17565e.h(iVar, 1.0f);
            this.f17565e.h(iVar2, -1.0f);
        } else {
            this.f17565e.h(iVar, -1.0f);
            this.f17565e.h(iVar2, 1.0f);
        }
        return this;
    }

    public b o(i iVar, i iVar2, i iVar3, int i10) {
        boolean z10 = false;
        if (i10 != 0) {
            if (i10 < 0) {
                i10 *= -1;
                z10 = true;
            }
            this.f17562b = i10;
        }
        if (z10) {
            this.f17565e.h(iVar, 1.0f);
            this.f17565e.h(iVar2, -1.0f);
            this.f17565e.h(iVar3, -1.0f);
        } else {
            this.f17565e.h(iVar, -1.0f);
            this.f17565e.h(iVar2, 1.0f);
            this.f17565e.h(iVar3, 1.0f);
        }
        return this;
    }

    public b p(i iVar, i iVar2, i iVar3, int i10) {
        boolean z10 = false;
        if (i10 != 0) {
            if (i10 < 0) {
                i10 *= -1;
                z10 = true;
            }
            this.f17562b = i10;
        }
        if (z10) {
            this.f17565e.h(iVar, 1.0f);
            this.f17565e.h(iVar2, -1.0f);
            this.f17565e.h(iVar3, 1.0f);
        } else {
            this.f17565e.h(iVar, -1.0f);
            this.f17565e.h(iVar2, 1.0f);
            this.f17565e.h(iVar3, -1.0f);
        }
        return this;
    }

    public b q(i iVar, i iVar2, i iVar3, i iVar4, float f10) {
        this.f17565e.h(iVar3, 0.5f);
        this.f17565e.h(iVar4, 0.5f);
        this.f17565e.h(iVar, -0.5f);
        this.f17565e.h(iVar2, -0.5f);
        this.f17562b = -f10;
        return this;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void r() {
        float f10 = this.f17562b;
        if (f10 < BitmapDescriptorFactory.HUE_RED) {
            this.f17562b = f10 * (-1.0f);
            this.f17565e.d();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean s() {
        i iVar = this.f17561a;
        return iVar != null && (iVar.f17618y == i.a.UNRESTRICTED || this.f17562b >= BitmapDescriptorFactory.HUE_RED);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public boolean t(i iVar) {
        return this.f17565e.c(iVar);
    }

    public String toString() {
        return z();
    }

    public i v(i iVar) {
        return w(null, iVar);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void x(i iVar) {
        i iVar2 = this.f17561a;
        if (iVar2 != null) {
            this.f17565e.h(iVar2, -1.0f);
            this.f17561a.f17612s = -1;
            this.f17561a = null;
        }
        float i10 = this.f17565e.i(iVar, true) * (-1.0f);
        this.f17561a = iVar;
        if (i10 == 1.0f) {
            return;
        }
        this.f17562b /= i10;
        this.f17565e.k(i10);
    }

    public void y() {
        this.f17561a = null;
        this.f17565e.clear();
        this.f17562b = BitmapDescriptorFactory.HUE_RED;
        this.f17566f = false;
    }

    /* JADX WARN: Removed duplicated region for block: B:21:0x00bf  */
    /* JADX WARN: Removed duplicated region for block: B:25:0x00cf  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    String z() {
        boolean z10;
        String str = (this.f17561a == null ? "0" : "" + this.f17561a) + " = ";
        if (this.f17562b != BitmapDescriptorFactory.HUE_RED) {
            str = str + this.f17562b;
            z10 = true;
        } else {
            z10 = false;
        }
        int a10 = this.f17565e.a();
        for (int i10 = 0; i10 < a10; i10++) {
            i b10 = this.f17565e.b(i10);
            if (b10 != null) {
                float e10 = this.f17565e.e(i10);
                if (e10 != BitmapDescriptorFactory.HUE_RED) {
                    String iVar = b10.toString();
                    if (!z10) {
                        if (e10 < BitmapDescriptorFactory.HUE_RED) {
                            str = str + "- ";
                            e10 *= -1.0f;
                        }
                        str = e10 == 1.0f ? str + iVar : str + e10 + " " + iVar;
                        z10 = true;
                    } else if (e10 > BitmapDescriptorFactory.HUE_RED) {
                        str = str + " + ";
                        if (e10 == 1.0f) {
                        }
                        z10 = true;
                    } else {
                        str = str + " - ";
                        e10 *= -1.0f;
                        if (e10 == 1.0f) {
                        }
                        z10 = true;
                    }
                }
            }
        }
        if (z10) {
            return str;
        }
        return str + IdManager.DEFAULT_VERSION_NAME;
    }

    public b(c cVar) {
        this.f17565e = new f3.a(this, cVar);
    }
}
