package com.bytedance.android.livesdk.envelope.widget;

import X.0CB;
import X.0CH;
import X.0UO;
import X.0Uo;
import X.0Zf;
import X.0Zi;
import X.0aP;
import X.0b0;
import X.0bQ;
import X.0cm;
import X.158;
import X.1sP;
import X.6Is;
import X.7YE;
import X.7hc;
import X.7he;
import X.C1393G1a;
import X.C1856GIv;
import X.C2099GSe;
import X.C2100GSf;
import X.C2334GaV;
import X.C2336GaX;
import X.C2337GaY;
import X.C2341Gac;
import X.C2343Gae;
import X.C2348Gaj;
import X.C2402Gbb;
import X.C3028Glh;
import X.C3245GpC;
import X.C3491GtA;
import X.C4100H7d;
import X.C4883HaW;
import X.Crj;
import X.CwZ;
import X.GRA;
import X.GRB;
import X.HEP;
import X.HFX;
import X.LWx;
import X.M12;
import android.content.Context;
import android.net.Uri;
import android.widget.LinearLayout;
import com.bytedance.android.live.actionhandler.IActionHandlerService;
import com.bytedance.android.live.base.model.user.FollowInfo;
import com.bytedance.android.live.base.model.user.User;
import com.bytedance.android.live.browser.IBrowserService;
import com.bytedance.android.live.liveinteract.api.IInteractService;
import com.bytedance.android.live.microom.IMicRoomService;
import com.bytedance.android.livesdk.game.model.AccessRecallMessage;
import com.bytedance.android.livesdk.livesetting.hybrid.LynxCardConfig;
import com.bytedance.android.livesdk.livesetting.redenvelope.RedEnvelopeURLConfig;
import com.bytedance.android.livesdk.livesetting.redenvelope.TreasureBoxAnimationImageSetting;
import com.bytedance.android.livesdk.model.Hashtag;
import com.bytedance.android.livesdk.rank.api.IRankService;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import com.bytedance.ies.sdk.datachannel.DataChannelGlobal;
import com.bytedance.ies.sdk.widgets.LiveRecyclableWidget;
import java.util.HashMap;
import java.util.Map;
import kotlin.h.b.n;

public final class RedEnvelopeWidget extends LiveRecyclableWidget implements C2348Gaj, 6Is {
    public static final C2341Gac LIZ = new C2341Gac((byte) 0);
    public 1sP LIZIZ;
    public GRA LIZJ;
    public final Crj LIZLLL = 7he.LIZ(7hc.NONE, C2343Gae.LIZ);
    public boolean LJ;

    static {
        Covode.recordClassIndex(15924);
    }

    public final C2336GaX LIZIZ() {
        return (C2336GaX) this.LIZLLL.getValue();
    }

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

    public final void onPause() {
        super.onPause();
        LIZIZ();
    }

    public final void onResume() {
        super.onResume();
        LIZIZ();
    }

    public final void LIZ() {
        GRA gra = this.LIZJ;
        if (gra != null) {
            gra.LIZ(0);
        }
    }

    public final void onUnload() {
        0Zf hybridDialogManager;
        LIZIZ().LIZ();
        IBrowserService LIZ2 = 0cm.LIZ(IBrowserService.class);
        if (LIZ2 != null && (hybridDialogManager = LIZ2.getHybridDialogManager()) != null) {
            hybridDialogManager.LIZ();
        }
    }

    public final void LIZ(AccessRecallMessage accessRecallMessage) {
        0aP.LIZ(3, "RedEnvelopeWidget", "onPermissionRevoke()");
        if (accessRecallMessage != null) {
            C2100GSf gSf = C2099GSe.LIZIZ;
            Context context = this.context;
            n.LIZIZ(context, "");
            gSf.LIZ(context, "ENVELOPE", accessRecallMessage, new C2334GaV(this, accessRecallMessage));
        }
        GRA gra = this.LIZJ;
        if (gra != null) {
            gra.LIZ(1);
        }
    }

    public final void onInit(Object[] objArr) {
        boolean z;
        Boolean bool = (Boolean) this.dataChannel.LIZIZ(HFX.class);
        if (bool != null) {
            z = bool.booleanValue();
        } else {
            z = false;
        }
        this.LJ = z;
        1sP r2 = new 1sP(this.context);
        this.LIZIZ = r2;
        0bQ.LIZ(r2, "tiktok_live_basic_resource", "ttlive_treasure_box_anim_pic.png");
    }

    public final void onLoad(Object[] objArr) {
        158 r4 = 158.REDENVELOPE;
        DataChannel dataChannel = this.dataChannel;
        DataChannel dataChannel2 = this.dataChannel;
        n.LIZIZ(dataChannel2, "");
        GRA gra = new GRA(dataChannel2);
        this.LIZJ = gra;
        r4.load(dataChannel, gra);
        C2336GaX LIZIZ2 = LIZIZ();
        DataChannel dataChannel3 = this.dataChannel;
        n.LIZIZ(dataChannel3, "");
        LIZIZ2.LIZ(dataChannel3, this);
    }

    public final void LIZ(String str) {
        String str2;
        M12.LIZ(str);
        if (LIZIZ().LIZJ()) {
            0aP.LIZ(3, "RedEnvelopeWidget", "notify envelope data change");
            Map LIZ2 = LWx.LIZ(CwZ.LIZ("update_data", 0UO.LIZIZ.LIZ(str, Map.class)));
            IBrowserService LIZ3 = 0cm.LIZ(IBrowserService.class);
            n.LIZIZ(LIZ3, "");
            0Zi lynxCardViewManager = LIZ3.getLynxCardViewManager();
            String LJ2 = LIZIZ().LJ();
            if (LJ2 == null) {
                n.LIZIZ();
            }
            lynxCardViewManager.LIZ(new 7YE(LJ2, "container_id", LIZ2));
            return;
        }
        0aP.LIZ(3, "RedEnvelopeWidget", "notify envelope data created");
        1sP r6 = null;
        Map map = null;
        for (Map next : TreasureBoxAnimationImageSetting.INSTANCE.getValue()) {
            String str3 = (String) next.get("business_type");
            if (str3 != null && Integer.parseInt(str3) == 1) {
                map = next;
            }
        }
        if (map != null) {
            str2 = (String) map.get("short_touch");
        } else {
            str2 = null;
        }
        Uri build = Uri.parse(str2).buildUpon().appendQueryParameter("initial_data", str).build();
        IBrowserService LIZ4 = 0cm.LIZ(IBrowserService.class);
        n.LIZIZ(LIZ4, "");
        0Zi lynxCardViewManager2 = LIZ4.getLynxCardViewManager();
        Context context = this.context;
        n.LIZIZ(context, "");
        n.LIZIZ(build, "");
        if (this.LJ && (r6 = this.LIZIZ) != null) {
            r6.setLayoutParams(new LinearLayout.LayoutParams(0b0.LIZ((float) LynxCardConfig.INSTANCE.getPreviewWidth()), 0b0.LIZ((float) LynxCardConfig.INSTANCE.getPreviewHeight())));
        }
        lynxCardViewManager2.LIZ(context, new C4883HaW(build, r6, "shortTouchTreasureBox", new C2337GaY(this), true));
    }

    public final void LIZ(GRB grb) {
        String str;
        C3028Glh LIZIZ2;
        0Uo LIZ2;
        String str2;
        String str3;
        FollowInfo followInfo;
        String str4;
        String str5;
        M12.LIZ(grb);
        String sendUrl = RedEnvelopeURLConfig.INSTANCE.getSendUrl();
        String str6 = "1";
        if (sendUrl != null) {
            0aP.LIZ(3, "RedEnvelopeWidget", "openRedEnvelopeCreate: url=".concat(String.valueOf(sendUrl)));
            0aP.LIZ(3, "RedEnvelopeWidget", "openRedEnvelopeCreateDialog: lynxUrl=".concat(String.valueOf(sendUrl)));
            Uri.Builder appendQueryParameter = Uri.parse(sendUrl).buildUpon().appendQueryParameter("enter_from_merge", C2402Gbb.LIZ.LIZ()).appendQueryParameter("enter_method", C2402Gbb.LIZ.LIZLLL());
            if (LIZIZ().LIZIZ()) {
                str4 = str6;
            } else {
                str4 = "0";
            }
            Uri.Builder appendQueryParameter2 = appendQueryParameter.appendQueryParameter("is_anchor", str4).appendQueryParameter("entrance", grb.LIZIZ);
            Room LIZLLL2 = LIZIZ().LIZLLL();
            if (LIZLLL2 == null || (str5 = LIZLLL2.getIdStr()) == null) {
                str5 = "";
            }
            Uri.Builder appendQueryParameter3 = appendQueryParameter2.appendQueryParameter("room_id", str5);
            n.LIZIZ(appendQueryParameter3, "");
            Uri parse = Uri.parse(appendQueryParameter3.toString());
            String queryParameter = parse.getQueryParameter("gravity");
            if (queryParameter == null || queryParameter.length() == 0) {
                parse = parse.buildUpon().appendQueryParameter("gravity", "bottom").build();
            }
            0cm.LIZ(IActionHandlerService.class).handle(this.context, parse);
        } else {
            0aP.LIZ(6, "RedEnvelopeWidget", "openRedEnvelopeCreate: send url is empty");
        }
        boolean LIZIZ3 = LIZIZ().LIZIZ();
        M12.LIZ(grb);
        HashMap hashMap = new HashMap(11);
        hashMap.put("enter_from_merge", C2402Gbb.LIZ.LIZ());
        hashMap.put("enter_method", C2402Gbb.LIZ.LIZLLL());
        hashMap.put("redpacket_type", "coins");
        Room room = (Room) DataChannelGlobal.LIZLLL.LIZIZ(HEP.class);
        if (room != null) {
            String idStr = room.getIdStr();
            if (idStr == null) {
                idStr = String.valueOf(room.getId());
            }
            hashMap.put("room_id", idStr);
            hashMap.put("anchor_id", String.valueOf(room.getOwnerUserId()));
            User owner = room.getOwner();
            if (owner == null || (followInfo = owner.getFollowInfo()) == null || (str2 = String.valueOf(followInfo.getFollowStatus())) == null) {
                str2 = "";
            }
            hashMap.put("follow_status", str2);
            Hashtag hashtag = room.hashtag;
            if (hashtag == null || (str3 = hashtag.title) == null) {
                str3 = "";
            }
            hashMap.put("hashtag_type", str3);
            C1856GIv streamType = room.getStreamType();
            n.LIZIZ(streamType, "");
            hashMap.put("live_type", C1393G1a.LIZ(streamType));
        }
        C4100H7d LIZ3 = C4100H7d.LIZ();
        if (!(LIZ3 == null || (LIZIZ2 = LIZ3.LIZIZ()) == null || (LIZ2 = LIZIZ2.LIZ()) == null)) {
            hashMap.put("user_id", String.valueOf(LIZ2.getId()));
        }
        if (!LIZIZ3) {
            str6 = "0";
        }
        hashMap.put("is_anchor", str6);
        IRankService LIZ4 = 0cm.LIZ(IRankService.class);
        hashMap.put("online_watch_users", String.valueOf(LIZ4.getCurrentRoomAudienceNum()));
        hashMap.put("hourly_ranking", String.valueOf(LIZ4.getCurrentRoomRank(C3245GpC.HOURLY_RANK.getType())));
        String str7 = "normal_video_live";
        if (0cm.LIZ(IMicRoomService.class) != null && 0cm.LIZ(IMicRoomService.class).isMicRoomForCurrentRoom()) {
            str7 = "video_anchor_order";
        } else if (0cm.LIZ(IInteractService.class) != null) {
            IInteractService LIZ5 = 0cm.LIZ(IInteractService.class);
            n.LIZIZ(LIZ5, "");
            if (LIZ5.isBattling()) {
                str7 = "video_anchor_pk";
            } else if (LIZ5.isInCoHost()) {
                str7 = "video_anchor_connect";
            } else if (LIZ5.isInMultiGuest()) {
                str7 = "video_anchor_guest_connect";
            }
        }
        hashMap.put("scene", str7);
        if (n.LIZ(grb.LIZIZ, "gift")) {
            str = "redpacket_panel_click";
        } else {
            str = "redpacket_in_more_click";
        }
        C3491GtA LIZ6 = C3491GtA.LJFF.LIZ(str);
        LIZ6.LIZ((Map<String, String>) hashMap);
        LIZ6.LIZ();
        LIZ6.LJ("live_detail");
        LIZ6.LIZLLL("click");
        LIZ6.LIZJ("live");
        LIZ6.LIZLLL();
    }
}
