package com.bytedance.android.livesdk.interaction.poll.ui;

import X.0b0;
import X.0cm;
import X.0yx;
import X.1Mf;
import X.2sR;
import X.7vl;
import X.C1044Fun;
import X.C1064Fv7;
import X.C1458G3n;
import X.C1781GFy;
import X.C3491GtA;
import X.C6455Hzs;
import X.Crj;
import X.G3E;
import X.G3H;
import X.G4X;
import X.GR9;
import X.GT2;
import X.GT4;
import X.GT5;
import X.GT6;
import X.GT8;
import X.GTC;
import X.GTD;
import X.GTE;
import X.GWE;
import X.HFY;
import X.HGZ;
import X.M12;
import X.Qyn;
import X.Qyq;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.bytedance.android.live.gift.IGiftService;
import com.bytedance.android.live.poll.PollApi;
import com.bytedance.android.livesdk.LiveDialogFragment;
import com.bytedance.android.livesdk.interaction.poll.ui.giftwidget.GiftPollWidget;
import com.bytedance.android.livesdk.interaction.poll.ui.giftwidget.NormalPollWidget;
import com.bytedance.android.livesdk.livesetting.roomfunction.LiveGiftPollDurationSetting;
import com.bytedance.android.livesdk.livesetting.roomfunction.LivePollDurationSetting;
import com.bytedance.android.livesdk.livesetting.roomfunction.LivePollSetting;
import com.bytedance.android.livesdk.model.Gift;
import com.bytedance.android.livesdk.model.RoomAuthStatus;
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.widgets.RecyclableWidgetManager;
import java.util.HashMap;
import java.util.Map;
import kotlin.h.b.n;

public final class PollManageDialog extends LiveDialogFragment implements GTE {
    public String LIZ = "";
    public NormalPollWidget LIZIZ;
    public GiftPollWidget LIZJ;
    public final Crj LIZLLL = 7vl.LIZ(new GR9(this));
    public HashMap LJ;

    static {
        Covode.recordClassIndex(17256);
    }

    private final RecyclableWidgetManager LJ() {
        return (RecyclableWidgetManager) this.LIZLLL.getValue();
    }

    public final View LIZ(int i) {
        if (this.LJ == null) {
            this.LJ = new HashMap();
        }
        View view = (View) this.LJ.get(Integer.valueOf(i));
        if (view != null) {
            return view;
        }
        View view2 = getView();
        if (view2 == null) {
            return null;
        }
        View findViewById = view2.findViewById(i);
        this.LJ.put(Integer.valueOf(i), findViewById);
        return findViewById;
    }

    public final /* synthetic */ void onDestroyView() {
        super.onDestroyView();
        z_();
    }

    public final void z_() {
        HashMap hashMap = this.LJ;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    public final C1044Fun LIZ() {
        C1044Fun fun = new C1044Fun(2131561654);
        fun.LIZIZ = 2131887240;
        fun.LIZ(new ColorDrawable(0));
        fun.LJI = 80;
        fun.LJIIIIZZ = -1;
        fun.LJFF = 0.0f;
        return fun;
    }

    public final G3E LIZLLL() {
        DataChannel dataChannel;
        Room room;
        RoomAuthStatus roomAuthStatus;
        if (LivePollSetting.INSTANCE.enable(this.LJIILIIL) && (dataChannel = this.LJIILIIL) != null && (room = (Room) dataChannel.LIZIZ(C1064Fv7.class)) != null && (roomAuthStatus = room.getRoomAuthStatus()) != null && roomAuthStatus.enableGiftPoll == 1) {
            return G3E.ALL;
        }
        if (LivePollSetting.INSTANCE.enable(this.LJIILIIL)) {
            return G3E.ONLY_NORMAL;
        }
        return G3E.ONLY_GIFT;
    }

    public final void onDismiss(DialogInterface dialogInterface) {
        super.onDismiss(dialogInterface);
    }

    public final void LIZIZ(GTD gtd) {
        long j;
        long millisecond;
        Long l;
        M12.LIZ(gtd);
        DataChannel dataChannel = this.LJIILIIL;
        if (dataChannel == null || (l = (Long) dataChannel.LIZIZ(HFY.class)) == null) {
            j = 0;
        } else {
            j = l.longValue();
        }
        IGiftService LIZ2 = 0cm.LIZ(IGiftService.class);
        n.LIZIZ(LIZ2, "");
        LIZ2.getPollGifts();
        if (gtd == GTD.GIFT) {
            millisecond = LiveGiftPollDurationSetting.INSTANCE.getMillisecond();
        } else {
            millisecond = LivePollDurationSetting.INSTANCE.getMillisecond();
        }
        ((PollApi) 0yx.LIZ().LIZ(PollApi.class)).startPoll(j, LivePollSetting.INSTANCE.getOptionListString(), millisecond, gtd.ordinal()).LIZ(new C6455Hzs()).LIZ(new GT4(this, gtd), G3H.LIZ);
    }

    public final void LIZ(GTD gtd) {
        int i = GTC.LIZ[gtd.ordinal()];
        if (i == 1) {
            2sR<Integer> r1 = C1781GFy.LIZ;
            n.LIZIZ(r1, "");
            r1.LIZ(Integer.valueOf(GTD.NORMAL.ordinal()));
            LJ().unload(this.LIZJ);
            LJ().load(2131368063, this.LIZIZ);
        } else if (i == 2) {
            2sR<Integer> r12 = C1781GFy.LIZ;
            n.LIZIZ(r12, "");
            r12.LIZ(Integer.valueOf(GTD.GIFT.ordinal()));
            LJ().unload(this.LIZIZ);
            LJ().load(2131365346, this.LIZJ);
        }
    }

    public final void onViewCreated(View view, Bundle bundle) {
        String str;
        int i;
        Long l;
        Gift gift;
        Gift gift2;
        TextView textView;
        String str2;
        TextView textView2;
        String str3;
        Resources resources;
        M12.LIZ(view);
        DataChannel dataChannel = this.LJIILIIL;
        if (dataChannel == null || (str = (String) dataChannel.LIZIZ(HGZ.class)) == null) {
            str = "";
        }
        this.LIZ = str;
        super.onViewCreated(view, bundle);
        LIZ(2131371474).setOnClickListener(new GT8(this));
        this.LIZIZ = new NormalPollWidget(this);
        this.LIZJ = new GiftPollWidget(this);
        Qyq newTab = LIZ(2131368637).newTab();
        newTab.LIZ(2131561789);
        View view2 = newTab.LJFF;
        Long l2 = null;
        if (!(view2 == null || (textView2 = (TextView) view2.findViewById(2131370989)) == null)) {
            Context context = getContext();
            if (context == null || (resources = context.getResources()) == null) {
                str3 = null;
            } else {
                str3 = resources.getQuantityString(2131689744, 1);
            }
            textView2.setText(str3);
        }
        n.LIZIZ(newTab, "");
        newTab.LIZ = Integer.valueOf(GTD.GIFT.ordinal());
        Qyq newTab2 = LIZ(2131368637).newTab();
        newTab2.LIZ(2131561789);
        View view3 = newTab2.LJFF;
        if (!(view3 == null || (textView = (TextView) view3.findViewById(2131370989)) == null)) {
            Context context2 = getContext();
            if (context2 != null) {
                str2 = context2.getString(2131829981);
            } else {
                str2 = null;
            }
            textView.setText(str2);
        }
        n.LIZIZ(newTab2, "");
        GTD gtd = GTD.NORMAL;
        newTab2.LIZ = Integer.valueOf(GTD.NORMAL.ordinal());
        LIZ(2131368637).addOnTabSelectedListener(new GT6(this));
        LIZ(2131369206).setOnClickListener(new C1458G3n(this, 0b0.LJ((int) (((float) 0b0.LIZIZ()) * 0.6f)) * 2.0f));
        if (LIZLLL() == G3E.ALL) {
            LIZ(2131368637).addTab(newTab2, false);
            1Mf LIZ2 = LIZ(2131369206);
            n.LIZIZ(LIZ2, "");
            LIZ2.setVisibility(8);
            IGiftService LIZ3 = 0cm.LIZ(IGiftService.class);
            n.LIZIZ(LIZ3, "");
            if (LIZ3.getPollGifts() != null) {
                LIZ(2131368637).addTab(newTab, false);
                1Mf LIZ4 = LIZ(2131369206);
                n.LIZIZ(LIZ4, "");
                LIZ4.setVisibility(0);
            }
            Qyn LIZ5 = LIZ(2131368637);
            n.LIZIZ(LIZ5, "");
            if (LIZ5.getTabCount() <= 1) {
                Qyq tabAt = LIZ(2131368637).getTabAt(0);
                if (tabAt != null) {
                    tabAt.LIZ();
                }
                gtd = GTD.NORMAL;
            } else {
                Qyn LIZ6 = LIZ(2131368637);
                n.LIZIZ(LIZ6, "");
                if (LIZ6.getTabCount() >= 2) {
                    2sR<Integer> r0 = C1781GFy.LIZ;
                    n.LIZIZ(r0, "");
                    Integer num = (Integer) r0.LIZ();
                    int ordinal = GTD.GIFT.ordinal();
                    if (num != null && num.intValue() == ordinal) {
                        Qyq tabAt2 = LIZ(2131368637).getTabAt(GTD.GIFT.ordinal());
                        if (tabAt2 != null) {
                            tabAt2.LIZ();
                        }
                        gtd = GTD.GIFT;
                    }
                }
                Qyn LIZ7 = LIZ(2131368637);
                n.LIZIZ(LIZ7, "");
                if (LIZ7.getTabCount() >= 2) {
                    2sR<Integer> r02 = C1781GFy.LIZ;
                    n.LIZIZ(r02, "");
                    Integer num2 = (Integer) r02.LIZ();
                    int ordinal2 = GTD.NORMAL.ordinal();
                    if (num2 != null && num2.intValue() == ordinal2) {
                        Qyq tabAt3 = LIZ(2131368637).getTabAt(GTD.NORMAL.ordinal());
                        if (tabAt3 != null) {
                            tabAt3.LIZ();
                        }
                        gtd = GTD.NORMAL;
                    }
                }
            }
        } else if (LIZLLL() == G3E.ONLY_NORMAL) {
            LIZ(2131368637).addTab(newTab2, true);
            gtd = GTD.NORMAL;
            1Mf LIZ8 = LIZ(2131369206);
            n.LIZIZ(LIZ8, "");
            LIZ8.setVisibility(8);
        } else {
            LIZ(2131368637).addTab(newTab, true);
            gtd = GTD.GIFT;
            1Mf LIZ9 = LIZ(2131369206);
            n.LIZIZ(LIZ9, "");
            LIZ9.setVisibility(0);
        }
        GT2 gt2 = GT2.LIZ;
        M12.LIZ(gtd);
        HashMap hashMap = new HashMap();
        IGiftService LIZ10 = 0cm.LIZ(IGiftService.class);
        n.LIZIZ(LIZ10, "");
        GWE pollGifts = LIZ10.getPollGifts();
        String str4 = "gift_poll";
        if (G4X.LIZIZ) {
            if (GT5.LIZ == GTD.GIFT) {
                hashMap.put("ongoing_type", str4);
                if (pollGifts == null || (gift2 = pollGifts.LIZ) == null) {
                    l = null;
                } else {
                    l = Long.valueOf(gift2.LIZLLL);
                }
                hashMap.put("gift_1_id", String.valueOf(l));
                if (!(pollGifts == null || (gift = pollGifts.LIZIZ) == null)) {
                    l2 = Long.valueOf(gift.LIZLLL);
                }
                hashMap.put("gift_2_id", String.valueOf(l2));
            } else {
                hashMap.put("ongoing_type", "normal_poll");
            }
            hashMap.put("poll_id", String.valueOf(GT5.LIZIZ));
        }
        C3491GtA LIZ11 = C3491GtA.LJFF.LIZ("livesdk_anchor_poll_panel_show");
        gt2.LIZ(LIZ11);
        LIZ11.LIZ();
        LIZ11.LIZ("is_ongoing", G4X.LIZIZ ? 1 : 0);
        if (gtd != GTD.GIFT) {
            str4 = "normal_poll";
        }
        LIZ11.LIZ("poll_type", str4);
        LIZ11.LIZ((Map<String, String>) hashMap);
        LIZ11.LIZLLL();
        View findViewById = view.findViewById(2131368638);
        n.LIZIZ(findViewById, "");
        ViewGroup.LayoutParams layoutParams = findViewById.getLayoutParams();
        GT5 gt5 = GT5.LJ;
        DataChannel dataChannel2 = this.LJIILIIL;
        if ((gt5.LIZ(dataChannel2, GTD.NORMAL) != null || gt5.LIZ()) && (gt5.LIZ(dataChannel2, GTD.GIFT) != null || gt5.LIZIZ())) {
            i = 0b0.LIZ(294.0f);
        } else {
            i = 0b0.LIZ(375.0f);
        }
        layoutParams.height = i;
        findViewById.setLayoutParams(layoutParams);
    }
}
