package com.bytedance.android.livesdk.survey.ui.widget;

import X.0CB;
import X.0CD;
import X.0CH;
import X.0yx;
import X.1Mn;
import X.1hK;
import X.2Pr;
import X.6Is;
import X.6iy;
import X.C1064Fv7;
import X.C1430G2l;
import X.C2429Gc2;
import X.C4350HGt;
import X.C4366HHj;
import X.C4724HVd;
import X.C4725HVe;
import X.C4726HVf;
import X.C4727HVg;
import X.C4728HVh;
import X.C4730HVj;
import X.C4732HVl;
import X.C4733HVm;
import X.C4744HVx;
import X.C4745HVy;
import X.C6455Hzs;
import X.DEF;
import X.HFY;
import X.HO0;
import X.HO2;
import X.HVV;
import X.HW0;
import X.HW2;
import X.HW3;
import X.HW7;
import X.HWA;
import X.LeS;
import X.Ls2;
import X.LsD;
import X.M12;
import android.content.Context;
import com.bytedance.android.livesdk.survey.api.SurveyApi;
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.LiveWidget;
import kotlin.h.b.n;

public final class SurveyControlWidget extends LiveWidget implements HW7, 6Is {
    public C4726HVf LIZ;
    public C4733HVm LIZIZ;
    public final LsD<String, Long, 2Pr> LIZJ = new C4732HVl(this);
    public final Ls2<2Pr> LIZLLL = new C4745HVy(this);
    public Room LJ;
    public final SurveyControlWidget$mActivityLifecycleObserver$1 LJFF = new SurveyControlWidget$mActivityLifecycleObserver$1(this);

    static {
        Covode.recordClassIndex(20920);
    }

    public final void LIZ(Throwable th) {
        C2429Gc2.LIZ(this, th);
    }

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

    public final void LIZ() {
        C4726HVf hVf = this.LIZ;
        if (hVf == null) {
            n.LIZ("");
        }
        hVf.LIZ();
    }

    public final void LIZIZ() {
        C4726HVf hVf = this.LIZ;
        if (hVf == null) {
            n.LIZ("");
        }
        hVf.LIZIZ();
    }

    public final void LIZJ() {
        C4726HVf hVf = this.LIZ;
        if (hVf == null) {
            n.LIZ("");
        }
        hVf.LIZJ();
    }

    public final void LIZLLL() {
        C4726HVf hVf = this.LIZ;
        if (hVf == null) {
            n.LIZ("");
        }
        hVf.LIZLLL();
    }

    public final String LJIIL() {
        return getClass().getName();
    }

    public final void onCreate() {
        super.onCreate();
        1Mn.LIZ.post(new HW3(new C4728HVh(this)), this.dataChannel);
    }

    public final void onDestroy() {
        1hK LIZ2;
        0CD lifecycle;
        super.onDestroy();
        C4733HVm hVm = this.LIZIZ;
        if (hVm != null) {
            HWA hwa = hVm.LIZLLL;
            if (hwa != null) {
                hwa.LIZIZ();
            }
            hVm.LIZ.dispose();
        }
        C4733HVm hVm2 = this.LIZIZ;
        if (hVm2 != null) {
            hVm2.f_();
        }
        Context context = this.context;
        if (context != null && (LIZ2 = C1430G2l.LIZ(context)) != null && (lifecycle = LIZ2.getLifecycle()) != null) {
            lifecycle.LIZIZ(this.LJFF);
        }
    }

    public final void LJ() {
        C4733HVm hVm;
        Long l;
        Long l2;
        1hK LIZ2;
        0CD lifecycle;
        long j;
        HWA hwa;
        C4733HVm hVm2;
        if (this.context != null && this.isViewValid) {
            if (this.dataChannel.LIZIZ(C4350HGt.class) != null) {
                hVm = (C4733HVm) this.dataChannel.LIZIZ(C4350HGt.class);
            } else if (this.dataChannel.LIZIZ(HFY.class) != null) {
                hVm = new C4733HVm();
            } else {
                return;
            }
            this.LIZIZ = hVm;
            if (hVm != null) {
                hVm.LIZ(this);
            }
            this.dataChannel.LIZ(C4350HGt.class, this.LIZIZ);
            DataChannel dataChannel = this.dataChannel;
            dataChannel.LIZ((0CH) this, HO2.class, new HVV(this));
            dataChannel.LIZ((0CH) this, HO0.class, new HW0(this));
            Room room = (Room) this.dataChannel.LIZIZ(C1064Fv7.class);
            Room room2 = this.LJ;
            if (room2 != null) {
                l = Long.valueOf(room2.getId());
            } else {
                l = null;
            }
            if (room != null) {
                l2 = Long.valueOf(room.getId());
            } else {
                l2 = null;
            }
            if ((!n.LIZ(l, l2)) && (hVm2 = this.LIZIZ) != null) {
                hVm2.LIZJ = null;
                hVm2.LJ = false;
                hVm2.LJFF = false;
            }
            this.LJ = room;
            Context context = this.context;
            n.LIZIZ(context, "");
            DataChannel dataChannel2 = this.dataChannel;
            n.LIZIZ(dataChannel2, "");
            this.LIZ = new C4726HVf(context, dataChannel2);
            C4733HVm hVm3 = this.LIZIZ;
            if (!(hVm3 == null || (hwa = hVm3.LIZLLL) == null)) {
                hwa.LIZ();
            }
            C4733HVm hVm4 = this.LIZIZ;
            if (hVm4 != null) {
                Long l3 = (Long) this.dataChannel.LIZIZ(HFY.class);
                if (l3 != null) {
                    j = l3.longValue();
                } else {
                    j = 0;
                }
                if (hVm4.LIZJ == null) {
                    if (hVm4.LIZIZ) {
                        C4730HVj hVj = new C4730HVj();
                        hVj.LIZ = "1111";
                        hVj.LIZJ = "thank you";
                        HW2 hw2 = new HW2();
                        hw2.LIZ = 2;
                        hw2.LIZIZ = 2;
                        hw2.LIZJ = 3;
                        hVj.LIZLLL = hw2;
                        C4724HVd hVd = new C4724HVd();
                        hVd.LIZ = "9999";
                        hVd.LIZIZ = "Do you like what you see";
                        C4725HVe hVe = new C4725HVe();
                        hVe.LIZ = 5001;
                        hVe.LIZIZ = "Yes";
                        C4725HVe hVe2 = new C4725HVe();
                        hVe2.LIZ = 5002;
                        hVe2.LIZIZ = "None";
                        C4725HVe hVe3 = new C4725HVe();
                        hVe3.LIZ = 5003;
                        hVe3.LIZIZ = "No";
                        hVd.LIZLLL = LeS.LIZIZ(new C4725HVe[]{hVe, hVe2, hVe3});
                        hVj.LIZIZ = 6iy.LIZ(hVd);
                        hVm4.LIZJ = hVj;
                        hVm4.LIZ(hVm4.LIZJ);
                    } else {
                        hVm4.LIZ.LIZ(((C4366HHj) ((SurveyApi) 0yx.LIZ().LIZ(SurveyApi.class)).list(j).LIZ(new C6455Hzs()).LIZ(DEF.LIZ((0CH) hVm4.LJJIJIIJI))).LIZ(new C4727HVg(hVm4), new C4744HVx(hVm4)));
                    }
                }
            }
            Context context2 = this.context;
            if (context2 != null && (LIZ2 = C1430G2l.LIZ(context2)) != null && (lifecycle = LIZ2.getLifecycle()) != null) {
                lifecycle.LIZ(this.LJFF);
            }
        }
    }

    public final void LIZ(C4730HVj hVj) {
        M12.LIZ(hVj);
        C4726HVf hVf = this.LIZ;
        if (hVf == null) {
            n.LIZ("");
        }
        hVf.LIZ(hVj);
    }
}
