package com.ss.android.ugc.aweme.homepage.ui.view.tab;

import X.0Bt;
import X.0CM;
import X.1hK;
import X.7hc;
import X.7he;
import X.C0295Crj;
import X.C4501Ei1;
import X.C4503Ei3;
import X.C4518EiI;
import X.C4525EiP;
import X.C4916Eoi;
import X.C4987Epr;
import X.Cc3;
import X.EMX;
import X.Lel;
import X.M12;
import X.SzB;
import android.view.View;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.tiktok.homepage.mainfragment.HomeTabAbility;
import com.ss.android.ugc.aweme.homepage.api.interaction.ScrollSwitchStateManager;
import com.ss.android.ugc.aweme.main.TabChangeManager;
import com.ss.android.ugc.aweme.services.IMainService;
import com.ss.android.ugc.aweme.services.MainServiceImpl;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import kotlin.h.b.n;

public final class HomeTabViewModel extends 0Bt implements C4987Epr {
    public static final C4503Ei3 LJ = new C4503Ei3((byte) 0);
    public boolean LIZ;
    public boolean LIZIZ;
    public boolean LIZJ;
    public C4916Eoi LIZLLL;
    public final 1hK LJFF;
    public final HashMap<String, C4525EiP> LJI = new HashMap<>();
    public final HashMap<C4525EiP, View> LJII = new HashMap<>();
    public final C0295Crj LJIIIIZZ;

    static {
        Covode.recordClassIndex(83200);
    }

    public static final synchronized HomeTabViewModel LIZ(1hK r3) {
        HomeTabViewModel LIZ2;
        synchronized (HomeTabViewModel.class) {
            MethodCollector.i(8532);
            LIZ2 = LJ.LIZ(r3);
            MethodCollector.o(8532);
        }
        return LIZ2;
    }

    public final List<C4525EiP> LIZ() {
        return (List) this.LJIIIIZZ.getValue();
    }

    public final boolean LIZIZ() {
        return this.LIZJ;
    }

    public final C4916Eoi LIZJ() {
        return this.LIZLLL;
    }

    public final List<C4525EiP> LIZLLL() {
        List<C4525EiP> LIZ2;
        HomeTabAbility LIZIZ2 = EMX.LIZIZ(SzB.LIZ(this.LJFF, (String) null), HomeTabAbility.class);
        if (LIZIZ2 == null || (LIZ2 = LIZIZ2.LIZ()) == null) {
            return Lel.INSTANCE;
        }
        return LIZ2;
    }

    public final View LJ() {
        int i;
        1hK r1 = this.LJFF;
        if (r1 == null) {
            return null;
        }
        if (C4501Ei1.LIZJ()) {
            i = 2131367519;
        } else {
            i = 2131367528;
        }
        return r1.findViewById(i);
    }

    public final void LIZ(C4916Eoi eoi) {
        this.LIZLLL = eoi;
    }

    public final <T extends View> T LIZIZ(String str) {
        T t = this.LJII.get(this.LJI.get(str));
        if (!(t instanceof View)) {
            t = null;
        }
        return (View) t;
    }

    public final <T extends C4525EiP> T LIZ(String str) {
        M12.LIZ(str);
        T t = this.LJI.get(str);
        if (!(t instanceof C4525EiP)) {
            t = null;
        }
        return (C4525EiP) t;
    }

    public HomeTabViewModel(1hK r4) {
        this.LJIIIIZZ = 7he.LIZ(7hc.SYNCHRONIZED, new C4518EiI(r4));
        if (r4 == null) {
            n.LIZIZ();
        }
        this.LJFF = r4;
        if (C4501Ei1.LIZJ()) {
            ScrollSwitchStateManager LIZ2 = ScrollSwitchStateManager.LJIILL.LIZ(r4);
            AnonymousClass1 r1 = new 0CM(this) {
                public final /* synthetic */ HomeTabViewModel LIZ;

                static {
                    Covode.recordClassIndex(83201);
                }

                {
                    this.LIZ = r1;
                }

                public final /* synthetic */ void onChanged(Object obj) {
                    boolean z;
                    Integer num = (Integer) obj;
                    HomeTabViewModel homeTabViewModel = this.LIZ;
                    if (num != null && num.intValue() == 1) {
                        z = true;
                    } else {
                        z = false;
                    }
                    homeTabViewModel.LIZ = z;
                    HomeTabViewModel homeTabViewModel2 = this.LIZ;
                    n.LIZIZ(num, "");
                    homeTabViewModel2.LIZ(num.intValue(), true);
                }
            };
            M12.LIZ(r4, r1);
            LIZ2.LIZ.observe(r4, r1);
            LIZ2.LIZLLL(r4, new 0CM(this) {
                public final /* synthetic */ HomeTabViewModel LIZ;

                static {
                    Covode.recordClassIndex(83202);
                }

                {
                    this.LIZ = r1;
                }

                public final /* synthetic */ void onChanged(Object obj) {
                    Integer num = (Integer) obj;
                    HomeTabViewModel homeTabViewModel = this.LIZ;
                    boolean z = true;
                    if (num == null || !(num.intValue() == 1 || num.intValue() == 2)) {
                        z = false;
                    }
                    homeTabViewModel.LIZIZ = z;
                }
            });
        }
    }

    public final void LIZ(int i, boolean z) {
        boolean z2;
        if (C4501Ei1.LIZJ()) {
            boolean z3 = false;
            this.LIZJ = false;
            if (this.LIZIZ || z) {
                if (i == 1) {
                    z2 = true;
                } else {
                    z2 = false;
                }
                this.LIZ = z2;
                String str = "HOME";
                if (!(!n.LIZ(TabChangeManager.LJII.LIZ(this.LJFF).LIZLLL, str))) {
                    IMainService createIMainServicebyMonsterPlugin = MainServiceImpl.createIMainServicebyMonsterPlugin(false);
                    1hK r0 = this.LJFF;
                    if (i != 0) {
                        str = "USER";
                    }
                    createIMainServicebyMonsterPlugin.changeStatusBarMainTab(r0, str);
                    if (i == 0) {
                        Cc3.LIZIZ(this.LJFF);
                        C4916Eoi eoi = this.LIZLLL;
                        if (eoi != null) {
                            eoi.LIZ(true);
                        }
                    } else {
                        Cc3.LIZJ(this.LJFF);
                        C4916Eoi eoi2 = this.LIZLLL;
                        if (eoi2 != null) {
                            eoi2.LIZ(false);
                        }
                    }
                    C4916Eoi eoi3 = this.LIZLLL;
                    if (eoi3 != null) {
                        if (i != 0) {
                            z3 = true;
                        }
                        eoi3.LIZ((String) null, Boolean.valueOf(z3));
                    }
                }
            }
        }
    }

    public final void LIZ(C4525EiP eiP, View view) {
        M12.LIZ(view);
        if (eiP != null) {
            Iterator<Map.Entry<C4525EiP, View>> it = this.LJII.entrySet().iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                C4525EiP eiP2 = (C4525EiP) it.next().getKey();
                if (eiP2 != null && n.LIZ(eiP.LJ(), eiP2.LJ())) {
                    it.remove();
                    break;
                }
            }
            this.LJII.put(eiP, view);
        }
    }

    public final void LIZ(String str, C4525EiP eiP) {
        M12.LIZ(str);
        this.LJI.put(str, eiP);
    }
}
