package com.bytedance.android.live.slot;

import X.6Is;
import X.AnonymousClass0CB;
import X.AnonymousClass0CH;
import X.AnonymousClass0CN;
import X.AnonymousClass14N;
import X.AnonymousClass14O;
import X.AnonymousClass14P;
import X.AnonymousClass14S;
import X.AnonymousClass2D6;
import X.C13960hO;
import X.C265414a;
import X.C265514b;
import X.C265614c;
import X.C265814e;
import X.C266014g;
import X.C266114h;
import X.C266514l;
import X.C39401hK;
import X.Fv2;
import X.Fv7;
import X.Gbb;
import X.Gc3;
import X.Gpj;
import X.HFD;
import X.HFL;
import X.HFM;
import X.HFN;
import X.HFj;
import X.HFz;
import X.HGo;
import android.content.Context;
import android.os.Bundle;
import android.os.Message;
import android.os.SystemClock;
import com.bytedance.android.live.slot.IFrameSlot;
import com.bytedance.android.live.slot.IIconSlot;
import com.bytedance.android.livesdk.model.AdLiveEnterRoomConfig;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import com.ss.ugc.live.sdk.message.data.IMessage;
import com.ss.ugc.live.sdk.message.interfaces.IMessageManager;
import com.ss.ugc.live.sdk.message.interfaces.OnMessageListener;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.PriorityBlockingQueue;

public class FrameSlotController implements WeakHandler.IHandler, 6Is, OnMessageListener {
    public Map<AnonymousClass14O, C265614c<IFrameSlot, IFrameSlot.SlotViewModel, AnonymousClass14O>> LIZ = new HashMap();
    public Map<AnonymousClass14O, IFrameSlot.SlotViewModel> LIZIZ = new HashMap();
    public Queue<C266114h> LIZJ;
    public WeakHandler LIZLLL = new WeakHandler(this);
    public C39401hK LJ;
    public DataChannel LJFF;
    public IMessageManager LJI;
    public Map<String, Object> LJII = new HashMap();
    public AnonymousClass14P LJIIIIZZ;
    public AnonymousClass14N LJIIIZ;
    public Room LJIIJ;
    public boolean LJIIJJI;
    public C265414a LJIIL = new C265414a() {
        static {
            Covode.recordClassIndex(10572);
        }

        public final boolean LIZ(C265614c<IIconSlot, IIconSlot.SlotViewModel, AnonymousClass14S> r2, IIconSlot.SlotViewModel slotViewModel) {
            return false;
        }

        public final Context LIZ() {
            return FrameSlotController.this.LJ;
        }
    };

    static {
        Covode.recordClassIndex(10571);
    }

    public void onStateChanged(AnonymousClass0CH r2, AnonymousClass0CB r3) {
        if (r3 == AnonymousClass0CB.ON_CREATE) {
            onCreate();
        } else if (r3 == AnonymousClass0CB.ON_RESUME) {
            onResume();
        } else if (r3 == AnonymousClass0CB.ON_START) {
            onStart();
        } else if (r3 == AnonymousClass0CB.ON_PAUSE) {
            onPause();
        } else if (r3 == AnonymousClass0CB.ON_STOP) {
            onStop();
        } else if (r3 == AnonymousClass0CB.ON_DESTROY) {
            onDestroy();
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:7:0x0012  */
    /* JADX WARNING: Removed duplicated region for block: B:9:? A[RETURN, SYNTHETIC] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final java.util.Map<java.lang.String, java.lang.String> LIZ() {
        /*
            r3 = this;
            java.util.Map<java.lang.String, java.lang.Object> r0 = r3.LJII
            java.lang.String r2 = "param_live_show_time"
            java.lang.Object r1 = r0.get(r2)
            boolean r0 = r1 instanceof java.util.Map
            if (r0 == 0) goto L_0x000f
            java.util.Map r1 = (java.util.Map) r1     // Catch:{ Exception -> 0x000f }
            goto L_0x0010
        L_0x000f:
            r1 = 0
        L_0x0010:
            if (r1 != 0) goto L_0x001a
            java.util.HashMap r1 = new java.util.HashMap
            r1.<init>()
            r3.LIZ((java.lang.String) r2, (java.lang.Object) r1)
        L_0x001a:
            return r1
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.android.live.slot.FrameSlotController.LIZ():java.util.Map");
    }

    @AnonymousClass0CN(LIZ = AnonymousClass0CB.ON_PAUSE)
    public void onPause() {
        Queue<C266114h> queue = this.LIZJ;
        if (queue != null) {
            for (C266114h r0 : queue) {
                r0.LIZIZ.LJ();
            }
        }
    }

    @AnonymousClass0CN(LIZ = AnonymousClass0CB.ON_RESUME)
    public void onResume() {
        Queue<C266114h> queue = this.LIZJ;
        if (queue != null) {
            for (C266114h r0 : queue) {
                r0.LIZIZ.LIZLLL();
            }
        }
    }

    @AnonymousClass0CN(LIZ = AnonymousClass0CB.ON_START)
    public void onStart() {
        Queue<C266114h> queue = this.LIZJ;
        if (queue != null) {
            for (C266114h r0 : queue) {
                r0.LIZIZ.LJFF();
            }
        }
    }

    @AnonymousClass0CN(LIZ = AnonymousClass0CB.ON_STOP)
    public void onStop() {
        Queue<C266114h> queue = this.LIZJ;
        if (queue != null) {
            for (C266114h r0 : queue) {
                r0.LIZIZ.LJI();
            }
        }
    }

    private HashMap<String, String> LIZIZ() {
        DataChannel dataChannel = this.LJFF;
        if (dataChannel == null) {
            return new HashMap<>();
        }
        HashMap<String, String> hashMap = (HashMap) dataChannel.LIZIZ(AnonymousClass2D6.class);
        if (hashMap != null) {
            return hashMap;
        }
        HashMap<String, String> hashMap2 = new HashMap<>();
        this.LJFF.LIZ(AnonymousClass2D6.class, hashMap2);
        return hashMap2;
    }

    @AnonymousClass0CN(LIZ = AnonymousClass0CB.ON_CREATE)
    public void onCreate() {
        Queue<C266114h> queue = this.LIZJ;
        if (queue != null) {
            for (C266114h r0 : queue) {
                r0.LIZIZ.LIZ(new Bundle());
            }
        }
    }

    @AnonymousClass0CN(LIZ = AnonymousClass0CB.ON_DESTROY)
    public void onDestroy() {
        IMessageManager iMessageManager = this.LJI;
        if (iMessageManager != null) {
            iMessageManager.removeMessageListener(this);
        }
        this.LIZLLL.removeCallbacksAndMessages((Object) null);
        Queue<C266114h> queue = this.LIZJ;
        if (queue != null) {
            for (C266114h r0 : queue) {
                r0.LIZIZ.LJII();
            }
        }
    }

    public void handleMsg(Message message) {
        if (message.what == 1 && !((C266114h) message.obj).LIZIZ.LIZ()) {
            LIZ(message.obj);
        }
    }

    public void onMessage(IMessage iMessage) {
        Queue<C266114h> queue = this.LIZJ;
        if (queue != null) {
            for (C266114h r1 : queue) {
                if (r1.LIZJ) {
                    r1.LIZIZ.LIZ(iMessage);
                }
            }
        }
    }

    private void LIZ(C266114h r4) {
        if (r4.LIZIZ.LJIIIZ() instanceof IFrameSlot) {
            IFrameSlot.SlotViewModel LIZ2 = IFrameSlot.SlotViewModel.LIZ(r4.LIZIZ, this.LJ);
            this.LJIIIZ.LIZ(r4, LIZ2);
            r4.LIZIZ.LIZ(LIZ2, this.LJIIL);
            r4.LJ = true;
        }
    }

    public final void LIZ(Gc3 gc3) {
        DataChannel provideDataChannel = gc3.provideDataChannel();
        this.LJFF = provideDataChannel;
        if (provideDataChannel != null) {
            this.LJI = (IMessageManager) provideDataChannel.LIZIZ(HGo.class);
            this.LJIIJ = (Room) this.LJFF.LIZIZ(Fv7.class);
            this.LJIIJJI = ((Boolean) this.LJFF.LIZIZ(Fv2.class)).booleanValue();
        }
    }

    public final void LIZ(Object obj) {
        C266114h r5 = (C266114h) obj;
        Iterator it = this.LIZJ.iterator();
        while (it.hasNext()) {
            C266114h r1 = (C266114h) it.next();
            if (r1.LIZLLL && !r1.LIZJ) {
                r1.LIZIZ.LJII();
                it.remove();
            }
        }
        if (r5 != null && r5.LIZJ && !r5.LJ) {
            LIZ(r5);
        }
        Map<String, String> LIZ2 = LIZ();
        StringBuilder sb = new StringBuilder();
        sb.append(SystemClock.uptimeMillis());
        LIZ2.put("PARAM_LIVE_SLOT_ON_CREATE", sb.toString());
    }

    private void LIZ(String str, Object obj) {
        this.LJII.put(str, obj);
    }

    public final void LIZ(C39401hK r8, AnonymousClass14O r9) {
        int i;
        Integer num;
        this.LIZJ = new PriorityBlockingQueue(3, new Comparator<C266114h>() {
            static {
                Covode.recordClassIndex(10573);
            }

            public final /* bridge */ /* synthetic */ int compare(Object obj, Object obj2) {
                return ((C266114h) obj).LIZ - ((C266114h) obj2).LIZ;
            }
        });
        List<C265814e> LIZ2 = C13960hO.LIZ().LIZ(r9);
        if (LIZ2 != null) {
            LIZ("param_live_enter_from_merge", (Object) Gbb.LIZ.LIZ());
            LIZ("param_live_enter_method_merge", (Object) Gbb.LIZ.LIZLLL());
            LIZ("param_live_action_type", (Object) Gbb.LIZ.LJ());
            LIZ("param_live_rec_content_id", (Object) Gbb.LIZ.LJIILL());
            LIZ("param_live_rec_content_type", (Object) Gbb.LIZ.LJIILLIIL());
            LIZ("param_live_begin_time", (Object) Long.valueOf(Gbb.LIZ.LJIJI()));
            LIZ("param_live_begin_time_real", (Object) Long.valueOf(Gbb.LIZ.LJIJJ()));
            DataChannel dataChannel = this.LJFF;
            if (dataChannel != null) {
                LIZ("param_room", dataChannel.LIZIZ(Fv7.class));
                AdLiveEnterRoomConfig LIZIZ2 = Gpj.LIZIZ(this.LJFF);
                if (LIZIZ2 != null) {
                    LIZ("param_effect_ad_extra", (Object) LIZIZ2.LIZ());
                    LIZ("param_effect_ad_id", (Object) LIZIZ2.LJIIIZ);
                }
                LIZ("param_enter_from_effect_ad_bool", this.LJFF.LIZIZ(HFN.class));
                HashMap<String, String> LIZIZ3 = LIZIZ();
                StringBuilder sb = new StringBuilder();
                sb.append(System.currentTimeMillis());
                LIZIZ3.put("param_live_slot_load_time", sb.toString());
                LIZ().putAll(LIZIZ());
                LIZ("param_extra_auto_route_schema", this.LJFF.LIZIZ(HFz.class));
                LIZ("param_extra_auto_open_product_bag", this.LJFF.LIZIZ(HFL.class));
                LIZ("param_extra_opt_auto_route_schema_routing_timing", this.LJFF.LIZIZ(HFM.class));
                LIZ("param_extra_auto_open_product_bag_params", this.LJFF.LIZIZ(HFj.class));
                LIZ("param_extra_ec_common_extra_param", this.LJFF.LIZIZ(HFD.class));
                LIZ("param_search_id", (Object) Gbb.LIZ.LJIIZILJ());
                LIZ("param_search_result_id", (Object) Gbb.LIZ.LJIJ());
            }
            for (C265814e r0 : LIZ2) {
                final C265614c<IFrameSlot, IFrameSlot.SlotViewModel, AnonymousClass14O> LIZ3 = r0.LIZIZ.LIZ((Context) r8, r9);
                if (LIZ3 != null) {
                    final C266114h r4 = new C266114h();
                    AnonymousClass14O LJIIIIZZ2 = LIZ3.LJIIIIZZ();
                    String LJIIJ2 = LIZ3.LJIIJ();
                    Map map = C266014g.LIZIZ.get(LJIIIIZZ2);
                    if (map == null || (num = (Integer) map.get(LJIIJ2)) == null) {
                        i = C266014g.LJ;
                    } else {
                        i = num.intValue();
                    }
                    r4.LIZ = i;
                    r4.LIZIZ = LIZ3;
                    this.LIZJ.offer(r4);
                    if (!(this.LJI == null || LIZ3.LIZJ() == null)) {
                        for (Integer next : LIZ3.LIZJ()) {
                            if (next.intValue() > 0) {
                                this.LJI.addMessageListener(next.intValue(), this);
                            }
                        }
                    }
                    C266514l.LIZ.LIZ("FrameSlotController", LIZ3, "prepareToShow", (Object) this.LJII);
                    LIZ3.LIZ(this.LJII, (C265514b) new C265514b() {
                        static {
                            Covode.recordClassIndex(10574);
                        }

                        public final void LIZ(boolean z) {
                            Map<String, String> LIZ2 = FrameSlotController.this.LIZ();
                            StringBuilder sb = new StringBuilder();
                            sb.append(SystemClock.uptimeMillis());
                            LIZ2.put("param_live_slot_prepare_to_show", sb.toString());
                            r4.LIZ(z);
                            if (LIZ3.LIZ()) {
                                FrameSlotController.this.LIZ((Object) r4);
                                return;
                            }
                            Message obtainMessage = FrameSlotController.this.LIZLLL.obtainMessage(1);
                            obtainMessage.obj = r4;
                            FrameSlotController.this.LIZLLL.sendMessage(obtainMessage);
                        }
                    });
                }
            }
        }
    }

    public FrameSlotController(C39401hK r2, AnonymousClass14N r3, AnonymousClass14P r4) {
        this.LJ = r2;
        this.LJIIIZ = r3;
        this.LJIIIIZZ = r4;
        r3.LIZ(r4);
    }
}
