package com.bytedance.android.live.slot;

import X.6Is;
import X.AnonymousClass0CB;
import X.AnonymousClass0CH;
import X.AnonymousClass0CM;
import X.AnonymousClass14N;
import X.AnonymousClass14P;
import X.C11100cm;
import X.C266114h;
import X.C266214i;
import X.C266514l;
import X.C267314t;
import X.C267414u;
import X.C31351Mn;
import X.FvT;
import X.Gc2;
import X.Gc3;
import X.HFY;
import android.os.Bundle;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Pair;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import com.bytedance.android.live.slot.IFrameSlot;
import com.bytedance.android.livesdkapi.host.IHostAction;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.ies.sdk.widgets.LiveRecyclableWidget;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.PriorityBlockingQueue;

public class FrameSlotWidget extends LiveRecyclableWidget implements AnonymousClass14N, Gc3, WeakHandler.IHandler, 6Is {
    public FrameSlotController LIZ;
    public View LIZIZ;
    public AnonymousClass14P LIZJ;
    public Queue<C266114h> LIZLLL;
    public Map<C266114h, IFrameSlot.SlotViewModel> LJ;
    public boolean LJFF;
    public long LJI;
    public IFrameSlot.SlotViewModel LJII;

    static {
        Covode.recordClassIndex(10575);
    }

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

    public int getLayoutId() {
        return 0;
    }

    public void handleMsg(Message message) {
    }

    public void onStateChanged(AnonymousClass0CH r1, AnonymousClass0CB r2) {
        FrameSlotWidget.super.onStateChanged(r1, r2);
    }

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

    /* JADX WARNING: type inference failed for: r0v3, types: [com.bytedance.android.live.slot.FrameSlotController, X.0CG] */
    public void onUnload() {
        IFrameSlot.SlotViewModel slotViewModel = this.LJII;
        if (slotViewModel != null) {
            slotViewModel.LIZ((AnonymousClass0CH) this);
        }
        Map<C266114h, IFrameSlot.SlotViewModel> map = this.LJ;
        if (map != null) {
            for (IFrameSlot.SlotViewModel LIZ2 : map.values()) {
                LIZ2.LIZ((AnonymousClass0CH) this);
            }
            this.LJ.clear();
        }
        if (this.LIZ != null) {
            getLifecycle().LIZIZ(this.LIZ);
            this.LIZ.onDestroy();
        }
    }

    public final void LIZ(AnonymousClass14P r1) {
        this.LIZJ = r1;
    }

    public void onInit(Object[] objArr) {
        hide();
    }

    public void onLoad(Object[] objArr) {
        if (this.dataChannel.LIZIZ(HFY.class) != null) {
            this.LJI = SystemClock.uptimeMillis();
            this.LIZLLL = new PriorityBlockingQueue(3, new Comparator<C266114h>() {
                static {
                    Covode.recordClassIndex(10576);
                }

                public final /* bridge */ /* synthetic */ int compare(Object obj, Object obj2) {
                    return ((C266114h) obj).LIZ - ((C266114h) obj2).LIZ;
                }
            });
            this.LJ = new HashMap();
            C31351Mn.LIZ.post(new C267314t(this), this);
        }
    }

    /* JADX WARNING: type inference failed for: r3v0, types: [X.0CH, com.bytedance.android.live.slot.FrameSlotWidget] */
    public final void LIZ(final C266114h r4, final IFrameSlot.SlotViewModel slotViewModel) {
        this.LIZLLL.add(r4);
        this.LJ.put(r4, slotViewModel);
        final IFrameSlot iFrameSlot = (IFrameSlot) r4.LIZIZ.LJIIIZ();
        if (this.LIZJ == AnonymousClass14P.LAST) {
            slotViewModel.LIZ.observe(this, new AnonymousClass0CM<Pair<Boolean, String>>() {
                static {
                    Covode.recordClassIndex(10577);
                }

                public final /* synthetic */ void onChanged(Object obj) {
                    MethodCollector.i(1787);
                    Pair pair = (Pair) obj;
                    if (FrameSlotWidget.this.getView() == null || pair == null) {
                        MethodCollector.o(1787);
                        return;
                    }
                    if (Boolean.TRUE.equals(slotViewModel.LIZIZ.getValue()) || Boolean.TRUE.equals(pair.first)) {
                        if (!Boolean.TRUE.equals(slotViewModel.LIZIZ.getValue()) && Boolean.TRUE.equals(pair.first)) {
                            for (Object next : FrameSlotWidget.this.LIZLLL) {
                                IFrameSlot.SlotViewModel slotViewModel = FrameSlotWidget.this.LJ.get(next);
                                if (r4 != next && Boolean.TRUE.equals(slotViewModel.LIZIZ.getValue())) {
                                    slotViewModel.LIZIZ.setValue(false);
                                }
                            }
                            slotViewModel.LIZIZ.setValue(true);
                        }
                        if (Boolean.TRUE.equals(pair.first)) {
                            if (FrameSlotWidget.this.dataChannel != null) {
                                FrameSlotWidget.this.dataChannel.LIZIZ(FvT.class, true);
                            }
                            r4.LIZIZ.LIZ("during_live");
                            FrameSlotWidget.this.show();
                            HashMap hashMap = new HashMap();
                            if (!FrameSlotWidget.this.LJFF) {
                                C266214i.LIZ.LIZ(hashMap, FrameSlotWidget.this.LIZ.LJII, FrameSlotWidget.this.LJI);
                                C266514l.LIZ.LIZ(r4.LIZIZ, (Map<String, String>) hashMap);
                            }
                            FrameSlotWidget.this.LJFF = true;
                            C266514l.LIZ.LIZ("FrameSlotWidget", r4.LIZIZ, "slot visible change, visible: true", (Object) hashMap);
                            if (FrameSlotWidget.this.getView() instanceof ViewGroup) {
                                ((ViewGroup) FrameSlotWidget.this.getView()).removeAllViews();
                            }
                            FrameSlotWidget frameSlotWidget = FrameSlotWidget.this;
                            frameSlotWidget.LIZIZ = iFrameSlot.LIZ(frameSlotWidget.getContext());
                            if (FrameSlotWidget.this.getView() instanceof ViewGroup) {
                                ((ViewGroup) FrameSlotWidget.this.getView()).addView(FrameSlotWidget.this.LIZIZ);
                            }
                            Animation LIZ2 = iFrameSlot.LIZ();
                            if (LIZ2 != null) {
                                FrameSlotWidget.this.LIZIZ.startAnimation(LIZ2);
                                C266514l.LIZ.LIZ("FrameSlotWidget", r4.LIZIZ, "slot start in anim");
                            }
                            if (FrameSlotWidget.this.LIZIZ != null && !FrameSlotWidget.this.LIZIZ.hasOnClickListeners()) {
                                FrameSlotWidget.this.LIZIZ.setOnClickListener(new View.OnClickListener() {
                                    static {
                                        Covode.recordClassIndex(10578);
                                    }

                                    public final void onClick(View view) {
                                        if (!TextUtils.isEmpty((CharSequence) null)) {
                                            C11100cm.LIZ(IHostAction.class).openLiveBrowser((String) null, new Bundle(), FrameSlotWidget.this.getContext());
                                        }
                                    }
                                });
                            }
                            MethodCollector.o(1787);
                            return;
                        } else if (FrameSlotWidget.this.LIZIZ != null) {
                            if (FrameSlotWidget.this.dataChannel != null) {
                                FrameSlotWidget.this.dataChannel.LIZIZ(FvT.class, false);
                            }
                            Animation LIZIZ2 = iFrameSlot.LIZIZ();
                            if (LIZIZ2 == null || "visibility_reason_conflict".equals(pair.second) || "visibility_reason_dispose".equals(pair.second)) {
                                if (FrameSlotWidget.this.getView() instanceof ViewGroup) {
                                    ((ViewGroup) FrameSlotWidget.this.getView()).removeAllViews();
                                }
                                FrameSlotWidget.this.hide();
                                C266514l.LIZ.LIZ("FrameSlotWidget", r4.LIZIZ, "slot visible change, visible: false");
                                MethodCollector.o(1787);
                                return;
                            }
                            LIZIZ2.setAnimationListener(new Animation.AnimationListener() {
                                static {
                                    Covode.recordClassIndex(10579);
                                }

                                public final void onAnimationRepeat(Animation animation) {
                                }

                                public final void onAnimationStart(Animation animation) {
                                }

                                public final void onAnimationEnd(Animation animation) {
                                    View view = FrameSlotWidget.this.getView();
                                    if (view != null) {
                                        view.post(new C267414u(this, view, r4));
                                    }
                                }
                            });
                            FrameSlotWidget.this.LIZIZ.startAnimation(LIZIZ2);
                            C266514l.LIZ.LIZ("FrameSlotWidget", r4.LIZIZ, "slot start end anim");
                        }
                    }
                    MethodCollector.o(1787);
                }
            });
        }
    }
}
