package com.ss.android.ugc.aweme.sticker.types.lock;

import X.07U;
import X.0CB;
import X.0CH;
import X.0CN;
import X.1oX;
import X.2Pr;
import X.6Is;
import X.C0992MiZ;
import X.C2150N2z;
import X.C2170N3t;
import X.C2310N9d;
import X.C2315N9i;
import X.C2320N9n;
import X.FWb;
import X.FZ2;
import X.FsK;
import X.HHi;
import X.IB5;
import X.IFh;
import X.Ibf;
import X.Ls2;
import X.LsC;
import X.M12;
import X.N32;
import X.N9I;
import X.NBS;
import X.NBT;
import X.NDW;
import X.NDX;
import X.NFH;
import X.NI4;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.services.sticker.OnUnlockShareFinishListener;
import com.ss.android.ugc.effectmanager.effect.model.CategoryEffectModel;
import com.ss.android.ugc.effectmanager.effect.model.Effect;
import com.ss.ugc.effectplatform.model.EffectCategoryModel;
import java.util.List;
import kotlin.h.b.n;

public final class LockStickerHandler implements 6Is, N9I, N32 {
    public boolean LIZ;
    public final 1oX LIZIZ;
    public Effect LIZJ;
    public int LIZLLL = -1;
    public boolean LJ;
    public NI4 LJFF;
    public boolean LJI;
    public final OnUnlockShareFinishListener LJII = new NDW(this);
    public final C2310N9d LJIIIIZZ;
    public final LsC<C2320N9n<?>, 2Pr> LJIIIZ;
    public final Ls2<2Pr> LJIIJ;

    static {
        Covode.recordClassIndex(116452);
    }

    public final void LIZ(View view) {
        M12.LIZ(view);
    }

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

    public final void bj_() {
        LIZLLL();
    }

    @0CN(LIZ = 0CB.ON_RESUME)
    public final void onResume() {
        if (this.LIZ) {
            LIZIZ();
        }
    }

    private final void LIZJ() {
        String str;
        NDX LJJIJIIJIL = FWb.LIZIZ.LIZ().LJJIJIIJIL();
        if (this.LJ) {
            str = "click_locked_prop";
        } else {
            str = "click_prop_entrance";
        }
        this.LJFF = LJJIJIIJIL.LIZ(str, this.LIZIZ, this.LIZJ, this.LJII, true);
    }

    public final void LIZIZ() {
        String str;
        NDX LJJIJIIJIL = FWb.LIZIZ.LIZ().LJJIJIIJIL();
        1oX r1 = this.LIZIZ;
        if (this.LJ) {
            str = "click_locked_prop";
        } else {
            str = "click_prop_entrance";
        }
        LJJIJIIJIL.LIZ(r1, str);
        this.LJIIJ.invoke();
        Effect effect = this.LIZJ;
        if (effect != null) {
            this.LJIIIZ.invoke(C2315N9i.LIZ(effect, this.LIZLLL, (FsK) null, (Effect) null, (Bundle) null, (C0992MiZ) null, (Ibf) null, 0, false, 254));
        }
        this.LIZ = false;
        this.LJ = false;
    }

    private final void LIZLLL() {
        List LIZ2;
        if (this.LJI) {
            FZ2 LJJIIJ = FWb.LIZIZ.LIZ().LJJIIJ();
            if (LJJIIJ.LIZIZ() && !TextUtils.isEmpty(LJJIIJ.LIZJ())) {
                07U<Effect, Integer> LIZ3 = LIZ(this.LJIIIIZZ);
                Effect effect = (Effect) LIZ3.LIZ;
                Integer num = (Integer) LIZ3.LIZIZ;
                if (effect != null && (LIZ2 = HHi.LIZ(this.LIZIZ, LJJIIJ.LIZJ())) != null && !LIZ2.isEmpty() && !LIZ2.contains(effect.getEffectId()) && HHi.LIZIZ(effect)) {
                    HHi.LIZ(this.LIZIZ, LJJIIJ.LIZJ(), effect.getEffectId());
                    this.LIZJ = effect;
                    if (num == null) {
                        n.LIZIZ();
                    }
                    this.LIZLLL = num.intValue();
                    LIZJ();
                }
            }
        }
    }

    public final void LIZIZ(C2170N3t n3t) {
        M12.LIZ(n3t);
        this.LJI = false;
    }

    public final void LIZ(C2170N3t n3t) {
        M12.LIZ(n3t);
        this.LJI = true;
        LIZLLL();
    }

    private final 07U<Effect, Integer> LIZ(C2310N9d n9d) {
        List LIZ2 = IB5.LIZ(n9d.LIZJ().LJIIIZ());
        07U<Effect, Integer> r7 = new 07U<>((Object) null, -1);
        if (LIZ2.isEmpty()) {
            return r7;
        }
        int size = LIZ2.size();
        for (int i = 0; i < size; i++) {
            CategoryEffectModel LIZ3 = IB5.LIZ(n9d.LIZJ().LJIIIZ(), ((EffectCategoryModel) LIZ2.get(i)).getKey());
            if (LIZ3 != null) {
                int size2 = LIZ3.getEffects().size();
                for (int i2 = 0; i2 < size2; i2++) {
                    Effect effect = (Effect) LIZ3.getEffects().get(i2);
                    if (NFH.LIZIZ(effect)) {
                        return new 07U<>(effect, Integer.valueOf(i2));
                    }
                }
                continue;
            }
        }
        return r7;
    }

    public final IFh LIZ(NBT nbt, C2150N2z n2z) {
        M12.LIZ(nbt, n2z);
        if (nbt instanceof NBS) {
            NBS nbs = (NBS) nbt;
            if (HHi.LIZIZ(nbs.LIZ)) {
                IFh LIZ2 = n2z.LIZ(nbs.LIZ(nbs.LIZ, nbs.LIZIZ, nbs.LIZJ, nbs.LJ));
                this.LIZJ = nbs.LIZ;
                this.LJ = true;
                LIZJ();
                return LIZ2;
            }
        }
        return n2z.LIZ(nbt);
    }

    public LockStickerHandler(1oX r3, C2310N9d n9d, LsC<? super C2320N9n<?>, 2Pr> lsC, Ls2<2Pr> ls2) {
        M12.LIZ(r3, n9d, lsC, ls2);
        this.LIZIZ = r3;
        this.LJIIIIZZ = n9d;
        this.LJIIIZ = lsC;
        this.LJIIJ = ls2;
        r3.getLifecycle().LIZ(this);
    }
}
