package com.ss.android.ugc.aweme.ad.feed.mask;

import X.0CB;
import X.0CD;
import X.0CH;
import X.2GO;
import X.2HZ;
import X.2Ic;
import X.2UX;
import X.2nK;
import X.3Ok;
import X.6Is;
import X.7Pb;
import X.BS4;
import X.C0984KOx;
import X.C1567Kek;
import X.C1569Kem;
import X.C1599KfG;
import X.C2261Kpw;
import X.C2366Krd;
import X.C2367Kre;
import X.C2901L0q;
import X.C2902L0r;
import X.C3162LAr;
import X.C3166LAv;
import X.C3402LJx;
import X.C3405LKa;
import X.ISm;
import X.JKX;
import X.KD5;
import X.LDV;
import X.LDW;
import X.LJG;
import X.LK2;
import X.LK3;
import X.LK9;
import X.LKC;
import X.LKK;
import X.LKN;
import X.LKS;
import X.M12;
import X.Rc9;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.ad.FeedAdServiceImpl;
import com.ss.android.ugc.aweme.ad.feed.IFeedAdService;
import com.ss.android.ugc.aweme.ad.preload.AdLandPagePreloadServiceImpl;
import com.ss.android.ugc.aweme.ad.preload.IAdLandPagePreloadService;
import com.ss.android.ugc.aweme.arch.widgets.base.DataCenter;
import com.ss.android.ugc.aweme.commercialize_x.service.CommercializeAdServiceImpl;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.feed.model.AwemeRawAd;
import com.ss.android.ugc.aweme.feed.model.CardStruct;
import java.util.HashMap;
import java.util.Map;
import kotlin.h.b.n;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONObject;

public final class FeedAdLynxMaskContainer implements 6Is, 2HZ, 2GO {
    public static final LKS LJIILJJIL = new LKS((byte) 0);
    public Aweme LIZ;
    public CardStruct LIZIZ;
    public JSONObject LIZJ;
    public C0984KOx LIZLLL;
    public LDV LJ;
    public LDW LJFF;
    public View LJI;
    public LKK LJII;
    public boolean LJIIIIZZ;
    public boolean LJIIIZ;
    public boolean LJIIJ;
    public final C3402LJx LJIIJJI;
    public FrameLayout LJIIL;
    public final String LJIILIIL;
    public AwemeRawAd LJIILL;
    public final LKC LJIILLIIL;
    public C3405LKa LJIIZILJ;
    public final C2261Kpw LJIJ;
    public final C3162LAr LJIJI;

    static {
        Covode.recordClassIndex(52674);
    }

    public final Map<Integer, Object> getSubscriberEventTypes() {
        HashMap hashMap = new HashMap();
        hashMap.put(411, new Rc9(FeedAdLynxMaskContainer.class, "onHideMaskLayoutEvent", C2901L0q.class, ThreadMode.MAIN, 0, false));
        hashMap.put(412, new Rc9(FeedAdLynxMaskContainer.class, "onPopUpPageHideResumeVideoEvent", C2366Krd.class, ThreadMode.MAIN, 0, false));
        hashMap.put(413, new Rc9(FeedAdLynxMaskContainer.class, "onPopUpPageShowHideMaskLayoutEvent", C2367Kre.class, ThreadMode.MAIN, 0, false));
        hashMap.put(414, new Rc9(FeedAdLynxMaskContainer.class, "onCardGetCodeButtonClickedEvent", JKX.class, ThreadMode.MAIN, 0, false));
        hashMap.put(415, new Rc9(FeedAdLynxMaskContainer.class, "onStoryMaskClickEvent", C2902L0r.class, ThreadMode.MAIN, 0, false));
        hashMap.put(416, new Rc9(FeedAdLynxMaskContainer.class, "onLynxConvert", KD5.class, ThreadMode.MAIN, 0, false));
        return hashMap;
    }

    public final void onStateChanged(0CH r1, 0CB r2) {
    }

    public final Bundle LIZ() {
        LJG ljg = LJG.LIZ;
        Aweme aweme = this.LIZ;
        Context context = this.LJIIL.getContext();
        n.LIZIZ(context, "");
        return ljg.LIZ(aweme, context);
    }

    @ISm(LIZ = ThreadMode.MAIN)
    public final void onCardGetCodeButtonClickedEvent(JKX jkx) {
        M12.LIZ((Object) jkx);
        LIZ("gameCodeClicked", (JSONObject) null);
    }

    @ISm(LIZ = ThreadMode.MAIN)
    public final void onLynxConvert(KD5 kd5) {
        M12.LIZ((Object) kd5);
        M12.LIZ((Object) "Lynx view was clicked with convert");
        7Pb.LJ = true;
    }

    @ISm(LIZ = ThreadMode.MAIN)
    public final void onPopUpPageHideResumeVideoEvent(C2366Krd krd) {
        M12.LIZ((Object) krd);
        this.LJIIJJI.LIZLLL();
    }

    @ISm(LIZ = ThreadMode.MAIN)
    public final void onStoryMaskClickEvent(C2902L0r l0r) {
        M12.LIZ((Object) l0r);
        LIZ(l0r.LIZ);
    }

    private final void LIZ(int i) {
        7Pb.LJI.LIZ(i);
        this.LJIIJJI.LIZIZ(false);
        this.LJIIJJI.LIZJ();
    }

    @ISm(LIZ = ThreadMode.MAIN)
    public final void onPopUpPageShowHideMaskLayoutEvent(C2367Kre kre) {
        M12.LIZ((Object) kre);
        this.LJIIJJI.LIZIZ(false);
        DataCenter dataCenter = this.LJIIJJI.LIZ;
        if (dataCenter != null) {
            dataCenter.LIZ("ad_feed_pause_video", (Object) null);
        }
    }

    @ISm(LIZ = ThreadMode.MAIN)
    public final void onHideMaskLayoutEvent(C2901L0q l0q) {
        M12.LIZ((Object) l0q);
        if (l0q.LIZ == this.LJIIL.hashCode()) {
            if (7Pb.LJI.LIZ(this.LIZ)) {
                LIZ(1);
            } else {
                this.LJIIJJI.LIZIZ(true);
            }
        }
    }

    public final void LIZ(Aweme aweme) {
        AwemeRawAd awemeRawAd;
        CardStruct cardStruct;
        String str;
        Map<String, CardStruct> cardInfos;
        this.LIZ = aweme;
        JSONObject jSONObject = null;
        if (aweme != null) {
            awemeRawAd = aweme.getAwemeRawAd();
        } else {
            awemeRawAd = null;
        }
        this.LJIILL = awemeRawAd;
        if (awemeRawAd == null || (cardInfos = awemeRawAd.getCardInfos()) == null) {
            cardStruct = null;
        } else {
            cardStruct = cardInfos.get("5");
        }
        this.LIZIZ = cardStruct;
        if (cardStruct != null) {
            jSONObject = cardStruct.getCardData();
        }
        this.LIZJ = jSONObject;
        if (2Ic.LIZ() && aweme != null) {
            LKK lkk = this.LJII;
            if (lkk != null) {
                lkk.LIZLLL();
            }
            if (!this.LJIIIIZZ) {
                2UX r2 = new 2UX();
                r2.LIZ("is_successful", 0);
                r2.LIZ("is_ever_failed", 0);
                if (C3166LAv.LIZIZ.LIZ().LJIIIIZZ) {
                    str = "1";
                } else {
                    str = "0";
                }
                r2.LIZ("is_spark", str);
                r2.LIZ("failed_reason", 1);
                2nK.LIZ("feed_lynx_mask_preload_usage", r2.LIZ);
            }
        }
    }

    public final void LIZ(String str, JSONObject jSONObject) {
        C1569Kem kitView;
        M12.LIZ((Object) str);
        if (C3166LAv.LIZIZ.LIZ().LJIIIIZZ) {
            FrameLayout frameLayout = this.LJIIL;
            if (!(frameLayout instanceof C1567Kek)) {
                frameLayout = null;
            }
            C1567Kek kek = (C1567Kek) frameLayout;
            if (kek != null && (kitView = kek.getKitView()) != null) {
                kitView.LIZ(str, jSONObject);
                return;
            }
            return;
        }
        C0984KOx kOx = this.LIZLLL;
        if (kOx != null) {
            kOx.onEvent(new LKN(str, jSONObject));
        }
    }

    public FeedAdLynxMaskContainer(C3402LJx lJx, FrameLayout frameLayout, String str) {
        0CD lifecycle;
        FrameLayout frameLayout2;
        LDV ldv;
        LDW ldw;
        String str2;
        String str3;
        C3405LKa lKa;
        LKK lkk;
        M12.LIZ((Object) lJx, (Object) frameLayout);
        this.LJIIJJI = lJx;
        this.LJIIL = frameLayout;
        this.LJIILIIL = str;
        BS4 LIZ2 = CommercializeAdServiceImpl.LIZ().LIZ(17);
        0CH r2 = null;
        LKC lkc = (LKC) (!(LIZ2 instanceof LKC) ? null : LIZ2);
        this.LJIILLIIL = lkc;
        LK9 lk9 = new LK9(this);
        this.LJIJ = lk9;
        LK3 lk3 = new LK3(this);
        this.LJIJI = lk3;
        3Ok r6 = new 3Ok();
        r6.element = false;
        if (2Ic.LIZ()) {
            IFeedAdService LJFF2 = FeedAdServiceImpl.LJFF();
            if (LJFF2 != null) {
                lKa = LJFF2.LIZLLL();
            } else {
                lKa = null;
            }
            this.LJIIZILJ = lKa;
            if (lKa != null) {
                lkk = (LKK) lKa.LIZ(str);
            } else {
                lkk = null;
            }
            this.LJII = lkk;
            if (lkk != null) {
                LK2 lk2 = new LK2(this, r6);
                if (C3166LAv.LIZIZ.LIZ().LJIIIIZZ) {
                    C1567Kek kek = lkk.LJ;
                    if (kek != null && lkk.LIZIZ == 3 && lk2.LIZ(kek)) {
                        this.LJIIIIZZ = true;
                        this.LJIIIZ = lkk.LJII;
                        this.LIZLLL = lkk.LJI;
                        this.LJI = lkk.LJFF;
                        r6.element = true;
                    }
                } else {
                    C1599KfG kfG = lkk.LIZLLL;
                    if (kfG != null && lkk.LIZIZ == 3 && lk2.LIZ(kfG)) {
                        this.LJIIIIZZ = true;
                        this.LJIIIZ = lkk.LJII;
                        this.LIZLLL = lkk.LJI;
                        this.LJI = lkk.LJFF;
                        r6.element = true;
                    }
                }
            }
        }
        if (!this.LJIIIIZZ) {
            FrameLayout frameLayout3 = this.LJIIL;
            if (!(frameLayout3 instanceof C1599KfG)) {
                frameLayout2 = null;
            } else {
                frameLayout2 = frameLayout3;
            }
            C1599KfG kfG2 = (C1599KfG) frameLayout2;
            C1567Kek kek2 = (C1567Kek) (!(frameLayout3 instanceof C1567Kek) ? null : frameLayout3);
            if (lkc != null) {
                IAdLandPagePreloadService LJFF3 = AdLandPagePreloadServiceImpl.LJFF();
                if (LJFF3 != null) {
                    str3 = LJFF3.LJI("lynx_feed");
                } else {
                    str3 = null;
                }
                ldv = lkc.LIZ(kfG2, str3, (C2261Kpw) lk9);
            } else {
                ldv = null;
            }
            this.LJ = ldv;
            if (lkc != null) {
                IAdLandPagePreloadService LJFF4 = AdLandPagePreloadServiceImpl.LJFF();
                if (LJFF4 != null) {
                    str2 = LJFF4.LJI("lynx_feed");
                } else {
                    str2 = null;
                }
                ldw = lkc.LIZ(kek2, str2, (C3162LAr) lk3);
            } else {
                ldw = null;
            }
            this.LJFF = ldw;
        }
        0CH context = this.LJIIL.getContext();
        0CH r22 = context instanceof 0CH ? context : r2;
        if (r22 != null && (lifecycle = r22.getLifecycle()) != null) {
            lifecycle.LIZ(this);
        }
    }
}
