package com.bytedance.android.live.slot;

import X.2cN;
import X.6Is;
import X.AnonymousClass0CB;
import X.AnonymousClass0CH;
import X.AnonymousClass0CM;
import X.AnonymousClass14N;
import X.AnonymousClass14P;
import X.C10000b0;
import X.C11100cm;
import X.C265614c;
import X.C266114h;
import X.C266214i;
import X.C266514l;
import X.C267114r;
import X.C267214s;
import X.C31351Mn;
import X.Fv3;
import X.Fve;
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.datachannel.DataChannel;
import com.bytedance.ies.sdk.widgets.LiveRecyclableWidget;
import java.util.HashMap;
import java.util.Map;

public class FrameL3SlotWidget extends LiveRecyclableWidget implements AnonymousClass14N, Gc3, WeakHandler.IHandler, 6Is {
    public FrameSlotController LIZ;
    public IFrameSlot LIZIZ;
    public IFrameSlot.SlotViewModel LIZJ;
    public View LIZLLL;
    public 2cN LJ;
    public 2cN LJFF;
    public boolean LJI;
    public int LJII;
    public boolean LJIIIIZZ;
    public long LJIIIZ;

    static {
        Covode.recordClassIndex(10565);
    }

    public final void LIZ(AnonymousClass14P r1) {
    }

    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) {
        FrameL3SlotWidget.super.onStateChanged(r1, r2);
    }

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

    public final void LIZ() {
        IFrameSlot.SlotViewModel slotViewModel;
        if (getView() != null && this.LIZLLL != null && (slotViewModel = this.LIZJ) != null && slotViewModel.LIZ.getValue() != null && ((Boolean) this.LIZJ.LIZ.getValue().first).booleanValue()) {
            final boolean z = true;
            if (this.LJII > 1 || this.LJI) {
                z = false;
                hide();
            } else {
                show();
            }
            C266514l.LIZ.LIZ("FrameL3SlotWidget", (C265614c) null, "slot visible change for changeContainerVisibilityDirect, visible: ".concat(String.valueOf(z)));
            this.dataChannel.LIZIZ(Fve.class, Boolean.valueOf(z));
            this.LIZLLL.post(new Runnable() {
                static {
                    Covode.recordClassIndex(10566);
                }

                public final void run() {
                    int i;
                    if (FrameL3SlotWidget.this.dataChannel != null) {
                        DataChannel dataChannel = FrameL3SlotWidget.this.dataChannel;
                        Class<Fv3> cls = Fv3.class;
                        if (z) {
                            i = FrameL3SlotWidget.this.LIZLLL.getHeight();
                        } else {
                            i = 0;
                        }
                        dataChannel.LIZIZ(cls, Integer.valueOf(i));
                    }
                }
            });
        }
    }

    /* JADX WARNING: type inference failed for: r0v9, types: [com.bytedance.android.live.slot.FrameSlotController, X.0CG] */
    public void onUnload() {
        IFrameSlot.SlotViewModel slotViewModel = this.LIZJ;
        if (slotViewModel != null) {
            slotViewModel.LIZ((AnonymousClass0CH) this);
        }
        2cN r0 = this.LJ;
        if (r0 != null) {
            r0.dispose();
        }
        2cN r02 = this.LJFF;
        if (r02 != null) {
            r02.dispose();
        }
        if (this.dataChannel != null) {
            this.dataChannel.LIZIZ(Fve.class, false);
            this.dataChannel.LIZIZ(Fv3.class, 0);
        }
        this.LJI = false;
        this.LJII = 0;
        if (this.LIZ != null) {
            getLifecycle().LIZIZ(this.LIZ);
            this.LIZ.onDestroy();
        }
        if (this.dataChannel != null) {
            this.dataChannel.LIZIZ(Fve.class, false);
            this.dataChannel.LIZIZ(Fv3.class, 0);
            this.dataChannel.LIZIZ(this);
        }
    }

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

    public void onLoad(Object[] objArr) {
        if (this.dataChannel.LIZIZ(HFY.class) != null) {
            this.LJIIIZ = SystemClock.uptimeMillis();
            C31351Mn.LIZ.post(new C267114r(this), this);
        }
    }

    public final void LIZ(int i) {
        if (getView() != null) {
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) getView().getLayoutParams();
            marginLayoutParams.bottomMargin = Math.max(C10000b0.LIZLLL(2131166273), i);
            getView().setLayoutParams(marginLayoutParams);
        }
    }

    /* JADX WARNING: type inference failed for: r3v0, types: [X.0CH, com.bytedance.android.live.slot.FrameL3SlotWidget] */
    public final void LIZ(C266114h r4, IFrameSlot.SlotViewModel slotViewModel) {
        final C265614c r2 = r4.LIZIZ;
        this.LIZIZ = (IFrameSlot) r2.LJIIIZ();
        this.LIZJ = slotViewModel;
        slotViewModel.LIZ.observe(this, new AnonymousClass0CM<Pair<Boolean, String>>() {
            static {
                Covode.recordClassIndex(10567);
            }

            public final /* synthetic */ void onChanged(Object obj) {
                MethodCollector.i(1470);
                Pair pair = (Pair) obj;
                if (FrameL3SlotWidget.this.getView() == null || pair == null) {
                    MethodCollector.o(1470);
                    return;
                }
                if (Boolean.TRUE.equals(pair.first)) {
                    if ((FrameL3SlotWidget.this.getView() instanceof ViewGroup) && (!FrameL3SlotWidget.this.isShowing() || ((ViewGroup) FrameL3SlotWidget.this.getView()).getChildCount() <= 0)) {
                        ((ViewGroup) FrameL3SlotWidget.this.getView()).removeAllViews();
                        FrameL3SlotWidget frameL3SlotWidget = FrameL3SlotWidget.this;
                        frameL3SlotWidget.LIZLLL = frameL3SlotWidget.LIZIZ.LIZ(FrameL3SlotWidget.this.getContext());
                        if (FrameL3SlotWidget.this.LIZLLL != null) {
                            ((ViewGroup) FrameL3SlotWidget.this.getView()).addView(FrameL3SlotWidget.this.LIZLLL);
                            if (FrameL3SlotWidget.this.LJI || FrameL3SlotWidget.this.LJII > 1) {
                                MethodCollector.o(1470);
                                return;
                            }
                            r2.LIZ("during_live");
                            FrameL3SlotWidget.this.show();
                            HashMap hashMap = new HashMap();
                            if (!FrameL3SlotWidget.this.LJIIIIZZ) {
                                C266214i.LIZ.LIZ(hashMap, FrameL3SlotWidget.this.LIZ.LJII, FrameL3SlotWidget.this.LJIIIZ);
                                C266514l.LIZ.LIZ(r2, (Map<String, String>) hashMap);
                            }
                            FrameL3SlotWidget.this.LJIIIIZZ = true;
                            C266514l.LIZ.LIZ("FrameL3SlotWidget", r2, "slot visible change, visible: true", (Object) hashMap);
                            if (FrameL3SlotWidget.this.dataChannel != null) {
                                FrameL3SlotWidget.this.dataChannel.LIZIZ(Fve.class, true);
                            }
                            Animation LIZ2 = FrameL3SlotWidget.this.LIZIZ.LIZ();
                            if (LIZ2 != null) {
                                FrameL3SlotWidget.this.LIZLLL.startAnimation(LIZ2);
                                C266514l.LIZ.LIZ("FrameL3SlotWidget", r2, "slot start in anim");
                            }
                            if (!FrameL3SlotWidget.this.LIZLLL.hasOnClickListeners()) {
                                FrameL3SlotWidget.this.LIZLLL.setOnClickListener(new View.OnClickListener() {
                                    static {
                                        Covode.recordClassIndex(10568);
                                    }

                                    public final void onClick(View view) {
                                        if (!TextUtils.isEmpty((CharSequence) null)) {
                                            C11100cm.LIZ(IHostAction.class).openLiveBrowser((String) null, new Bundle(), FrameL3SlotWidget.this.getContext());
                                        }
                                    }
                                });
                            }
                            FrameL3SlotWidget.this.LIZLLL.post(new Runnable() {
                                static {
                                    Covode.recordClassIndex(10569);
                                }

                                public final void run() {
                                    if (FrameL3SlotWidget.this.dataChannel != null) {
                                        FrameL3SlotWidget.this.dataChannel.LIZIZ(Fv3.class, Integer.valueOf(FrameL3SlotWidget.this.LIZLLL.getHeight()));
                                    }
                                }
                            });
                            MethodCollector.o(1470);
                            return;
                        }
                    }
                } else if (FrameL3SlotWidget.this.isShowing() && FrameL3SlotWidget.this.LIZLLL != null) {
                    Animation LIZIZ2 = FrameL3SlotWidget.this.LIZIZ.LIZIZ();
                    if (LIZIZ2 == null || "visibility_reason_conflict".equals(pair.second) || "visibility_reason_dispose".equals(pair.second)) {
                        if (FrameL3SlotWidget.this.getView() instanceof ViewGroup) {
                            ((ViewGroup) FrameL3SlotWidget.this.getView()).removeAllViews();
                            FrameL3SlotWidget.this.hide();
                            C266514l.LIZ.LIZ("FrameL3SlotWidget", r2, "slot visible change, visible: false");
                        }
                        if (FrameL3SlotWidget.this.dataChannel != null) {
                            FrameL3SlotWidget.this.dataChannel.LIZIZ(Fve.class, false);
                            FrameL3SlotWidget.this.dataChannel.LIZIZ(Fv3.class, 0);
                            MethodCollector.o(1470);
                            return;
                        }
                    } else {
                        LIZIZ2.setAnimationListener(new Animation.AnimationListener() {
                            static {
                                Covode.recordClassIndex(10570);
                            }

                            public final void onAnimationRepeat(Animation animation) {
                            }

                            public final void onAnimationStart(Animation animation) {
                            }

                            public final void onAnimationEnd(Animation animation) {
                                View view = FrameL3SlotWidget.this.getView();
                                if (view != null) {
                                    view.post(new C267214s(this, view, r2));
                                }
                                if (FrameL3SlotWidget.this.dataChannel != null) {
                                    FrameL3SlotWidget.this.dataChannel.LIZIZ(Fve.class, false);
                                    FrameL3SlotWidget.this.dataChannel.LIZIZ(Fv3.class, 0);
                                }
                            }
                        });
                        FrameL3SlotWidget.this.LIZLLL.startAnimation(LIZIZ2);
                        C266514l.LIZ.LIZ("FrameL3SlotWidget", r2, "slot start end anim");
                    }
                }
                MethodCollector.o(1470);
            }
        });
    }
}
