package com.bytedance.ies.xelement.text.text;

import X.6db;
import X.C3933Qf4;
import X.C3935Qf6;
import X.C3939QfA;
import X.C3941QfC;
import X.C3945QfG;
import X.C3948QfJ;
import X.C3984Qft;
import X.C3986Qfv;
import X.C4398QmZ;
import X.Fs9;
import X.LbX;
import X.LeS;
import X.Lf3;
import X.LsC;
import X.M12;
import X.Q39;
import X.QNL;
import android.content.Context;
import android.graphics.Typeface;
import android.text.Layout;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.xelement.text.inlinetext.LynxInlineTextShadowNode;
import com.bytedance.ies.xelement.text.inlinetruncation.LynxInlineTruncationShadowNode;
import com.lynx.tasm.behavior.shadow.LayoutNode;
import com.lynx.tasm.behavior.shadow.ShadowNode;
import com.lynx.tasm.behavior.shadow.text.RawTextShadowNode;
import com.lynx.tasm.behavior.shadow.text.TextShadowNode;
import java.util.ArrayList;
import java.util.List;
import kotlin.h.b.n;

public final class LynxTextShadowNode extends TextShadowNode implements LbX {
    public static final Lf3 LIZIZ = new Lf3("^[\\s]+|[\\s]+$");
    public static final C3939QfA LIZJ = new C3939QfA((byte) 0);
    public LsC<? super Context, ? extends Fs9> LIZ = C3945QfG.LIZ;
    public String LJIJI = "none";
    public int LJIJJ;
    public SpannableStringBuilder LJIJJLI;

    public final boolean LIZIZ() {
        return false;
    }

    static {
        Covode.recordClassIndex(32602);
    }

    public final void LIZJ() {
        super.LIZJ();
        CharSequence charSequence = (SpannableStringBuilder) this.LJIJ;
        if (charSequence == null) {
            charSequence = Q39.LIZJ;
        }
        this.LJIJJLI = new SpannableStringBuilder(charSequence);
    }

    private final void LJIIL() {
        CharSequence charSequence = this.LJIJ;
        n.LIZ(charSequence, Q39.LIZJ);
        SpannableStringBuilder spannableStringBuilder = null;
        if ((charSequence instanceof SpannableStringBuilder) && charSequence != null) {
            spannableStringBuilder = (SpannableStringBuilder) charSequence;
        }
        int LJIIIIZZ = LJIIIIZZ();
        for (int i = 0; i < LJIIIIZZ; i++) {
            ShadowNode LIZIZ2 = LIZIZ(i);
            if ((LIZIZ2 instanceof LynxInlineTruncationShadowNode) && spannableStringBuilder != null) {
                spannableStringBuilder.append(((TextShadowNode) LIZIZ2).LJIJ);
            }
        }
    }

    @QNL(LIZ = "text-maxline")
    public final void setTextMaxLine(String str) {
        M12.LIZ(str);
        super.setTextMaxLine(str);
        this.LJIJJ = Integer.parseInt(str);
        LJFF();
    }

    public final void LIZ(C4398QmZ qmZ) {
        super.LIZ(qmZ);
        C3984Qft LIZ2 = C3984Qft.LIZJ.LIZ();
        LsC<? super Context, ? extends Fs9> lsC = this.LIZ;
        if (qmZ == null) {
            n.LIZ();
        }
        LIZ2.LIZ((Fs9) lsC.invoke(qmZ));
    }

    @QNL(LIZ = "ellipsize-mode")
    public final void setEllipsizeMode(String str) {
        M12.LIZ(str);
        int hashCode = str.hashCode();
        if (hashCode != 3056464) {
            if (hashCode == 3552336 && str.equals("tail")) {
                setTextOverflow(1);
            }
        } else if (str.equals("clip")) {
            setTextOverflow(0);
        }
        LJFF();
    }

    @QNL(LIZ = "richtype")
    public final void setRichType(String str) {
        float f;
        M12.LIZ(str);
        this.LJIJI = str;
        if (n.LIZ(str, "bracket")) {
            C3933Qf4 qf4 = this.LJIILJJIL;
            n.LIZ(qf4, Q39.LIZJ);
            if (C3948QfJ.LIZ(qf4.LJIIJ)) {
                f = 40.0f;
            } else {
                C3933Qf4 qf42 = this.LJIILJJIL;
                n.LIZ(qf42, Q39.LIZJ);
                f = qf42.LJIIJ;
            }
            setLineHeight(f);
        }
        LJFF();
    }

    /* JADX WARNING: Removed duplicated region for block: B:37:0x0104  */
    /* JADX WARNING: Removed duplicated region for block: B:47:0x0138  */
    /* JADX WARNING: Removed duplicated region for block: B:67:0x01b1  */
    /* JADX WARNING: Removed duplicated region for block: B:78:0x01fb  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private final boolean LIZIZ(float r19) {
        /*
            r18 = this;
            r2 = r18
            java.lang.String r3 = ""
            int r5 = r18.LJIIIIZZ()
            r6 = 0
            r4 = 0
            r1 = 0
        L_0x000b:
            if (r4 >= r5) goto L_0x001a
            com.lynx.tasm.behavior.shadow.ShadowNode r0 = r2.LIZIZ(r4)
            boolean r0 = r0 instanceof com.bytedance.ies.xelement.text.inlinetruncation.LynxInlineTruncationShadowNode
            if (r0 == 0) goto L_0x0017
            int r1 = r1 + 1
        L_0x0017:
            int r4 = r4 + 1
            goto L_0x000b
        L_0x001a:
            if (r1 > 0) goto L_0x001d
            return r6
        L_0x001d:
            r7 = 0
            X.QmZ r1 = r18.LJIIJ()     // Catch:{ Qf2 -> 0x003d, Exception -> 0x002c }
            X.Qf4 r0 = r2.LJIILJJIL     // Catch:{ Qf2 -> 0x003d, Exception -> 0x002c }
            android.text.TextPaint r4 = X.C3930Qf1.LIZ((X.C4398QmZ) r1, (X.C3933Qf4) r0)     // Catch:{ Qf2 -> 0x003d, Exception -> 0x002c }
            kotlin.h.b.n.LIZ(r4, r3)     // Catch:{ Qf2 -> 0x003d, Exception -> 0x002c }
            goto L_0x006c
        L_0x002c:
            r0 = move-exception
            java.lang.String r1 = java.lang.String.valueOf(r0)
            java.lang.String r0 = "create text paint failed during ellipsize. e:"
            java.lang.String r1 = r0.concat(r1)
            java.lang.String r0 = "LynxTextShadowNode"
            com.lynx.tasm.base.LLog.LIZLLL(r0, r1)
            return r6
        L_0x003d:
            X.LbP r5 = X.LbP.LIZ()
            X.QmZ r4 = r18.LJIIJ()
            X.Qf4 r0 = r2.LJIILJJIL
            kotlin.h.b.n.LIZ(r0, r3)
            java.lang.String r1 = r0.LJIJ
            X.Qf4 r0 = r2.LJIILJJIL
            kotlin.h.b.n.LIZ(r0, r3)
            int r0 = r0.LJII
            r5.LIZ(r4, r1, r0, r2)
            X.Qf4 r0 = r2.LJIILJJIL
            X.Qf4 r1 = r0.LIZIZ()
            kotlin.h.b.n.LIZ(r1, r3)
            r1.LJIJ = r7
            X.QmZ r0 = r18.LJIIJ()
            android.text.TextPaint r4 = X.C3930Qf1.LIZ((X.C4398QmZ) r0, (X.C3933Qf4) r1)
            kotlin.h.b.n.LIZ(r4, r3)
        L_0x006c:
            int r1 = android.os.Build.VERSION.SDK_INT
            r0 = 23
            r5 = r19
            if (r1 < r0) goto L_0x015e
            java.lang.CharSequence r1 = r2.LJIJ
            java.lang.CharSequence r0 = r2.LJIJ
            int r0 = r0.length()
            int r7 = (int) r5
            android.text.StaticLayout$Builder r1 = android.text.StaticLayout.Builder.obtain(r1, r6, r0, r4, r7)
            android.text.Layout$Alignment r0 = android.text.Layout.Alignment.ALIGN_NORMAL
            android.text.StaticLayout$Builder r6 = r1.setAlignment(r0)
            X.Qf4 r0 = r2.LJIILJJIL
            kotlin.h.b.n.LIZ(r0, r3)
            float r1 = r0.LJIIL
            r0 = 1065353216(0x3f800000, float:1.0)
            android.text.StaticLayout$Builder r1 = r6.setLineSpacing(r1, r0)
            X.Qf4 r0 = r2.LJIILJJIL
            kotlin.h.b.n.LIZ(r0, r3)
            boolean r0 = r0.LJIIZILJ
            android.text.StaticLayout$Builder r1 = r1.setIncludePad(r0)
            android.text.TextUtils$TruncateAt r0 = android.text.TextUtils.TruncateAt.END
            android.text.StaticLayout$Builder r0 = r1.setEllipsize(r0)
            android.text.StaticLayout$Builder r1 = r0.setEllipsizedWidth(r7)
            X.Qf4 r0 = r2.LJIILJJIL
            kotlin.h.b.n.LIZ(r0, r3)
            android.text.TextDirectionHeuristic r0 = r0.LIZLLL()
            android.text.StaticLayout$Builder r0 = r1.setTextDirection(r0)
            android.text.StaticLayout r10 = r0.build()
            kotlin.h.b.n.LIZ(r10, r3)
        L_0x00bd:
            int r1 = android.os.Build.VERSION.SDK_INT
            r0 = 29
            if (r1 != r0) goto L_0x00ce
            boolean r0 = X.LoI.LIZJ()
            if (r0 == 0) goto L_0x00ce
            java.lang.CharSequence r0 = r2.LJIJ
            X.Ap4.LIZ(r10, r0)
        L_0x00ce:
            int r0 = r2.LJIJJ
            r14 = 1
            if (r0 <= 0) goto L_0x00de
            r0 = r10
            android.text.StaticLayout r0 = (android.text.StaticLayout) r0
            int r1 = r0.getLineCount()
            int r0 = r2.LJIJJ
            if (r1 > r0) goto L_0x00f3
        L_0x00de:
            int r7 = r18.LJIIIIZZ()
            r6 = 0
        L_0x00e3:
            if (r6 >= r7) goto L_0x015b
            com.lynx.tasm.behavior.shadow.ShadowNode r1 = r2.LIZIZ(r6)
            boolean r0 = r1 instanceof com.bytedance.ies.xelement.text.inlinetruncation.LynxInlineTruncationShadowNode
            if (r0 == 0) goto L_0x0158
            com.bytedance.ies.xelement.text.inlinetruncation.LynxInlineTruncationShadowNode r1 = (com.bytedance.ies.xelement.text.inlinetruncation.LynxInlineTruncationShadowNode) r1
            boolean r0 = r1.LIZ
            if (r0 == 0) goto L_0x0158
        L_0x00f3:
            r16 = 1
        L_0x00f5:
            r0 = r10
            android.text.StaticLayout r0 = (android.text.StaticLayout) r0
            int r1 = r0.getLineCount()
            int r0 = r2.LJIJJ
            int r11 = X.C5048Qx3.LIZLLL(r1, r0)
            if (r16 == 0) goto L_0x0239
            int r0 = r11 + -1
            float r6 = r10.getLineWidth(r0)
            int r8 = r10.getLineEnd(r0)
            int r7 = r10.getLineStart(r0)
            java.lang.CharSequence r0 = r2.LJIJ
            int r13 = r8 + -1
            char r12 = r0.charAt(r13)
            r1 = 10
            r9 = 13
            r0 = 2
            if (r12 != r1) goto L_0x0152
            if (r8 <= r14) goto L_0x0150
            java.lang.CharSequence r1 = r2.LJIJ
            int r0 = r8 + -2
            char r0 = r1.charAt(r0)
            if (r0 != r9) goto L_0x0150
            r0 = 2
        L_0x012e:
            int r8 = r8 - r0
        L_0x012f:
            r14 = 1
        L_0x0130:
            r9 = 0
            int r12 = r18.LJIIIIZZ()
            r1 = 0
        L_0x0136:
            if (r1 >= r12) goto L_0x0191
            com.lynx.tasm.behavior.shadow.ShadowNode r13 = r2.LIZIZ(r1)
            boolean r0 = r13 instanceof com.bytedance.ies.xelement.text.inlinetruncation.LynxInlineTruncationShadowNode
            if (r0 == 0) goto L_0x014b
            com.lynx.tasm.behavior.shadow.text.TextShadowNode r13 = (com.lynx.tasm.behavior.shadow.text.TextShadowNode) r13
            java.lang.CharSequence r0 = r13.LJIJ
            if (r0 == 0) goto L_0x014b
            float r0 = android.text.Layout.getDesiredWidth(r0, r4)
            float r9 = r9 + r0
        L_0x014b:
            int r1 = r1 + 1
            r0 = 0
            r0 = 1
            goto L_0x0136
        L_0x0150:
            r0 = 1
            goto L_0x012e
        L_0x0152:
            if (r12 != r9) goto L_0x0156
            r8 = r13
            goto L_0x012f
        L_0x0156:
            r14 = 0
            goto L_0x0130
        L_0x0158:
            int r6 = r6 + 1
            goto L_0x00e3
        L_0x015b:
            r16 = 0
            goto L_0x00f5
        L_0x015e:
            java.lang.CharSequence r8 = r2.LJIJ
            java.lang.CharSequence r0 = r2.LJIJ
            int r9 = r0.length()
            int r7 = (int) r5
            android.text.Layout$Alignment r12 = android.text.Layout.Alignment.ALIGN_NORMAL
            X.Qf4 r0 = r2.LJIILJJIL
            kotlin.h.b.n.LIZ(r0, r3)
            float r6 = r0.LJIIL
            X.Qf4 r0 = r2.LJIILJJIL
            kotlin.h.b.n.LIZ(r0, r3)
            boolean r1 = r0.LJIIZILJ
            android.text.TextUtils$TruncateAt r15 = android.text.TextUtils.TruncateAt.END
            r16 = -1
            X.Qf4 r0 = r2.LJIILJJIL
            kotlin.h.b.n.LIZ(r0, r3)
            android.text.TextDirectionHeuristic r17 = r0.LIZLLL()
            r10 = r4
            r11 = r7
            r13 = r6
            r14 = r1
            android.text.StaticLayout r10 = X.C3905Qec.LIZ(r8, r9, r10, r11, r12, r13, r14, r15, r16, r17)
            kotlin.h.b.n.LIZ(r10, r3)
            goto L_0x00bd
        L_0x0191:
            r12 = 1056964608(0x3f000000, float:0.5)
            float r9 = r9 + r12
            double r0 = (double) r9
            double r0 = java.lang.Math.ceil(r0)
            float r9 = (float) r0
            float r9 = r9 + r6
            int r0 = (r9 > r5 ? 1 : (r9 == r5 ? 0 : -1))
            float r0 = r9 - r5
            float r0 = r0 + r12
            int r1 = (int) r0
            X.Qf4 r0 = r2.LJIILJJIL
            int r0 = r0.LJ
            if (r0 != 0) goto L_0x01ad
            int r0 = (r9 > r5 ? 1 : (r9 == r5 ? 0 : -1))
            if (r0 >= 0) goto L_0x0203
            if (r14 == 0) goto L_0x0203
        L_0x01ad:
            java.lang.CharSequence r5 = r2.LJIJ
            if (r5 == 0) goto L_0x01fb
            android.text.Spanned r5 = (android.text.Spanned) r5
            java.lang.Class<java.lang.Object> r0 = java.lang.Object.class
            java.lang.Object[] r9 = r5.getSpans(r8, r8, r0)
            X.Qf4 r0 = r2.LJIILJJIL
            int r5 = r0.LJ
            r0 = 3
            if (r5 != r0) goto L_0x01dd
            android.text.SpannableStringBuilder r5 = new android.text.SpannableStringBuilder
            java.lang.String r0 = "‎…‬"
            r5.<init>(r0)
        L_0x01c7:
            kotlin.h.b.n.LIZ(r9, r3)
            int r15 = r9.length
            r14 = 0
        L_0x01cc:
            if (r14 >= r15) goto L_0x01f3
            r13 = r9[r14]
            int r12 = r5.length()
            r3 = 33
            r0 = 0
            r5.setSpan(r13, r0, r12, r3)
            int r14 = r14 + 1
            goto L_0x01cc
        L_0x01dd:
            X.Qf4 r0 = r2.LJIILJJIL
            int r0 = r0.LJ
            if (r0 == 0) goto L_0x01eb
            android.text.SpannableStringBuilder r5 = new android.text.SpannableStringBuilder
            java.lang.String r0 = "…"
            r5.<init>(r0)
            goto L_0x01c7
        L_0x01eb:
            android.text.SpannableStringBuilder r5 = new android.text.SpannableStringBuilder
            java.lang.String r0 = "‏…‬"
            r5.<init>(r0)
            goto L_0x01c7
        L_0x01f3:
            float r0 = android.text.Layout.getDesiredWidth(r5, r4)
            int r0 = (int) r0
            int r1 = r1 + r0
            r13 = 1
            goto L_0x0205
        L_0x01fb:
            X.7xU r1 = new X.7xU
            java.lang.String r0 = "null cannot be cast to non-null type android.text.Spanned"
            r1.<init>(r0)
            throw r1
        L_0x0203:
            r13 = 0
            r5 = 0
        L_0x0205:
            java.lang.CharSequence r0 = r2.LJIJ
            java.lang.CharSequence r0 = r0.subSequence(r7, r8)
            java.util.List r9 = r2.LIZ(r1, r0, r4)
            android.text.SpannableStringBuilder r3 = new android.text.SpannableStringBuilder
            r3.<init>()
            r0 = 1
            if (r11 <= r0) goto L_0x0227
            java.lang.CharSequence r12 = r2.LJIJ
            int r0 = r11 + -2
            int r1 = r10.getLineEnd(r0)
            r0 = 0
            java.lang.CharSequence r0 = r12.subSequence(r0, r1)
            r3.append(r0)
        L_0x0227:
            if (r13 == 0) goto L_0x023a
            java.lang.CharSequence r0 = r2.LJIJ
            java.lang.CharSequence r0 = r0.subSequence(r7, r8)
            r3.append(r0)
        L_0x0232:
            if (r5 == 0) goto L_0x0237
            r3.append(r5)
        L_0x0237:
            r2.LJIJ = r3
        L_0x0239:
            return r16
        L_0x023a:
            java.lang.CharSequence r0 = r2.LJIJ
            java.lang.CharSequence r1 = r0.subSequence(r7, r8)
            r0 = 1
            java.lang.Object r0 = r9.get(r0)
            java.lang.Number r0 = (java.lang.Number) r0
            float r0 = r0.floatValue()
            float r6 = r6 - r0
            android.text.TextUtils$TruncateAt r0 = android.text.TextUtils.TruncateAt.END
            java.lang.CharSequence r0 = android.text.TextUtils.ellipsize(r1, r4, r6, r0)
            r3.append(r0)
            goto L_0x0232
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.ies.xelement.text.text.LynxTextShadowNode.LIZIZ(float):boolean");
    }

    public final void LIZ(Typeface typeface, int i) {
        LJFF();
    }

    private final int LIZ(List<? extends List<Integer>> list, int i) {
        int size = list.size();
        while (true) {
            size--;
            if (size < 0) {
                return 0;
            }
            List list2 = (List) list.get(size);
            if (((Number) list2.get(0)).intValue() <= i && i <= ((Number) list2.get(1)).intValue()) {
                return ((Number) list2.get(1)).intValue() - ((Number) list2.get(0)).intValue();
            }
        }
    }

    public final void LIZ(SpannableStringBuilder spannableStringBuilder, RawTextShadowNode rawTextShadowNode) {
        M12.LIZ(spannableStringBuilder, rawTextShadowNode);
        String LIZ2 = LIZJ.LIZ(rawTextShadowNode.LIZ);
        if (n.LIZ(this.LJIJI, "bracket")) {
            C3986Qfv qfv = C3986Qfv.LIZJ;
            C4398QmZ LJIIJ = LJIIJ();
            C3933Qf4 qf4 = this.LJIILJJIL;
            n.LIZ(qf4, Q39.LIZJ);
            spannableStringBuilder.append(qfv.LIZ(LJIIJ, LIZ2, (int) qf4.LJIIJ));
            return;
        }
        spannableStringBuilder.append(LIZ2);
    }

    public final void LIZ(SpannableStringBuilder spannableStringBuilder, List<C3941QfC> list) {
        int LJIIIIZZ = LJIIIIZZ();
        for (int i = 0; i < LJIIIIZZ; i++) {
            ShadowNode LIZIZ2 = LIZIZ(i);
            if (LIZIZ2 instanceof LynxInlineTextShadowNode) {
                String str = this.LJIJI;
                M12.LIZ(str);
                ((LynxInlineTextShadowNode) LIZIZ2).LIZ = str;
            }
        }
        super.LIZ(spannableStringBuilder, list);
    }

    private final List<Integer> LIZ(int i, CharSequence charSequence, TextPaint textPaint) {
        ArrayList LIZLLL = LeS.LIZLLL(new Integer[]{0, 0});
        CharSequence charSequence2 = charSequence;
        if (TextUtils.isEmpty(charSequence2)) {
            return LIZLLL;
        }
        int length = charSequence2.length();
        float f = 0.0f;
        ArrayList arrayList = new ArrayList();
        if (!TextUtils.isEmpty(charSequence2) && (charSequence2 instanceof Spanned)) {
            Spanned spanned = (Spanned) charSequence2;
            for (6db r14 : (6db[]) spanned.getSpans(0, charSequence2.length(), 6db.class)) {
                arrayList.add(LeS.LIZIZ(new Integer[]{Integer.valueOf(spanned.getSpanStart(r14)), Integer.valueOf(spanned.getSpanEnd(r14))}));
            }
        }
        while (true) {
            if (length <= 0) {
                break;
            }
            int i2 = i;
            TextPaint textPaint2 = textPaint;
            if (((float) i2) <= f) {
                while (((float) i2) > f) {
                    length--;
                    f = Layout.getDesiredWidth(charSequence2.subSequence(length, charSequence2.length()), textPaint2);
                    if (length <= 0) {
                        break;
                    }
                }
            } else {
                int LIZ2 = LIZ((List<? extends List<Integer>>) arrayList, length);
                if (LIZ2 <= 0) {
                    LIZ2 = 1;
                }
                length -= LIZ2;
                f = Layout.getDesiredWidth(charSequence2.subSequence(length, charSequence2.length()), textPaint2);
            }
        }
        LIZLLL.set(0, Integer.valueOf(charSequence2.length() - length));
        LIZLLL.set(1, Integer.valueOf((int) f));
        return LIZLLL;
    }

    public final long LIZ(LayoutNode layoutNode, float f, C3935Qf6 qf6, float f2, C3935Qf6 qf62) {
        float f3;
        if (this.LJIJJLI != null) {
            this.LJIJ = new SpannableStringBuilder(this.LJIJJLI);
        }
        if (qf6 == C3935Qf6.UNDEFINED) {
            f3 = Float.MAX_VALUE;
        } else {
            f3 = f;
        }
        if (LIZIZ(f3)) {
            LJIIL();
        }
        return super.LIZ(layoutNode, f, qf6, f2, qf62);
    }
}
