package com.bytedance.android.livesdk.interaction.poll.selectpoll.widget;

import X.0CB;
import X.0CH;
import X.0cm;
import X.1Mg;
import X.2sG;
import X.2tK;
import X.6Is;
import X.C1430G2l;
import X.C2208GWj;
import X.C2213GWo;
import X.C2216GWr;
import X.C2217GWs;
import X.C2474Gcl;
import X.GT5;
import X.GTD;
import X.GTR;
import X.GWE;
import X.GXB;
import android.content.Context;
import android.content.res.Resources;
import android.widget.LinearLayout;
import com.bytedance.android.live.base.model.ImageModel;
import com.bytedance.android.live.gift.IGiftService;
import com.bytedance.android.livesdk.interaction.poll.selectpoll.SelectPollViewModel;
import com.bytedance.android.livesdk.model.Gift;
import com.bytedance.android.livesdk.model.PollData;
import com.bytedance.android.livesdk.model.PollInfo;
import com.bytedance.android.livesdk.model.UserVoteInfo;
import com.bytedance.android.livesdk.model.message.PollMessage;
import com.bytedance.android.livesdk.model.message.PollOptionInfo;
import com.bytedance.android.livesdk.model.message.PollStartContent;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import java.util.List;
import kotlin.h.b.n;

public final class GiftSelectPollWidget extends AbsSelectPollWidget implements 6Is {
    static {
        Covode.recordClassIndex(17246);
    }

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

    public final void onUnload() {
        super.onUnload();
        this.dataChannel.LIZIZ((Object) this);
    }

    public final void show() {
        super.show();
        GT5.LIZLLL = false;
        SelectPollViewModel LJ = LJ();
        if (LJ != null) {
            LJ.LIZ = GTD.GIFT;
        }
    }

    public final void LIZ(long j) {
        GTR.LIZIZ.LIZ(j, this.dataChannel, GTD.GIFT);
    }

    public final void onLoad(Object[] objArr) {
        DataChannel dataChannel;
        Room LJFF;
        PollInfo pollInfo;
        PollData pollData;
        Room LJFF2;
        PollInfo pollInfo2;
        PollData pollData2;
        List<PollOptionInfo> list;
        Room LJFF3;
        PollInfo pollInfo3;
        PollData pollData3;
        Room LJFF4;
        PollInfo pollInfo4;
        UserVoteInfo userVoteInfo;
        2tK<PollMessage> LIZ;
        super.onLoad(objArr);
        this.dataChannel.LIZ((Object) this, C2474Gcl.class, new C2216GWr(this));
        SelectPollViewModel LJ = LJ();
        if (!(LJ == null || (LIZ = LJ.LIZ()) == null)) {
            LIZ.observe(this, new C2217GWs(this));
        }
        Room LJFF5 = LJFF();
        Boolean bool = null;
        if (!(LJFF5 == null || (pollInfo4 = LJFF5.advancedPollInfo) == null || (userVoteInfo = pollInfo4.LIZIZ) == null)) {
            bool = Boolean.valueOf(userVoteInfo.LIZ);
        }
        if (!(!C1430G2l.LIZIZ(bool) || (LJFF = LJFF()) == null || (pollInfo = LJFF.advancedPollInfo) == null || (pollData = pollInfo.LIZ) == null || pollData.LIZ != GTD.GIFT.ordinal() || (LJFF2 = LJFF()) == null || (pollInfo2 = LJFF2.advancedPollInfo) == null || (pollData2 = pollInfo2.LIZ) == null || (list = pollData2.LJFF) == null || list.size() <= 0 || (LJFF3 = LJFF()) == null || (pollInfo3 = LJFF3.advancedPollInfo) == null || (pollData3 = pollInfo3.LIZ) == null || pollData3.LIZJ != 1 || (LJFF4 = LJFF()) == null || !LJFF4.giftPollVoteEnabled)) {
            Room LJFF6 = LJFF();
            if (LJFF6 == null) {
                n.LIZIZ();
            }
            PollInfo pollInfo5 = LJFF6.advancedPollInfo;
            if (pollInfo5 == null) {
                n.LIZIZ();
            }
            PollData pollData4 = pollInfo5.LIZ;
            if (pollData4 == null) {
                n.LIZIZ();
            }
            LIZ(pollData4);
        }
        Room LJFF7 = LJFF();
        if (!(LJFF7 == null || LJFF7.advancedPollInfo == null || (dataChannel = this.dataChannel) == null)) {
            dataChannel.LIZIZ(GXB.class, 1);
        }
        if (this.LJI) {
            this.LIZIZ = new PollStartContent();
            show();
        }
    }

    public final void LIZ(List<PollOptionInfo> list, long j) {
        Gift gift;
        String str;
        ImageModel imageModel;
        Gift gift2;
        Resources resources;
        int i;
        String str2;
        ImageModel imageModel2;
        Gift gift3;
        Resources resources2;
        int i2;
        GiftSelectPollWidget giftSelectPollWidget = this;
        MethodCollector.i(13076);
        List<PollOptionInfo> list2 = list;
        super.LIZ(list2, j);
        if (list2 == null) {
            n.LIZIZ();
        }
        int i3 = 0;
        for (PollOptionInfo next : list2) {
            if (next != null) {
                Context context = giftSelectPollWidget.context;
                n.LIZIZ(context, "");
                1Mg gWo = new C2213GWo(context, (byte) 0);
                int i4 = 1;
                gWo.setCircular(true);
                IGiftService LIZ = 0cm.LIZ(IGiftService.class);
                n.LIZIZ(LIZ, "");
                GWE pollGifts = LIZ.getPollGifts();
                2sG r5 = new 2sG();
                Gift gift4 = null;
                r5.element = null;
                String str3 = "1";
                if (i3 == 0) {
                    if (pollGifts != null) {
                        gift4 = pollGifts.LIZ;
                    }
                    r5.element = gift4;
                    Context context2 = gWo.getContext();
                    if (context2 == null || (resources2 = context2.getResources()) == null) {
                        str2 = null;
                    } else {
                        Gift gift5 = (Gift) r5.element;
                        if (gift5 != null) {
                            i2 = gift5.LJFF;
                        } else {
                            i2 = 1;
                        }
                        Object[] objArr = new Object[1];
                        Gift gift6 = (Gift) r5.element;
                        if (gift6 != null) {
                            i4 = gift6.LJFF;
                        }
                        objArr[0] = Integer.valueOf(i4);
                        str2 = resources2.getQuantityString(2131689745, i2, objArr);
                    }
                    if (pollGifts == null || (gift3 = pollGifts.LIZ) == null) {
                        imageModel2 = null;
                    } else {
                        imageModel2 = gift3.LJJ;
                    }
                    gWo.setGiftImage(imageModel2);
                    if (str2 != null) {
                        str3 = str2;
                    }
                    gWo.setGiftPrice(str3);
                } else {
                    if (pollGifts != null) {
                        gift = pollGifts.LIZIZ;
                    } else {
                        gift = null;
                    }
                    r5.element = gift;
                    Context context3 = gWo.getContext();
                    if (context3 == null || (resources = context3.getResources()) == null) {
                        str = null;
                    } else {
                        Gift gift7 = (Gift) r5.element;
                        if (gift7 != null) {
                            i = gift7.LJFF;
                        } else {
                            i = 1;
                        }
                        Object[] objArr2 = new Object[1];
                        Gift gift8 = (Gift) r5.element;
                        if (gift8 != null) {
                            i4 = gift8.LJFF;
                        }
                        objArr2[0] = Integer.valueOf(i4);
                        str = resources.getQuantityString(2131689745, i, objArr2);
                    }
                    if (pollGifts == null || (gift2 = pollGifts.LIZIZ) == null) {
                        imageModel = null;
                    } else {
                        imageModel = gift2.LJJ;
                    }
                    gWo.setGiftImage(imageModel);
                    if (str != null) {
                        str3 = str;
                    }
                    gWo.setGiftPrice(str3);
                }
                if (!giftSelectPollWidget.LJI) {
                    gWo.setOnClickListener(new C2208GWj(r5, giftSelectPollWidget, i3, next));
                }
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, giftSelectPollWidget.LIZIZ());
                layoutParams.setMarginStart(giftSelectPollWidget.LIZJ());
                layoutParams.setMarginEnd(giftSelectPollWidget.LIZJ());
                giftSelectPollWidget.LIZLLL().addView(gWo, layoutParams);
            }
            i3++;
        }
        MethodCollector.o(13076);
    }
}
