package T0;

import B.C0053c;
import a1.AbstractC0958a;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.os.Build;
import android.text.Layout;
import android.text.SegmentFinder;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.TextUtils;
import c1.AbstractC1227b;
import c1.C1226a;
import c1.C1228c;
import c1.C1230e;
import e1.C1962b;
import f1.C2024l;
import f1.EnumC2022j;
import h1.C2069a;
import java.util.ArrayList;
import o0.C2632c;
import p0.AbstractC2686D;
import p0.AbstractC2697c;
import p0.AbstractC2711q;
import p0.InterfaceC2712s;
import p0.W;

/* JADX INFO: renamed from: T0.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0590a {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final long f6492c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final U0.k f6493d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final CharSequence f6494e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final Object f6495f;

    /* JADX WARN: Removed duplicated region for block: B:104:0x014e  */
    /* JADX WARN: Removed duplicated region for block: B:106:0x0159  */
    /* JADX WARN: Removed duplicated region for block: B:114:0x019f  */
    /* JADX WARN: Removed duplicated region for block: B:133:0x01d6  */
    /* JADX WARN: Removed duplicated region for block: B:136:0x0214  */
    /* JADX WARN: Removed duplicated region for block: B:137:0x0217  */
    /* JADX WARN: Removed duplicated region for block: B:141:0x024f  */
    /* JADX WARN: Removed duplicated region for block: B:146:0x0283  */
    /* JADX WARN: Removed duplicated region for block: B:147:0x0287  */
    /* JADX WARN: Removed duplicated region for block: B:158:0x02d9  */
    /* JADX WARN: Removed duplicated region for block: B:74:0x00f4  */
    /* JADX WARN: Removed duplicated region for block: B:86:0x010d  */
    /* JADX WARN: Removed duplicated region for block: B:95:0x0121  */
    /* JADX WARN: Removed duplicated region for block: B:97:0x0131  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public C0590a(C1228c c1228c, int i6, int i7, long j4) {
        int i8;
        int i9;
        CharSequence charSequence;
        O o6;
        int i10;
        O o7;
        int i11;
        int i12;
        int i13;
        int i14;
        int i15;
        int i16;
        int i17;
        char c6;
        int i18;
        TextUtils.TruncateAt truncateAt;
        TextUtils.TruncateAt truncateAt2;
        U0.k kVarA;
        int i19;
        C0590a c0590a;
        int i20;
        U0.k kVar;
        C1962b[] c1962bArr;
        CharSequence charSequence2;
        Object obj;
        boolean z6;
        C2632c c2632c;
        float fH;
        int i21;
        this.f6490a = c1228c;
        this.f6491b = i6;
        this.f6492c = j4;
        if (C2069a.i(j4) != 0 || C2069a.j(j4) != 0) {
            AbstractC0958a.a("Setting Constraints.minWidth and Constraints.minHeight is not supported, these should be the default zero values instead.");
        }
        if (i6 < 1) {
            AbstractC0958a.a("maxLines should be greater than 0");
        }
        boolean z7 = i7 == 2;
        O o8 = c1228c.f13392b;
        CharSequence charSequence3 = c1228c.f13398k;
        if (z7) {
            i8 = 1;
            i9 = 0;
            charSequence = charSequence3;
            if (!h1.o.a(o8.f6485a.f6446h, W.a.l0(0))) {
                charSequence = charSequence3;
                if (!h1.o.a(o8.f6485a.f6446h, h1.o.f16633c)) {
                    int i22 = o8.f6486b.f6557a;
                    charSequence = charSequence3;
                    charSequence = charSequence3;
                    charSequence = charSequence3;
                    if (i22 != 0 && i22 != 5 && i22 != 4) {
                        int length = charSequence3.length();
                        charSequence = charSequence3;
                        if (length != 0) {
                            Spannable spannable = charSequence3 instanceof Spannable ? (Spannable) charSequence3 : null;
                            Spannable spannableString = spannable == null ? new SpannableString(charSequence3) : spannable;
                            boolean zF = U0.h.f(spannableString, W0.c.class);
                            charSequence = spannableString;
                            if (!zF) {
                                spannableString.setSpan(new W0.c(), spannableString.length() - 1, spannableString.length() - 1, 33);
                                charSequence = spannableString;
                            }
                        }
                    }
                }
            }
        } else {
            i8 = 1;
            i9 = 0;
            charSequence = charSequence3;
        }
        CharSequence charSequence4 = charSequence;
        this.f6494e = charSequence4;
        u uVar = o8.f6486b;
        int i23 = uVar.f6557a;
        int i24 = i23 == i8 ? 3 : i23 == 2 ? 4 : i23 == 3 ? 2 : (i23 != 5 && i23 == 6) ? 1 : i9;
        int i25 = i23 == 4 ? 1 : i9;
        if (uVar.f6564h != 2) {
            o6 = o8;
            i10 = i9;
        } else if (Build.VERSION.SDK_INT <= 32) {
            o6 = o8;
            i10 = 2;
        } else {
            o6 = o8;
            i10 = 4;
        }
        int i26 = uVar.f6563g;
        int i27 = i26 & 255;
        if (i27 != 1) {
            if (i27 == 2) {
                o7 = o6;
                i11 = 1;
            } else if (i27 == 3) {
                o7 = o6;
                i11 = 2;
            } else {
                o7 = o6;
                i11 = i9;
            }
        }
        int i28 = (i26 >> 8) & 255;
        if (i28 != 1) {
            i12 = i28 == 2 ? 1 : i28 == 3 ? 2 : i28 == 4 ? 3 : i9;
        }
        int i29 = (i26 >> 16) & 255;
        if (i29 != 1) {
            i13 = 2;
            i14 = i29 == 2 ? 1 : i14;
            if (i7 != i13) {
                truncateAt2 = TextUtils.TruncateAt.END;
            } else if (i7 == 5) {
                truncateAt2 = TextUtils.TruncateAt.MIDDLE;
            } else {
                if (i7 != 4) {
                    int i30 = i12;
                    i15 = 5;
                    i16 = i30;
                    i17 = 4;
                    c6 = ' ';
                    i18 = i14;
                    truncateAt = null;
                    kVarA = a(i24, i25, truncateAt, i6, i10, i11, i16, i18, charSequence4);
                    if (Build.VERSION.SDK_INT >= 35 || c1228c.f13397j.getLetterSpacing() == 0.0f || !(i7 == i17 || i7 == i15)) {
                        i19 = 2;
                        c0590a = this;
                        i20 = i6;
                    } else {
                        Layout layout = kVarA.f6848f;
                        int i31 = i9;
                        if (layout.getEllipsisCount(i31) > 0) {
                            int ellipsisStart = layout.getEllipsisStart(i31);
                            int ellipsisCount = layout.getEllipsisCount(i31) + ellipsisStart;
                            CharSequence charSequenceSubSequence = charSequence4.subSequence(i31, ellipsisStart);
                            CharSequence charSequenceSubSequence2 = charSequence4.subSequence(ellipsisCount, charSequence4.length());
                            CharSequence[] charSequenceArr = new CharSequence[3];
                            charSequenceArr[i31] = charSequenceSubSequence;
                            charSequenceArr[1] = "…";
                            i19 = 2;
                            charSequenceArr[2] = charSequenceSubSequence2;
                            C0590a c0590a2 = this;
                            i20 = i6;
                            kVarA = c0590a2.a(i24, i25, truncateAt, i20, i10, i11, i16, i18, TextUtils.concat(charSequenceArr));
                            c0590a = c0590a2;
                        }
                    }
                    if (i7 != i19 || kVarA.a() <= C2069a.g(j4) || i20 <= 1) {
                        c0590a.f6493d = kVarA;
                    } else {
                        int iG = C2069a.g(j4);
                        int i32 = 0;
                        while (true) {
                            i21 = kVarA.f6849g;
                            if (i32 >= i21) {
                                break;
                            }
                            if (kVarA.e(i32) > iG) {
                                i21 = i32;
                                break;
                            }
                            i32++;
                        }
                        if (i21 >= 0 && i21 != c0590a.f6491b) {
                            kVarA = c0590a.a(i24, i25, truncateAt, i21 < 1 ? 1 : i21, i10, i11, i16, i18, c0590a.f6494e);
                        }
                        c0590a.f6493d = kVarA;
                    }
                    C1228c c1228c2 = c0590a.f6490a;
                    G g6 = o7.f6485a;
                    c1228c2.f13397j.c(g6.f6439a.b(), (((long) Float.floatToRawIntBits(c0590a.b())) & 4294967295L) | (((long) Float.floatToRawIntBits(c0590a.d())) << c6), g6.f6439a.getAlpha());
                    kVar = c0590a.f6493d;
                    if (kVar.f6848f.getText() instanceof Spanned) {
                        Layout layout2 = kVar.f6848f;
                        CharSequence text = layout2.getText();
                        kotlin.jvm.internal.o.f(text, "null cannot be cast to non-null type android.text.Spanned");
                        Spanned spanned = (Spanned) text;
                        if (spanned.nextSpanTransition(-1, spanned.length(), C1962b.class) != spanned.length()) {
                            CharSequence text2 = layout2.getText();
                            kotlin.jvm.internal.o.f(text2, "null cannot be cast to non-null type android.text.Spanned");
                            c1962bArr = (C1962b[]) ((Spanned) text2).getSpans(0, layout2.getText().length(), C1962b.class);
                        }
                    } else {
                        c1962bArr = null;
                    }
                    if (c1962bArr != null) {
                        for (C1962b c1962b : c1962bArr) {
                            float fD = c0590a.d();
                            float fB = c0590a.b();
                            long jFloatToRawIntBits = Float.floatToRawIntBits(fD);
                            long jFloatToRawIntBits2 = ((long) Float.floatToRawIntBits(fB)) & 4294967295L;
                            c1962b.getClass();
                            c1962b.f16266c.setValue(new o0.e(jFloatToRawIntBits2 | (jFloatToRawIntBits << c6)));
                        }
                    }
                    charSequence2 = c0590a.f6494e;
                    if (charSequence2 instanceof Spanned) {
                        Spanned spanned2 = (Spanned) charSequence2;
                        Object[] spans = spanned2.getSpans(0, charSequence2.length(), W0.j.class);
                        ArrayList arrayList = new ArrayList(spans.length);
                        for (Object obj2 : spans) {
                            W0.j jVar = (W0.j) obj2;
                            int spanStart = spanned2.getSpanStart(jVar);
                            int spanEnd = spanned2.getSpanEnd(jVar);
                            int lineForOffset = c0590a.f6493d.f6848f.getLineForOffset(spanStart);
                            boolean z8 = lineForOffset >= c0590a.f6491b;
                            if (c0590a.f6493d.f6848f.getEllipsisCount(lineForOffset) > 0) {
                                z6 = spanEnd > c0590a.f6493d.f6848f.getEllipsisStart(lineForOffset) + c0590a.f6493d.f6848f.getLineStart(lineForOffset);
                            }
                            boolean z9 = spanEnd > c0590a.f6493d.f(lineForOffset);
                            if (z6 || z9 || z8) {
                                c2632c = null;
                            } else {
                                int iOrdinal = (c0590a.f6493d.f6848f.isRtlCharAt(spanStart) ? EnumC2022j.f16383b : EnumC2022j.f16382a).ordinal();
                                if (iOrdinal == 0) {
                                    fH = c0590a.f6493d.h(spanStart, false);
                                } else {
                                    if (iOrdinal != 1) {
                                        throw new E3.v();
                                    }
                                    float fH2 = c0590a.f6493d.h(spanStart, false);
                                    if (!jVar.f8415d) {
                                        AbstractC0958a.b("PlaceholderSpan is not laid out yet.");
                                    }
                                    fH = fH2 - jVar.f8413b;
                                }
                                if (!jVar.f8415d) {
                                    AbstractC0958a.b("PlaceholderSpan is not laid out yet.");
                                }
                                float fD2 = c0590a.f6493d.d(lineForOffset) - jVar.b();
                                c2632c = new C2632c(fH, fD2, jVar.f8413b + fH, jVar.b() + fD2);
                            }
                            arrayList.add(c2632c);
                        }
                        obj = arrayList;
                    } else {
                        obj = x4.y.f26065a;
                    }
                    c0590a.f6495f = obj;
                }
                truncateAt2 = TextUtils.TruncateAt.START;
            }
            i18 = i14;
            truncateAt = truncateAt2;
            i17 = 4;
            int i33 = i12;
            i15 = 5;
            i16 = i33;
            c6 = ' ';
            kVarA = a(i24, i25, truncateAt, i6, i10, i11, i16, i18, charSequence4);
            if (Build.VERSION.SDK_INT >= 35) {
                i19 = 2;
                c0590a = this;
                i20 = i6;
            }
            if (i7 != i19) {
                c0590a.f6493d = kVarA;
            }
            C1228c c1228c22 = c0590a.f6490a;
            G g62 = o7.f6485a;
            c1228c22.f13397j.c(g62.f6439a.b(), (((long) Float.floatToRawIntBits(c0590a.b())) & 4294967295L) | (((long) Float.floatToRawIntBits(c0590a.d())) << c6), g62.f6439a.getAlpha());
            kVar = c0590a.f6493d;
            if (kVar.f6848f.getText() instanceof Spanned) {
            }
            if (c1962bArr != null) {
            }
            charSequence2 = c0590a.f6494e;
            if (charSequence2 instanceof Spanned) {
            }
            c0590a.f6495f = obj;
        }
        i13 = 2;
        i14 = i9;
        if (i7 != i13) {
        }
        i18 = i14;
        truncateAt = truncateAt2;
        i17 = 4;
        int i332 = i12;
        i15 = 5;
        i16 = i332;
        c6 = ' ';
        kVarA = a(i24, i25, truncateAt, i6, i10, i11, i16, i18, charSequence4);
        if (Build.VERSION.SDK_INT >= 35) {
        }
        if (i7 != i19) {
        }
        C1228c c1228c222 = c0590a.f6490a;
        G g622 = o7.f6485a;
        c1228c222.f13397j.c(g622.f6439a.b(), (((long) Float.floatToRawIntBits(c0590a.b())) & 4294967295L) | (((long) Float.floatToRawIntBits(c0590a.d())) << c6), g622.f6439a.getAlpha());
        kVar = c0590a.f6493d;
        if (kVar.f6848f.getText() instanceof Spanned) {
        }
        if (c1962bArr != null) {
        }
        charSequence2 = c0590a.f6494e;
        if (charSequence2 instanceof Spanned) {
        }
        c0590a.f6495f = obj;
    }

    public final U0.k a(int i6, int i7, TextUtils.TruncateAt truncateAt, int i8, int i9, int i10, int i11, int i12, CharSequence charSequence) {
        w wVar;
        float fD = d();
        C1228c c1228c = this.f6490a;
        C1226a c1226a = AbstractC1227b.f13390a;
        y yVar = c1228c.f13392b.f6487c;
        return new U0.k(charSequence, fD, c1228c.f13397j, i6, truncateAt, c1228c.f13401o, (yVar == null || (wVar = yVar.f6573b) == null) ? false : wVar.f6569a, i8, i10, i11, i12, i9, i7, c1228c.l);
    }

    public final float b() {
        return this.f6493d.a();
    }

    /* JADX WARN: Removed duplicated region for block: B:45:0x00d6  */
    /* JADX WARN: Type inference failed for: r13v25, types: [U0.a] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final long c(C2632c c2632c, int i6, G0.K k6) {
        V0.d bVar;
        int i7;
        int[] rangeForRect;
        SegmentFinder segmentFinderJ;
        RectF rectFG = AbstractC2686D.G(c2632c);
        boolean z6 = i6 != 0 && i6 == 1;
        final C0053c c0053c = new C0053c(k6, 12);
        int i8 = Build.VERSION.SDK_INT;
        U0.k kVar = this.f6493d;
        TextPaint textPaint = kVar.f6843a;
        Layout layout = kVar.f6848f;
        if (i8 >= 34) {
            if (z6) {
                segmentFinderJ = new V0.a(new T.p(21, layout.getText(), kVar.j()));
            } else {
                T.n.s();
                segmentFinderJ = T.n.j(T.n.i(layout.getText(), textPaint));
            }
            rangeForRect = layout.getRangeForRect(rectFG, segmentFinderJ, new Layout.TextInclusionStrategy() { // from class: U0.a
                @Override // android.text.Layout.TextInclusionStrategy
                public final boolean isSegmentInside(RectF rectF, RectF rectF2) {
                    return ((Boolean) c0053c.invoke(rectF, rectF2)).booleanValue();
                }
            });
        } else {
            C0606q c0606qC = kVar.c();
            if (z6) {
                bVar = new T.p(21, layout.getText(), kVar.j());
            } else {
                CharSequence text = layout.getText();
                bVar = i8 >= 29 ? new V0.b(text, textPaint) : new V0.c(text);
            }
            V0.d dVar = bVar;
            int lineForVertical = layout.getLineForVertical((int) rectFG.top);
            if (rectFG.top <= kVar.e(lineForVertical) || (lineForVertical = lineForVertical + 1) < kVar.f6849g) {
                int i9 = lineForVertical;
                int lineForVertical2 = layout.getLineForVertical((int) rectFG.bottom);
                if (lineForVertical2 != 0 || rectFG.bottom >= kVar.g(0)) {
                    int iE = U0.h.e(kVar, layout, c0606qC, i9, rectFG, dVar, c0053c, true);
                    while (true) {
                        i7 = i9;
                        if (iE != -1 || i7 >= lineForVertical2) {
                            break;
                        }
                        i9 = i7 + 1;
                        iE = U0.h.e(kVar, layout, c0606qC, i9, rectFG, dVar, c0053c, true);
                    }
                    if (iE == -1) {
                        rangeForRect = null;
                    } else {
                        int i10 = lineForVertical2;
                        int iE2 = U0.h.e(kVar, layout, c0606qC, i10, rectFG, dVar, c0053c, false);
                        while (iE2 == -1 && i7 < i10) {
                            i10--;
                            iE2 = U0.h.e(kVar, layout, c0606qC, i10, rectFG, dVar, c0053c, false);
                        }
                        if (iE2 != -1) {
                            rangeForRect = new int[]{dVar.f(iE + 1), dVar.g(iE2 - 1)};
                        }
                    }
                }
            }
        }
        return rangeForRect == null ? N.f6481b : android.support.v4.media.session.b.g(rangeForRect[0], rangeForRect[1]);
    }

    public final float d() {
        return C2069a.h(this.f6492c);
    }

    public final void e(InterfaceC2712s interfaceC2712s) {
        Canvas canvasA = AbstractC2697c.a(interfaceC2712s);
        U0.k kVar = this.f6493d;
        if (kVar.f6846d) {
            canvasA.save();
            canvasA.clipRect(0.0f, 0.0f, d(), b());
        }
        if (canvasA.getClipBounds(kVar.f6857p)) {
            int i6 = kVar.f6850h;
            if (i6 != 0) {
                canvasA.translate(0.0f, i6);
            }
            ThreadLocal threadLocal = U0.l.f6859a;
            Object jVar = threadLocal.get();
            if (jVar == null) {
                jVar = new U0.j();
                threadLocal.set(jVar);
            }
            U0.j jVar2 = (U0.j) jVar;
            jVar2.f6842a = canvasA;
            try {
                kVar.f6848f.draw(jVar2);
                if (i6 != 0) {
                    canvasA.translate(0.0f, (-1) * i6);
                }
            } finally {
                jVar2.f6842a = null;
            }
        }
        if (kVar.f6846d) {
            canvasA.restore();
        }
    }

    public final void f(InterfaceC2712s interfaceC2712s, long j4, W w6, C2024l c2024l, r0.f fVar) {
        C1230e c1230e = this.f6490a.f13397j;
        int i6 = c1230e.f13406c;
        c1230e.d(j4);
        c1230e.f(w6);
        c1230e.g(c2024l);
        c1230e.e(fVar);
        c1230e.b(3);
        e(interfaceC2712s);
        c1230e.b(i6);
    }

    public final void g(InterfaceC2712s interfaceC2712s, AbstractC2711q abstractC2711q, float f6, W w6, C2024l c2024l, r0.f fVar) {
        C1230e c1230e = this.f6490a.f13397j;
        int i6 = c1230e.f13406c;
        float fD = d();
        c1230e.c(abstractC2711q, (((long) Float.floatToRawIntBits(b())) & 4294967295L) | (Float.floatToRawIntBits(fD) << 32), f6);
        c1230e.f(w6);
        c1230e.g(c2024l);
        c1230e.e(fVar);
        c1230e.b(3);
        e(interfaceC2712s);
        c1230e.b(i6);
    }
}
