package com.ss.android.ugc.aweme.editSticker.text.als;

import X.0Gp;
import X.0HH;
import X.0PM;
import X.1Bn;
import X.1Hw;
import X.1iq;
import X.2HN;
import X.2Pr;
import X.3G4;
import X.7he;
import X.8cV;
import X.AnonymousClass5LC;
import X.AnonymousClass5M6;
import X.AnonymousClass5PR;
import X.AnonymousClass5PS;
import X.AnonymousClass6NJ;
import X.AnonymousClass6NK;
import X.AnonymousClass6OD;
import X.AnonymousClass6OE;
import X.AnonymousClass6OG;
import X.AnonymousClass6OH;
import X.AnonymousClass6OK;
import X.AnonymousClass6ON;
import X.AnonymousClass6OV;
import X.AnonymousClass6P0;
import X.AnonymousClass6P1;
import X.AnonymousClass6P2;
import X.AnonymousClass6P3;
import X.AnonymousClass6P4;
import X.AnonymousClass6P5;
import X.AnonymousClass6P6;
import X.AnonymousClass6P7;
import X.AnonymousClass6P8;
import X.AnonymousClass6P9;
import X.AnonymousClass6PA;
import X.AnonymousClass6PB;
import X.AnonymousClass6PC;
import X.AnonymousClass6PD;
import X.AnonymousClass6PE;
import X.AnonymousClass6PG;
import X.AnonymousClass6PH;
import X.AnonymousClass6PI;
import X.AnonymousClass6PJ;
import X.AnonymousClass6PP;
import X.AnonymousClass6PS;
import X.AnonymousClass6R7;
import X.C03505Am;
import X.C04875Ft;
import X.C06105Km;
import X.C14105gO;
import X.C17855mR;
import X.C18225n2;
import X.C23805w2;
import X.C32696Ot;
import X.C32756Oz;
import X.C32776Pb;
import X.C32786Pc;
import X.C32936Pr;
import X.C38056dv;
import X.C43576mp;
import X.Crj;
import X.Cwu;
import X.I9P;
import X.LsC;
import X.LsD;
import X.M12;
import android.content.Context;
import android.graphics.PointF;
import android.graphics.RectF;
import android.text.TextWatcher;
import android.view.ViewGroup;
import com.bytedance.covode.number.Covode;
import com.bytedance.ui_component.LifecycleAwareViewModel;
import com.google.gson.Gson;
import com.ss.android.ugc.aweme.editSticker.compile.TextStickerCompileResult;
import com.ss.android.ugc.aweme.editSticker.model.StickerItemModel;
import com.ss.android.ugc.aweme.editSticker.text.bean.TextStickerData;
import com.ss.android.ugc.aweme.editSticker.text.bean.TextStickerTextWrap;
import com.ss.android.ugc.aweme.sticker.data.InteractStickerStruct;
import com.ss.android.ugc.aweme.sticker.data.NormalTrackTimeStamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import kotlin.h.b.n;

public final class EditTextStickerViewModel extends LifecycleAwareViewModel<EditTextStickerViewState> implements C17855mR, C18225n2 {
    public static final AnonymousClass6PP LJIILL = new AnonymousClass6PP((byte) 0);
    public final String LIZ = "EditTextStickerViewModel";
    public boolean LIZIZ;
    public boolean LIZJ;
    public TextStickerData LIZLLL;
    public boolean LJ;
    public final List<C32786Pc> LJFF = new ArrayList();
    public boolean LJI = true;
    public boolean LJII;
    public final 1Hw<2Pr> LJIIL = new 1Hw<>();
    public final 1Hw<Cwu<Boolean, Boolean>> LJIILIIL = new 1Hw<>();
    public final 1Hw<Boolean> LJIILJJIL = new 1Hw<>();
    public 1Bn<Boolean> LJIILLIIL;
    public final Crj LJIIZILJ = 7he.LIZ(C06105Km.LIZ);
    public Cwu<Integer, Integer> LJIJ;
    public final Crj LJIJI = 7he.LIZ(AnonymousClass6PS.LIZ);
    public final 1iq<Boolean> LJIJJ = new 1iq<>(false);

    static {
        Covode.recordClassIndex(73609);
    }

    public final void LJFF() {
        this.LIZJ = true;
    }

    public final 1Bn<Cwu<Float, Boolean>> LJJ() {
        return (1Bn) this.LJIIZILJ.getValue();
    }

    public final 1Hw<2Pr> LIZIZ() {
        return this.LJIIL;
    }

    public final 1Hw<Cwu<Boolean, Boolean>> LIZJ() {
        return this.LJIILIIL;
    }

    public final 1Hw<Boolean> LIZLLL() {
        return this.LJIILJJIL;
    }

    public final boolean LJ() {
        return this.LIZIZ;
    }

    public final C17855mR LJIJ() {
        return this;
    }

    public final List<C32786Pc> LJIJI() {
        return this.LJFF;
    }

    public final 0PM<Boolean> LJIJJLI() {
        return this.LJIJJ;
    }

    public final void LIZ(boolean z) {
        LIZJ(new AnonymousClass6ON(z));
        this.LJ = z;
        for (C32786Pc r1 : this.LJFF) {
            r1.LJJIIJ = this.LJ;
        }
    }

    public final void LIZ(TextStickerData textStickerData, String str) {
        M12.LIZ(textStickerData);
        LIZJ(new AnonymousClass6OE(textStickerData, str));
    }

    public final void LIZ(TextStickerData textStickerData) {
        M12.LIZ(textStickerData);
        LIZLLL(new AnonymousClass6OD(textStickerData));
    }

    public final boolean LIZ(RectF rectF) {
        M12.LIZ(rectF);
        for (C32786Pc anglePointList : this.LJFF) {
            PointF[] anglePointList2 = anglePointList.getAnglePointList();
            if (!(anglePointList2 == null || anglePointList2.length == 0)) {
                RectF LIZ2 = C23805w2.LIZ(anglePointList2);
                n.LIZIZ(LIZ2, "");
                if (LIZ2.top < rectF.top || LIZ2.bottom > rectF.bottom) {
                    return true;
                }
            }
        }
        return false;
    }

    public final void LIZ(LsD<? super C32786Pc, ? super C32786Pc, 2Pr> lsD) {
        LIZJ(new AnonymousClass6P1(lsD));
    }

    public final void LIZ(LsC<? super C32786Pc, 2Pr> lsC) {
        LIZJ(new AnonymousClass6PA(lsC));
    }

    public final void LIZ(C32936Pr r2) {
        LIZJ(new AnonymousClass6P2(r2));
    }

    public final void LIZ(Cwu<Integer, Integer> cwu) {
        if (this.LJIJ == null) {
            this.LJIJ = cwu;
        }
        LIZJ(new AnonymousClass6P4(cwu));
    }

    public final void LIZ(TextWatcher textWatcher) {
        M12.LIZ(textWatcher);
        LIZLLL(new AnonymousClass6P7(textWatcher));
    }

    public final void LJI() {
        LIZLLL(AnonymousClass6P8.LIZ);
    }

    public final void LJIIIZ() {
        LIZJ(AnonymousClass6P0.LIZ);
    }

    public final void LJIIJ() {
        LIZJ(AnonymousClass6PI.LIZ);
    }

    public final void LJIIJJI() {
        LIZJ(AnonymousClass6PH.LIZ);
    }

    public final void LJIILIIL() {
        LIZLLL(AnonymousClass6PG.LIZ);
    }

    public final void LJIILJJIL() {
        LIZLLL(AnonymousClass6OH.LIZ);
    }

    public final void LJIL() {
        LIZJ(AnonymousClass6PJ.LIZ);
    }

    public final int LJJIFFI() {
        return this.LJFF.size();
    }

    public final boolean LJJII() {
        return this.LJFF.isEmpty();
    }

    public final void LJII() {
        LIZLLL(new AnonymousClass6PD());
    }

    public final void LJIIL() {
        LIZJ(new AnonymousClass6P6());
    }

    public final boolean LJIILLIIL() {
        if (!LJJII()) {
            return true;
        }
        return false;
    }

    public final boolean LJIIIIZZ() {
        Boolean bool;
        1Bn<Boolean> r0 = this.LJIILLIIL;
        if (r0 == null || (bool = (Boolean) r0.getValue()) == null) {
            return false;
        }
        return bool.booleanValue();
    }

    public final C32786Pc LJJIII() {
        T t;
        Iterator<T> it = this.LJFF.iterator();
        while (true) {
            if (!it.hasNext()) {
                t = null;
                break;
            }
            t = it.next();
            if (((C32786Pc) t).LJIILIIL) {
                break;
            }
        }
        return (C32786Pc) t;
    }

    public final boolean LJIILL() {
        LIZJ(AnonymousClass6OG.LIZ);
        boolean z = false;
        for (C32786Pc next : this.LJFF) {
            if (next.LJ()) {
                next.setShowHelpBox(false);
                z = true;
            }
        }
        return z;
    }

    public final boolean LJIIZILJ() {
        Iterator<T> it = this.LJFF.iterator();
        while (true) {
            if (!it.hasNext()) {
                break;
            }
            T next = it.next();
            TextStickerData data = ((C32786Pc) next).getData();
            if (data != null && data.getHasReadTextAudio()) {
                if (next != null) {
                    return true;
                }
            }
        }
        return false;
    }

    public final List<TextStickerData> LJIJJ() {
        ArrayList arrayList = new ArrayList();
        for (C32786Pc LIZIZ2 : this.LJFF) {
            TextStickerData LIZIZ3 = LIZIZ2.LIZIZ();
            n.LIZIZ(LIZIZ3, "");
            arrayList.add(LIZIZ3);
        }
        return arrayList;
    }

    public final int LJJI() {
        if (this.LJFF.isEmpty()) {
            return 0;
        }
        int size = this.LJFF.size();
        int i = 0;
        for (int i2 = 0; i2 < size; i2++) {
            List<TextStickerTextWrap> textWrapList = this.LJFF.get(i2).getTextWrapList();
            n.LIZIZ(textWrapList, "");
            for (TextStickerTextWrap next : textWrapList) {
                if (next != null) {
                    i += next.safeStrPair().LIZIZ.size();
                }
            }
        }
        return i;
    }

    public final /* synthetic */ C03505Am dU_() {
        return new EditTextStickerViewState((C04875Ft) null, false, (C14105gO) null, (AnonymousClass5LC) null, (AnonymousClass5M6) null, (C14105gO) null, (AnonymousClass5LC) null, (C14105gO) null, (C14105gO) null, (C14105gO) null, (C14105gO) null, (C14105gO) null, (C14105gO) null, (C14105gO) null, (C14105gO) null, (C14105gO) null, (C14105gO) null, (AnonymousClass5LC) null, (AnonymousClass5LC) null, (AnonymousClass5PR) null, (AnonymousClass5LC) null, (AnonymousClass5PR) null, (C14105gO) null, (AnonymousClass5LC) null, (C14105gO) null, (AnonymousClass5PR) null, (AnonymousClass5PR) null, (C14105gO) null, (C14105gO) null, (AnonymousClass5PR) null, (AnonymousClass5PR) null, (C14105gO) null, (C14105gO) null, (C14105gO) null, (AnonymousClass5PS) null, (AnonymousClass5LC) null, (AnonymousClass5LC) null, -1, 31, (2HN) null);
    }

    public final void LIZ(1Bn<Boolean> r1) {
        M12.LIZ(r1);
        this.LJIILLIIL = r1;
    }

    public final void LIZ(int i) {
        LIZJ(new AnonymousClass6PB(i));
    }

    public final void LIZIZ(C32786Pc r3) {
        M12.LIZ(r3);
        this.LJFF.add(0, r3);
    }

    public final void LIZJ(C32786Pc r2) {
        LIZJ(new AnonymousClass6OK(r2));
    }

    public final void LIZLLL(boolean z) {
        LIZJ(new AnonymousClass6PE(z));
    }

    public final void LJ(boolean z) {
        LIZLLL(new AnonymousClass6PC(z));
    }

    public final void LJFF(boolean z) {
        this.LJIJJ.LIZIZ(Boolean.valueOf(z));
    }

    public final void LIZ(float f) {
        LJJ().setValue(new Cwu(Float.valueOf(f), false));
    }

    public final void LIZIZ(LsC<? super C32786Pc, 2Pr> lsC) {
        LIZJ(new AnonymousClass6P9(lsC));
    }

    public final void LIZJ(boolean z) {
        this.LJI = z;
        for (C32786Pc enableEdit : this.LJFF) {
            enableEdit.setEnableEdit(this.LJI);
        }
    }

    public final Cwu<Float, Float> LIZ(Context context) {
        float f;
        int LIZ2;
        Cwu<Integer, Integer> cwu = this.LJIJ;
        float f2 = 0.0f;
        if (cwu != null) {
            f2 = (float) ((Number) cwu.getFirst()).intValue();
            LIZ2 = ((Number) cwu.getSecond()).intValue();
        } else if (context != null) {
            f2 = (float) 3G4.LIZIZ(context);
            LIZ2 = 3G4.LIZ(context);
        } else {
            f = 0.0f;
            return new Cwu<>(Float.valueOf(f2), Float.valueOf(f));
        }
        f = (float) LIZ2;
        return new Cwu<>(Float.valueOf(f2), Float.valueOf(f));
    }

    public final void LIZIZ(boolean z) {
        LIZJ(new AnonymousClass6OV(z));
        1Bn<Boolean> r2 = this.LJIILLIIL;
        if (r2 != null && (!n.LIZ(r2.getValue(), Boolean.valueOf(z)))) {
            r2.setValue(Boolean.valueOf(z));
        }
    }

    public final void LIZ(AnonymousClass6NJ r2) {
        LIZJ(new AnonymousClass6P5(r2));
    }

    public final void LIZ(AnonymousClass6NK r2) {
        LIZJ(new AnonymousClass6P3(r2));
    }

    public final void LIZ(C32786Pc r2) {
        M12.LIZ(r2);
        this.LJFF.remove(r2);
    }

    public final 0Gp<List<TextStickerCompileResult>> LIZ(C32696Ot r14, ViewGroup viewGroup) {
        ViewGroup viewGroup2 = viewGroup;
        M12.LIZ(r14, viewGroup2);
        LJIILL();
        ArrayList arrayList = new ArrayList();
        for (C32786Pc next : this.LJFF) {
            0Gp LIZJ2 = ((C38056dv) this.LJIJI.getValue()).LIZ(next, viewGroup2, r14.LIZ, r14.LIZIZ, r14.LIZJ, r14.LIZLLL, r14.LJ).LIZJ(new C32756Oz(this, arrayList, next, viewGroup2));
            n.LIZIZ(LIZJ2, "");
            arrayList.add(LIZJ2);
        }
        0Gp<List<TextStickerCompileResult>> LIZ2 = 0Gp.LIZ(arrayList);
        n.LIZIZ(LIZ2, "");
        return LIZ2;
    }

    private final PointF LIZ(PointF pointF, Context context) {
        int i;
        PointF pointF2 = new PointF();
        Cwu<Integer, Integer> cwu = this.LJIJ;
        int i2 = 0;
        if (cwu != null) {
            i = ((Number) cwu.getFirst()).intValue();
            i2 = ((Number) cwu.getSecond()).intValue();
        } else if (context != null) {
            i = 3G4.LIZIZ(context);
            i2 = 3G4.LIZ(context);
        } else {
            i = 0;
        }
        if (i2 == 0 || i == 0) {
            i = 3G4.LIZIZ(I9P.LIZIZ.LIZIZ());
            i2 = 3G4.LIZ(I9P.LIZIZ.LIZIZ());
        }
        try {
            AnonymousClass6PP r7 = LJIILL;
            pointF2.set(r7.LIZ((pointF.x * 1.0f) / ((float) i)), r7.LIZ((pointF.y * 1.0f) / ((float) i2)));
        } catch (Exception unused) {
            8cV.LIZ(this.LIZ + ": " + ("x: " + pointF.x + ", y: " + pointF.y + ", videoW: " + i + ", videoH: " + i2));
        }
        return pointF2;
    }

    public final List<InteractStickerStruct> LIZ(Context context, List<? extends StickerItemModel> list, Gson gson) {
        int i;
        List<? extends StickerItemModel> list2 = list;
        M12.LIZ(list2, gson);
        ArrayList arrayList = new ArrayList(LJJIFFI());
        for (C32786Pc r8 : this.LJFF) {
            if (!r8.LJIILIIL) {
                List<TextStickerTextWrap> textWrapList = r8.getTextWrapList();
                n.LIZIZ(textWrapList, "");
                InteractStickerStruct interactStickerStruct = new InteractStickerStruct();
                interactStickerStruct.setType(18);
                LinkedList linkedList = new LinkedList();
                NormalTrackTimeStamp normalTrackTimeStamp = new NormalTrackTimeStamp();
                normalTrackTimeStamp.setRotation(LJIILL.LIZ(r8.getStickerRotate()));
                normalTrackTimeStamp.setScale(Float.valueOf(r8.getStickerScale()));
                Context context2 = context;
                PointF LIZ2 = LIZ(new PointF(r8.getCenterX(), r8.getTextMiddleLineCenterY()), context2);
                normalTrackTimeStamp.setX(LIZ2.x);
                normalTrackTimeStamp.setY(LIZ2.y);
                PointF LIZ3 = LIZ(new PointF((float) r8.getContentViewWidth(), (float) r8.getContentViewHeight()), context2);
                normalTrackTimeStamp.setWidth(LIZ3.x);
                normalTrackTimeStamp.setHeight(LIZ3.y);
                normalTrackTimeStamp.setStartTime((float) r8.LIZ(-1));
                normalTrackTimeStamp.setEndTime((float) r8.LIZIZ(-1));
                linkedList.add(normalTrackTimeStamp);
                C32776Pb.LIZ(interactStickerStruct, linkedList);
                try {
                    interactStickerStruct.setTextStruct(textWrapList.get(0).getText());
                } catch (Exception e) {
                    AnonymousClass6R7.LIZLLL().LIZ((Throwable) e);
                }
                int size = list2.size();
                int i2 = 0;
                while (true) {
                    if (i2 >= size) {
                        break;
                    } else if (((StickerItemModel) list2.get(i2)).viewHash == r8.hashCode()) {
                        interactStickerStruct.setIndex(((StickerItemModel) list2.get(i2)).layerWeight);
                        HashMap hashMap = new HashMap();
                        String str = ((StickerItemModel) list2.get(i2)).stickerId;
                        n.LIZIZ(str, "");
                        hashMap.put("text_sticker_id", str);
                        interactStickerStruct.setAttr(AnonymousClass6R7.LIZIZ().LIZIZ(hashMap));
                        break;
                    } else {
                        i2++;
                    }
                }
                StringBuilder sb = new StringBuilder("#");
                String LIZ4 = 0HH.LIZ("%08x", Arrays.copyOf(new Object[]{Integer.valueOf(r8.LJJI)}, 1));
                n.LIZIZ(LIZ4, "");
                sb.append(LIZ4);
                String sb2 = sb.toString();
                StringBuilder sb3 = new StringBuilder("#");
                String LIZ5 = 0HH.LIZ("%08x", Arrays.copyOf(new Object[]{Integer.valueOf(r8.LJJ)}, 1));
                n.LIZIZ(LIZ5, "");
                sb3.append(LIZ5);
                String sb4 = sb3.toString();
                int i3 = r8.LJIIIIZZ.LIZLLL;
                if (i3 == 1) {
                    i = 1;
                } else if (i3 == 2 || i3 != 3) {
                    i = 0;
                } else {
                    i = 2;
                }
                PointF LIZ6 = LIZ(new PointF(r8.getOriginWidth(), r8.getOriginHeight()), context2);
                interactStickerStruct.setTextInfo(new C43576mp(sb4, sb2, "", LIZ6.x, LIZ6.y, 28, i));
                arrayList.add(interactStickerStruct);
            }
        }
        return arrayList;
    }
}
