package o;

import android.graphics.Matrix;
import android.graphics.Shader;
import android.text.Layout;
import android.text.TextUtils;
import java.util.ArrayList;
import java.util.List;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.rQ, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C2331rQ {
    public final Q1 a;
    public final int b;
    public final boolean c;
    public final float d;
    public final float e;
    public final int f;
    public final ArrayList g;
    public final ArrayList h;

    /* JADX WARN: Type inference failed for: r7v1, types: [java.lang.Object, java.util.Collection, java.util.List] */
    public C2331rQ(Q1 q1, long j, int i, int i2) {
        boolean z;
        int i3;
        int iG;
        int i4;
        this.a = q1;
        this.b = i;
        if (C0634Yl.j(j) != 0 || C0634Yl.i(j) != 0) {
            AbstractC2228qH.a("Setting Constraints.minWidth and Constraints.minHeight is not supported, these should be the default zero values instead.");
        }
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = (ArrayList) q1.m;
        int size = arrayList2.size();
        float f = 0.0f;
        int i5 = 0;
        int i6 = 0;
        while (i5 < size) {
            CV cv = (CV) arrayList2.get(i5);
            N4 n4 = cv.a;
            int iH = C0634Yl.h(j);
            if (C0634Yl.c(j)) {
                i3 = i5;
                iG = C0634Yl.g(j) - ((int) Math.ceil(f));
                if (iG < 0) {
                    iG = 0;
                }
            } else {
                i3 = i5;
                iG = C0634Yl.g(j);
            }
            J4 j4 = new J4(n4, this.b - i6, i2, AbstractC0842bm.b(iH, iG, 5));
            float fB = j4.b() + f;
            Le0 le0 = j4.d;
            int i7 = i6 + le0.g;
            arrayList.add(new BV(j4, cv.b, cv.c, i6, i7, f, fB));
            if (!le0.d) {
                if (i7 == this.b) {
                    i4 = i3;
                    if (i4 != AbstractC0008Ai.R((ArrayList) this.a.m)) {
                    }
                } else {
                    i4 = i3;
                }
                i5 = i4 + 1;
                i6 = i7;
                f = fB;
            }
            z = true;
            i6 = i7;
            f = fB;
            break;
        }
        z = false;
        this.e = f;
        this.f = i6;
        this.c = z;
        this.h = arrayList;
        this.d = C0634Yl.h(j);
        ArrayList arrayList3 = new ArrayList(arrayList.size());
        int size2 = arrayList.size();
        for (int i8 = 0; i8 < size2; i8++) {
            BV bv = (BV) arrayList.get(i8);
            ?? r7 = bv.a.f;
            ArrayList arrayList4 = new ArrayList(r7.size());
            int size3 = r7.size();
            for (int i9 = 0; i9 < size3; i9++) {
                T00 t00 = (T00) r7.get(i9);
                arrayList4.add(t00 != null ? bv.a(t00) : null);
            }
            AbstractC0138Fi.Y(arrayList4, arrayList3);
        }
        if (arrayList3.size() < ((List) this.a.n).size()) {
            int size4 = ((List) this.a.n).size() - arrayList3.size();
            ArrayList arrayList5 = new ArrayList(size4);
            for (int i10 = 0; i10 < size4; i10++) {
                arrayList5.add(null);
            }
            arrayList3 = AbstractC3117zi.l0(arrayList3, arrayList5);
        }
        this.g = arrayList3;
    }

    public static void i(C2331rQ c2331rQ, InterfaceC2923xg interfaceC2923xg, AbstractC0601Xe abstractC0601Xe, float f, I70 i70, C2823wd0 c2823wd0, AbstractC2190pt abstractC2190pt) {
        interfaceC2923xg.n();
        ArrayList arrayList = c2331rQ.h;
        if (arrayList.size() <= 1 || (abstractC0601Xe instanceof Q90)) {
            AbstractC2539te.y(c2331rQ, interfaceC2923xg, abstractC0601Xe, f, i70, c2823wd0, abstractC2190pt);
        } else {
            if (!(abstractC0601Xe instanceof G70)) {
                throw new C2170pj();
            }
            int size = arrayList.size();
            float fMax = 0.0f;
            float fB = 0.0f;
            for (int i = 0; i < size; i++) {
                BV bv = (BV) arrayList.get(i);
                fB += bv.a.b();
                fMax = Math.max(fMax, bv.a.d());
            }
            Shader shaderB = ((G70) abstractC0601Xe).b((Float.floatToRawIntBits(fMax) << 32) | (Float.floatToRawIntBits(fB) & 4294967295L));
            Matrix matrix = new Matrix();
            shaderB.getLocalMatrix(matrix);
            int size2 = arrayList.size();
            for (int i2 = 0; i2 < size2; i2++) {
                J4 j4 = ((BV) arrayList.get(i2)).a;
                j4.g(interfaceC2923xg, new C0627Ye(shaderB), f, i70, c2823wd0, abstractC2190pt);
                interfaceC2923xg.j(0.0f, j4.b());
                matrix.setTranslate(0.0f, -j4.b());
                shaderB.setLocalMatrix(matrix);
            }
        }
        interfaceC2923xg.k();
    }

    public final void a(long j, float[] fArr) {
        j(Ue0.f(j));
        k(Ue0.e(j));
        C3058z10 c3058z10 = new C3058z10();
        c3058z10.l = 0;
        AbstractC0249Jp.I(this.h, j, new C1685ke(j, fArr, c3058z10, new C2963y10()));
    }

    public final float b(int i) {
        l(i);
        ArrayList arrayList = this.h;
        BV bv = (BV) arrayList.get(AbstractC0249Jp.G(i, arrayList));
        J4 j4 = bv.a;
        return j4.d.e(i - bv.d) + bv.f;
    }

    public final int c(int i, boolean z) {
        int iF;
        l(i);
        ArrayList arrayList = this.h;
        BV bv = (BV) arrayList.get(AbstractC0249Jp.G(i, arrayList));
        J4 j4 = bv.a;
        int i2 = i - bv.d;
        Le0 le0 = j4.d;
        if (z) {
            Layout layout = le0.f;
            C0729ad0 c0729ad0 = Pe0.a;
            if (layout.getEllipsisCount(i2) <= 0 || le0.b != TextUtils.TruncateAt.END) {
                Q1 q1C = le0.c();
                Layout layout2 = (Layout) q1C.f292o;
                iF = q1C.u(layout2.getLineEnd(i2), layout2.getLineStart(i2));
            } else {
                iF = layout.getEllipsisStart(i2) + layout.getLineStart(i2);
            }
        } else {
            iF = le0.f(i2);
        }
        return iF + bv.b;
    }

    public final int d(int i) {
        int length = ((C0977d7) this.a.f292o).m.length();
        ArrayList arrayList = this.h;
        BV bv = (BV) arrayList.get(i >= length ? AbstractC0008Ai.R(arrayList) : i < 0 ? 0 : AbstractC0249Jp.F(i, arrayList));
        return bv.a.d.f.getLineForOffset(bv.d(i)) + bv.d;
    }

    public final int e(float f) {
        ArrayList arrayList = this.h;
        BV bv = (BV) arrayList.get(AbstractC0249Jp.H(arrayList, f));
        int i = bv.c - bv.b;
        int i2 = bv.d;
        if (i == 0) {
            return i2;
        }
        J4 j4 = bv.a;
        float f2 = f - bv.f;
        Le0 le0 = j4.d;
        return le0.f.getLineForVertical(((int) f2) - le0.h) + i2;
    }

    public final float f(int i) {
        l(i);
        ArrayList arrayList = this.h;
        BV bv = (BV) arrayList.get(AbstractC0249Jp.G(i, arrayList));
        J4 j4 = bv.a;
        return j4.d.g(i - bv.d) + bv.f;
    }

    public final int g(long j) {
        int i = (int) (j & 4294967295L);
        float fIntBitsToFloat = Float.intBitsToFloat(i);
        ArrayList arrayList = this.h;
        BV bv = (BV) arrayList.get(AbstractC0249Jp.H(arrayList, fIntBitsToFloat));
        int i2 = bv.c;
        int i3 = bv.b;
        if (i2 - i3 == 0) {
            return i3;
        }
        J4 j4 = bv.a;
        float fIntBitsToFloat2 = Float.intBitsToFloat((int) (j >> 32));
        float fIntBitsToFloat3 = Float.intBitsToFloat(i) - bv.f;
        long jFloatToRawIntBits = (Float.floatToRawIntBits(fIntBitsToFloat3) & 4294967295L) | (Float.floatToRawIntBits(fIntBitsToFloat2) << 32);
        Le0 le0 = j4.d;
        int lineForVertical = le0.f.getLineForVertical(((int) Float.intBitsToFloat((int) (4294967295L & jFloatToRawIntBits))) - le0.h);
        return le0.f.getOffsetForHorizontal(lineForVertical, (le0.b(lineForVertical) * (-1)) + Float.intBitsToFloat((int) (jFloatToRawIntBits >> 32))) + i3;
    }

    public final long h(T00 t00, int i, C0387Oy c0387Oy) {
        long jB;
        long j;
        float f = t00.b;
        ArrayList arrayList = this.h;
        int iH = AbstractC0249Jp.H(arrayList, f);
        float f2 = ((BV) arrayList.get(iH)).g;
        float f3 = t00.d;
        if (f2 >= f3 || iH == AbstractC0008Ai.R(arrayList)) {
            BV bv = (BV) arrayList.get(iH);
            return bv.b(true, bv.a.c(bv.c(t00), i, c0387Oy));
        }
        int iH2 = AbstractC0249Jp.H(arrayList, f3);
        long jB2 = Ue0.b;
        while (true) {
            jB = Ue0.b;
            if (!Ue0.b(jB2, jB) || iH > iH2) {
                break;
            }
            BV bv2 = (BV) arrayList.get(iH);
            jB2 = bv2.b(true, bv2.a.c(bv2.c(t00), i, c0387Oy));
            iH++;
        }
        if (Ue0.b(jB2, jB)) {
            return jB;
        }
        while (true) {
            j = Ue0.b;
            if (!Ue0.b(jB, j) || iH > iH2) {
                break;
            }
            BV bv3 = (BV) arrayList.get(iH2);
            jB = bv3.b(true, bv3.a.c(bv3.c(t00), i, c0387Oy));
            iH2--;
        }
        return Ue0.b(jB, j) ? jB2 : AbstractC2378rs0.u((int) (jB2 >> 32), (int) (4294967295L & jB));
    }

    public final void j(int i) {
        boolean z = false;
        Q1 q1 = this.a;
        if (i >= 0 && i < ((C0977d7) q1.f292o).m.length()) {
            z = true;
        }
        if (z) {
            return;
        }
        StringBuilder sbO = AbstractC0126Ew.o(i, "offset(", ") is out of bounds [0, ");
        sbO.append(((C0977d7) q1.f292o).m.length());
        sbO.append(')');
        AbstractC2228qH.a(sbO.toString());
    }

    public final void k(int i) {
        boolean z = false;
        Q1 q1 = this.a;
        if (i >= 0 && i <= ((C0977d7) q1.f292o).m.length()) {
            z = true;
        }
        if (z) {
            return;
        }
        StringBuilder sbO = AbstractC0126Ew.o(i, "offset(", ") is out of bounds [0, ");
        sbO.append(((C0977d7) q1.f292o).m.length());
        sbO.append(']');
        AbstractC2228qH.a(sbO.toString());
    }

    public final void l(int i) {
        boolean z = false;
        int i2 = this.f;
        if (i >= 0 && i < i2) {
            z = true;
        }
        if (z) {
            return;
        }
        AbstractC2228qH.a("lineIndex(" + i + ") is out of bounds [0, " + i2 + ')');
    }
}
