package com.ss.android.ugc.aweme.story.edit.business.shared.effect;

import X.0CB;
import X.0CH;
import X.0CN;
import X.0NG;
import X.2HN;
import X.2Pr;
import X.2sG;
import X.3Ok;
import X.7he;
import X.AnonymousClass4zV;
import X.AnonymousClass54U;
import X.AnonymousClass550;
import X.AnonymousClass562;
import X.AnonymousClass563;
import X.AnonymousClass59Q;
import X.AnonymousClass5B4;
import X.AnonymousClass5BA;
import X.AnonymousClass5BB;
import X.AnonymousClass5BC;
import X.AnonymousClass5BE;
import X.AnonymousClass5FV;
import X.AnonymousClass5LC;
import X.AnonymousClass78T;
import X.C020754z;
import X.C030758v;
import X.C03505Am;
import X.C04875Ft;
import X.C06055Kh;
import X.C12085d8;
import X.C14855hb;
import X.C25195yH;
import X.Crj;
import X.LeS;
import X.LeY;
import X.Ls2;
import X.LsC;
import X.M12;
import X.NrO;
import X.Nwp;
import X.O5i;
import X.O5p;
import X.PMk;
import X.PMp;
import com.bytedance.covode.number.Covode;
import com.bytedance.ui_component.LifecycleAwareViewModel;
import com.ss.android.ugc.aweme.effect.EffectModel;
import com.ss.android.ugc.aweme.effect.EffectPointModel;
import com.ss.android.ugc.aweme.story.edit.clip.impl.VEEditClip;
import com.ss.android.ugc.aweme.story.edit.clip.impl.VEEditClipCluster;
import com.ss.android.ugc.aweme.story.edit.model.StoryEditClipModel;
import com.ss.android.ugc.aweme.story.edit.model.StoryEditModel;
import java.util.ArrayList;
import kotlin.h.b.n;

public final class StoryEditEffectPanelViewModel extends LifecycleAwareViewModel<StoryEditEffectPanelState> implements C06055Kh, AnonymousClass5BE, O5i, AnonymousClass5BA, AnonymousClass5BA {
    public static final /* synthetic */ PMp[] LIZ;
    public final AnonymousClass78T LIZIZ = Nwp.LIZ(getDiContainer(), VEEditClipCluster.class);
    public final AnonymousClass78T LIZJ = Nwp.LIZ(getDiContainer(), StoryEditModel.class);
    public final Crj LIZLLL = 0NG.LIZIZ(this, C14855hb.class);
    public final Crj LJ = 7he.LIZ(AnonymousClass5BC.LIZ);
    public final NrO LJFF;

    public final O5p LIZJ() {
        return (O5p) this.LJ.getValue();
    }

    public final void onStateChanged(0CH r2, 0CB r3) {
        if (r3 == 0CB.ON_DESTROY) {
            onDestroy();
        }
    }

    public final NrO getDiContainer() {
        return this.LJFF;
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    private final void onDestroy() {
        LIZJ().LIZ();
    }

    public final void LIZIZ() {
        LIZJ(AnonymousClass5BB.LIZ);
    }

    public final /* synthetic */ C03505Am dU_() {
        return new StoryEditEffectPanelState((C04875Ft) null, (AnonymousClass5LC) null, 3, (2HN) null);
    }

    public final void cl_() {
        StoryEditEffectPanelViewModel.super.cl_();
        getLifecycle().LIZ(this);
    }

    public final /* synthetic */ AnonymousClass5B4 dW_() {
        return (VEEditClipCluster) this.LIZIZ.LIZ(this, LIZ[0]);
    }

    public final void LJII() {
        ((C14855hb) this.LIZLLL.getValue()).LIZ(new C12085d8(100, "click_panel"));
    }

    static {
        Class<StoryEditEffectPanelViewModel> cls = StoryEditEffectPanelViewModel.class;
        Covode.recordClassIndex(117404);
        LIZ = new PMp[]{new PMk(cls, "clipCluster", "getClipCluster()Lcom/ss/android/ugc/aweme/story/edit/clip/impl/VEEditClipCluster;", 0), new PMk(cls, "editModel", "getEditModel()Lcom/ss/android/ugc/aweme/story/edit/model/StoryEditModel;", 0)};
    }

    public final void LIZLLL() {
        boolean z;
        VEEditClip LIZJ2 = AnonymousClass59Q.LIZJ(this);
        if (LIZJ2 != null) {
            ArrayList<EffectPointModel> effectList = LIZJ2.LJI.getEffectList();
            if (effectList == null || effectList.isEmpty()) {
                z = true;
            } else {
                z = false;
            }
            if ((!z) && effectList != null) {
                AnonymousClass54U.LIZ("StoryEditEffectPanelViewModel.clearEffect", (Ls2<2Pr>) new AnonymousClass550(effectList, LIZJ2));
                C030758v LIZ2 = AnonymousClass59Q.LIZ(LIZJ2);
                if (LIZ2 != null) {
                    AnonymousClass54U.LIZ("StoryEditEffectPanelViewModel.clearEffect", LIZ2, (LsC<? super AnonymousClass4zV, 2Pr>) new C020754z(effectList));
                }
            }
            LIZJ2.LJI.setEffectList((ArrayList<EffectPointModel>) null);
        }
    }

    public StoryEditEffectPanelViewModel(NrO nrO) {
        M12.LIZ(nrO);
        this.LJFF = nrO;
    }

    public final void LIZ(EffectModel effectModel) {
        C030758v LIZ2;
        int i;
        EffectModel effectModel2 = effectModel;
        M12.LIZ(effectModel2);
        VEEditClip LIZJ2 = AnonymousClass59Q.LIZJ(this);
        if (LIZJ2 != null && (LIZ2 = AnonymousClass59Q.LIZ(LIZJ2)) != null) {
            LIZLLL();
            int LJI = LIZ2.LJI();
            2sG r6 = new 2sG();
            r6.element = new int[0];
            3Ok r9 = new 3Ok();
            r9.element = true;
            AnonymousClass54U.LIZ("StoryEditEffectPanelViewModel.selectEffect", (Ls2<2Pr>) new AnonymousClass563(r6, LIZ2, LJI, r9, this, effectModel2));
            if (r9.element) {
                2sG r1 = new 2sG();
                r1.element = "";
                AnonymousClass54U.LIZ("StoryEditEffectPanelViewModel.selectEffect", LIZ2, (LsC<? super AnonymousClass4zV, 2Pr>) new AnonymousClass562(LJI, r1, this, effectModel2));
                EffectPointModel effectPointModel = new EffectPointModel();
                effectPointModel.setName(effectModel2.name);
                effectPointModel.setKey(effectModel2.key);
                effectPointModel.setExtra(effectModel2.extra);
                effectPointModel.setType(effectModel2.type);
                effectPointModel.setCategory(effectModel2.category);
                Integer LIZIZ2 = LeY.LIZIZ((int[]) r6.element, 0);
                if (LIZIZ2 != null) {
                    i = LIZIZ2.intValue();
                } else {
                    i = 0;
                }
                effectPointModel.setIndex(i);
                effectPointModel.setUuid((String) r1.element);
                effectPointModel.setUiStartPoint(0);
                effectPointModel.setUiEndPoint(LJI);
                effectPointModel.setStartPoint(0);
                effectPointModel.setEndPoint(LJI);
                effectPointModel.setFromEnd(false);
                effectPointModel.setSelectedColor(0);
                effectPointModel.setDuration(LJI - 0);
                effectPointModel.setResDir(effectModel2.resDir);
                effectPointModel.setAdjustParams(effectModel2.adjustParams);
                effectPointModel.setIsNewEngineEffect(effectModel2.isNewEngineEffect);
                StoryEditClipModel LIZLLL2 = AnonymousClass59Q.LIZLLL(this);
                if (LIZLLL2 != null) {
                    LIZLLL2.setEffectList(LeS.LIZLLL(new EffectPointModel[]{effectPointModel}));
                }
                StoryEditModel storyEditModel = (StoryEditModel) this.LIZJ.LIZ(this, LIZ[1]);
                String str = effectModel2.name;
                n.LIZIZ(str, "");
                String str2 = effectModel2.key;
                n.LIZIZ(str2, "");
                boolean z = effectModel2.isGoToCapCutEffect;
                M12.LIZ(storyEditModel, str, str2);
                C25195yH.LIZ("effect_click", storyEditModel, new AnonymousClass5FV(str, str2, z));
            }
        }
    }
}
