package com.debridstream.tv;

import E3.v;
import J4.c;
import R4.g;
import R4.n;
import S4.p;
import S4.w;
import V2.AbstractC0696m3;
import V2.AbstractC0711q1;
import V2.AbstractC0714r1;
import V2.AbstractC0742y1;
import V2.C0645c2;
import V2.C0650d2;
import V2.C0655e2;
import V2.C0695m2;
import V2.C0706p0;
import V2.C0716s;
import V2.C0718s1;
import V2.C0723t2;
import V2.C0726u1;
import V2.C0727u2;
import V2.C0730v1;
import V2.C0734w1;
import V2.C0735w2;
import V2.C0736x;
import V2.C0738x1;
import V2.C0739x2;
import V2.EnumC0722t1;
import V2.F1;
import V2.H2;
import V2.K1;
import V2.O1;
import V2.T1;
import V2.U1;
import V2.W1;
import V2.X1;
import V2.Y1;
import V2.Z1;
import V2.n3;
import V2.u3;
import V2.z3;
import V4.E;
import V4.InterfaceC0765i0;
import Y2.o;
import Y2.r;
import Y4.H;
import Y4.O;
import Y4.a0;
import Y4.c0;
import a.AbstractC0872a;
import android.app.Application;
import android.content.Context;
import androidx.compose.runtime.internal.StabilityInferred;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.X;
import androidx.media3.extractor.text.ttml.TtmlNode;
import b3.f;
import com.debridstream.tv.HomeViewModel;
import com.debridstream.tv.data.home.HomeMetaItem;
import com.google.android.gms.common.internal.ImagesContract;
import e5.a;
import e5.d;
import g3.k;
import i3.M;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import m3.AbstractC2467b;
import n2.AbstractC2612c;
import org.json.JSONObject;
import p0.C2714u;
import q.AbstractC2761L;
import w4.C3137A;
import x4.AbstractC3229F;
import x4.AbstractC3233J;
import x4.AbstractC3250p;
import x4.AbstractC3251q;
import x4.AbstractC3252r;
import x4.AbstractC3253s;
import x4.AbstractC3257w;
import x4.C3224A;
import x4.y;
import z4.C3296a;

/* JADX INFO: loaded from: classes.dex */
@StabilityInferred(parameters = 0)
public final class HomeViewModel extends AndroidViewModel {
    public static final int $stable = 8;
    private final H _heroUiState;
    private final H _kidsHomeState;
    private final H _uiState;
    private String appliedBecauseYouWatchedDepsKey;
    private List<? extends AbstractC0742y1> baseMainCatalogs;
    private List<C0718s1> cachedBecauseYouWatchedEntries;
    private String cachedBecauseYouWatchedKey;
    private List<? extends AbstractC0742y1> configsKidsMain;
    private List<? extends AbstractC0742y1> configsMainList;
    private List<? extends AbstractC0742y1> configsMovies;
    private List<? extends AbstractC0742y1> configsTv;
    private final a0 heroUiState;
    private final a0 kidsHomeState;
    private InterfaceC0765i0 loadJob;
    private final Set<String> loadedKidsMain;
    private final Set<String> loadedMain;
    private final Set<String> loadedMovies;
    private final Set<String> loadedTv;
    private final Set<String> loadingKidsMain;
    private final Set<String> loadingMain;
    private final Set<String> loadingMovies;
    private final Set<String> loadingTv;
    private final o repository;
    private final a sectionLoadMutex;
    private List<? extends AbstractC0742y1> shuffledBaseMainCatalogs;
    private String shuffledBaseMainCatalogsKey;
    private final a0 uiState;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public HomeViewModel(Application application) {
        super(application);
        kotlin.jvm.internal.o.h(application, "application");
        this.repository = new o();
        y yVar = y.f26065a;
        this.baseMainCatalogs = yVar;
        this.shuffledBaseMainCatalogs = yVar;
        this.cachedBecauseYouWatchedEntries = yVar;
        List<AbstractC0742y1> listComputeMainCatalogsWithoutBecause = computeMainCatalogsWithoutBecause((List) ((c0) AbstractC0714r1.f8037b.f8871a).getValue());
        this.configsMainList = listComputeMainCatalogsWithoutBecause;
        this.configsMovies = yVar;
        this.configsTv = yVar;
        this.configsKidsMain = yVar;
        c0 c0VarC = O.c(new MultiTabHomeUiState(shellState(listComputeMainCatalogsWithoutBecause), shellState(this.configsMovies), shellState(this.configsTv)));
        this._uiState = c0VarC;
        this.uiState = c0VarC;
        c0 c0VarC2 = O.c(shellState(this.configsKidsMain));
        this._kidsHomeState = c0VarC2;
        this.kidsHomeState = c0VarC2;
        c0 c0VarC3 = O.c(new HomeTabHeroesUiState(null, null, null, 0L, 0L, 0L, false, 127, null));
        this._heroUiState = c0VarC3;
        this.heroUiState = c0VarC3;
        this.loadedMain = new LinkedHashSet();
        this.loadedMovies = new LinkedHashSet();
        this.loadedTv = new LinkedHashSet();
        this.loadedKidsMain = new LinkedHashSet();
        this.loadingMain = new LinkedHashSet();
        this.loadingMovies = new LinkedHashSet();
        this.loadingTv = new LinkedHashSet();
        this.loadingKidsMain = new LinkedHashSet();
        this.sectionLoadMutex = d.a();
        E.y(X.h(this), null, null, new K1(this, null), 3);
        E.y(X.h(this), null, null, new O1(this, null), 3);
        E.y(X.h(this), null, null, new T1(this, null), 3);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:40:0x0107  */
    /* JADX WARN: Removed duplicated region for block: B:57:0x015c  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0017  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object applyBecauseYouWatchedDependencyChangeIfNeeded(A4.d dVar) throws Throwable {
        X1 x12;
        String strBuildBecauseYouWatchedCacheKey;
        List listD0;
        List<? extends AbstractC0742y1> list;
        HomeViewModel homeViewModel;
        HomeViewModel homeViewModel2;
        List list2;
        List<? extends AbstractC0742y1> list3;
        c0 c0Var;
        Object value;
        c0 c0Var2;
        Object value2;
        MultiTabHomeUiState multiTabHomeUiState;
        HomeUiState main;
        ArrayList arrayList;
        if (dVar instanceof X1) {
            x12 = (X1) dVar;
            int i6 = x12.f7622j;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                x12.f7622j = i6 - Integer.MIN_VALUE;
            } else {
                x12 = new X1(this, dVar);
            }
        }
        Object objAssembleMainCatalogs = x12.f7620e;
        B4.a aVar = B4.a.f492a;
        int i7 = x12.f7622j;
        C3137A c3137a = C3137A.f25453a;
        if (i7 == 0) {
            AbstractC2467b.l(objAssembleMainCatalogs);
            if (!this.baseMainCatalogs.isEmpty()) {
                strBuildBecauseYouWatchedCacheKey = buildBecauseYouWatchedCacheKey();
                if (!kotlin.jvm.internal.o.c(strBuildBecauseYouWatchedCacheKey, this.appliedBecauseYouWatchedDepsKey)) {
                    List<? extends AbstractC0742y1> list4 = this.configsMainList;
                    listD0 = n.d0(n.b0(new g(AbstractC3251q.W(list4), true, W1.f7606a), new C0736x(18)));
                    x12.f7616a = this;
                    x12.f7617b = strBuildBecauseYouWatchedCacheKey;
                    x12.f7618c = list4;
                    x12.f7619d = listD0;
                    x12.f7622j = 1;
                    Object objResolveBecauseYouWatchedCatalogEntries = resolveBecauseYouWatchedCatalogEntries(x12);
                    if (objResolveBecauseYouWatchedCatalogEntries != aVar) {
                        list = list4;
                        objAssembleMainCatalogs = objResolveBecauseYouWatchedCatalogEntries;
                        homeViewModel = this;
                    }
                    return aVar;
                }
            }
            return c3137a;
        }
        if (i7 != 1) {
            if (i7 != 2) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            list2 = x12.f7619d;
            listD0 = x12.f7618c;
            list = (List) x12.f7617b;
            HomeViewModel homeViewModel3 = x12.f7616a;
            AbstractC2467b.l(objAssembleMainCatalogs);
            homeViewModel2 = homeViewModel3;
            list3 = (List) objAssembleMainCatalogs;
            final Set setH0 = AbstractC3251q.H0(list2);
            boolean zSameCatalogIds = homeViewModel2.sameCatalogIds(list3, list);
            int i8 = -1;
            if (!homeViewModel2.sameNonBecauseSectionIdsInOrder(list3, list)) {
                Set<String> setR = AbstractC3233J.r(setH0, AbstractC3251q.H0(listD0));
                homeViewModel2.applyMainCatalogLayoutPreservingStableRows(list3, setR);
                homeViewModel2.filterBecauseYouWatchedItemsInPlace();
                if (!setR.isEmpty()) {
                    Iterator<? extends AbstractC0742y1> it = homeViewModel2.configsMainList.iterator();
                    int i9 = 0;
                    while (true) {
                        if (!it.hasNext()) {
                            break;
                        }
                        if (setR.contains(it.next().a())) {
                            i8 = i9;
                            break;
                        }
                        i9++;
                    }
                    Integer num = new Integer(i8);
                    Integer num2 = num.intValue() >= 0 ? num : null;
                    homeViewModel2.requestSectionsAround(F1.f7316a, num2 != null ? num2.intValue() : 0, 6);
                }
                return c3137a;
            }
            if (!zSameCatalogIds || setH0.isEmpty()) {
                homeViewModel2.configsMainList = list3;
                homeViewModel2.loadedMain.clear();
                homeViewModel2.loadingMain.clear();
                H h5 = homeViewModel2._uiState;
                do {
                    c0Var = (c0) h5;
                    value = c0Var.getValue();
                } while (!c0Var.i(value, MultiTabHomeUiState.copy$default((MultiTabHomeUiState) value, homeViewModel2.shellState(homeViewModel2.configsMainList), null, null, 6, null)));
                homeViewModel2.refreshContinueWatchingFromStore();
                requestSectionsAround$default(homeViewModel2, F1.f7316a, 0, 0, 4, null);
                return c3137a;
            }
            homeViewModel2.configsMainList = list3;
            final int i10 = 0;
            AbstractC3257w.Q(homeViewModel2.loadedMain, new c() { // from class: V2.H1
                @Override // J4.c
                public final Object invoke(Object obj) {
                    switch (i10) {
                        case 0:
                            return Boolean.valueOf(HomeViewModel.applyBecauseYouWatchedDependencyChangeIfNeeded$lambda$30(setH0, (String) obj));
                        default:
                            return Boolean.valueOf(HomeViewModel.applyBecauseYouWatchedDependencyChangeIfNeeded$lambda$31(setH0, (String) obj));
                    }
                }
            });
            final int i11 = 1;
            AbstractC3257w.Q(homeViewModel2.loadingMain, new c() { // from class: V2.H1
                @Override // J4.c
                public final Object invoke(Object obj) {
                    switch (i11) {
                        case 0:
                            return Boolean.valueOf(HomeViewModel.applyBecauseYouWatchedDependencyChangeIfNeeded$lambda$30(setH0, (String) obj));
                        default:
                            return Boolean.valueOf(HomeViewModel.applyBecauseYouWatchedDependencyChangeIfNeeded$lambda$31(setH0, (String) obj));
                    }
                }
            });
            H h6 = homeViewModel2._uiState;
            do {
                c0Var2 = (c0) h6;
                value2 = c0Var2.getValue();
                multiTabHomeUiState = (MultiTabHomeUiState) value2;
                main = multiTabHomeUiState.getMain();
                List<HomeSection> sections = multiTabHomeUiState.getMain().getSections();
                arrayList = new ArrayList(AbstractC3253s.G(sections, 10));
                for (HomeSection homeSectionCopy$default : sections) {
                    if (setH0.contains(homeSectionCopy$default.getId())) {
                        homeSectionCopy$default = HomeSection.copy$default(homeSectionCopy$default, null, null, y.f26065a, 3, null);
                    }
                    arrayList.add(homeSectionCopy$default);
                }
            } while (!c0Var2.i(value2, MultiTabHomeUiState.copy$default(multiTabHomeUiState, HomeUiState.copy$default(main, arrayList, false, null, 6, null), null, null, 6, null)));
            Iterator<? extends AbstractC0742y1> it2 = homeViewModel2.configsMainList.iterator();
            int i12 = 0;
            while (true) {
                if (!it2.hasNext()) {
                    break;
                }
                if (setH0.contains(it2.next().a())) {
                    i8 = i12;
                    break;
                }
                i12++;
            }
            Integer num3 = new Integer(i8);
            Integer num4 = num3.intValue() >= 0 ? num3 : null;
            homeViewModel2.requestSectionsAround(F1.f7316a, num4 != null ? num4.intValue() : 0, 6);
            return c3137a;
        }
        listD0 = x12.f7619d;
        list = x12.f7618c;
        strBuildBecauseYouWatchedCacheKey = (String) x12.f7617b;
        homeViewModel = x12.f7616a;
        AbstractC2467b.l(objAssembleMainCatalogs);
        List<C0718s1> list5 = (List) objAssembleMainCatalogs;
        ArrayList arrayList2 = new ArrayList(AbstractC3253s.G(list5, 10));
        Iterator<T> it3 = list5.iterator();
        while (it3.hasNext()) {
            arrayList2.add(((C0718s1) it3.next()).f8057a);
        }
        if (kotlin.jvm.internal.o.c(listD0, arrayList2)) {
            homeViewModel.appliedBecauseYouWatchedDepsKey = strBuildBecauseYouWatchedCacheKey;
            homeViewModel.configsMainList = homeViewModel.patchBecauseEntriesInConfigs(list, list5);
            homeViewModel.filterBecauseYouWatchedItemsInPlace();
            return c3137a;
        }
        homeViewModel.appliedBecauseYouWatchedDepsKey = strBuildBecauseYouWatchedCacheKey;
        List<? extends Map<String, ? extends Object>> list6 = (List) ((c0) AbstractC0714r1.f8037b.f8871a).getValue();
        x12.f7616a = homeViewModel;
        x12.f7617b = list;
        x12.f7618c = listD0;
        x12.f7619d = arrayList2;
        x12.f7622j = 2;
        objAssembleMainCatalogs = homeViewModel.assembleMainCatalogs(list6, list5, x12);
        if (objAssembleMainCatalogs != aVar) {
            homeViewModel2 = homeViewModel;
            list2 = arrayList2;
            list3 = (List) objAssembleMainCatalogs;
            final Set setH02 = AbstractC3251q.H0(list2);
            boolean zSameCatalogIds2 = homeViewModel2.sameCatalogIds(list3, list);
            int i82 = -1;
            if (!homeViewModel2.sameNonBecauseSectionIdsInOrder(list3, list)) {
            }
        }
        return aVar;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final String applyBecauseYouWatchedDependencyChangeIfNeeded$lambda$26(C0718s1 it) {
        kotlin.jvm.internal.o.h(it, "it");
        return it.f8057a;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final boolean applyBecauseYouWatchedDependencyChangeIfNeeded$lambda$30(Set set, String it) {
        kotlin.jvm.internal.o.h(it, "it");
        return set.contains(it);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final boolean applyBecauseYouWatchedDependencyChangeIfNeeded$lambda$31(Set set, String it) {
        kotlin.jvm.internal.o.h(it, "it");
        return set.contains(it);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object applyCatalogConfigs(C0739x2 c0739x2, A4.d dVar) throws Throwable {
        Y1 y12;
        HomeViewModel homeViewModel;
        HomeViewModel homeViewModel2;
        if (dVar instanceof Y1) {
            y12 = (Y1) dVar;
            int i6 = y12.f7638e;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                y12.f7638e = i6 - Integer.MIN_VALUE;
            } else {
                y12 = new Y1(this, dVar);
            }
        }
        Object objComputeMainCatalogs = y12.f7636c;
        B4.a aVar = B4.a.f492a;
        int i7 = y12.f7638e;
        if (i7 == 0) {
            AbstractC2467b.l(objComputeMainCatalogs);
            if (!c0739x2.f8162a.isEmpty()) {
                this.baseMainCatalogs = c0739x2.f8162a;
                invalidateShuffledBaseMainCatalogs();
            }
            List list = c0739x2.f8163b;
            if (!list.isEmpty()) {
                this.configsMovies = AbstractC0696m3.q(list);
            }
            List list2 = c0739x2.f8164c;
            if (!list2.isEmpty()) {
                this.configsTv = AbstractC0696m3.q(list2);
            }
            List list3 = c0739x2.f8165d;
            if (!list3.isEmpty()) {
                this.configsKidsMain = AbstractC0696m3.q(list3);
            }
            List<? extends Map<String, ? extends Object>> list4 = (List) ((c0) AbstractC0714r1.f8037b.f8871a).getValue();
            y12.f7634a = this;
            y12.f7635b = this;
            y12.f7638e = 1;
            objComputeMainCatalogs = computeMainCatalogs(list4, y12);
            if (objComputeMainCatalogs == aVar) {
                return aVar;
            }
            homeViewModel = this;
            homeViewModel2 = homeViewModel;
        } else {
            if (i7 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            homeViewModel = y12.f7635b;
            homeViewModel2 = y12.f7634a;
            AbstractC2467b.l(objComputeMainCatalogs);
        }
        homeViewModel.configsMainList = (List) objComputeMainCatalogs;
        H h5 = homeViewModel2._uiState;
        MultiTabHomeUiState multiTabHomeUiState = new MultiTabHomeUiState(homeViewModel2.shellState(homeViewModel2.configsMainList), homeViewModel2.shellState(homeViewModel2.configsMovies), homeViewModel2.shellState(homeViewModel2.configsTv));
        c0 c0Var = (c0) h5;
        c0Var.getClass();
        c0Var.k(null, multiTabHomeUiState);
        ((c0) homeViewModel2._kidsHomeState).j(homeViewModel2.shellState(homeViewModel2.configsKidsMain));
        homeViewModel2.refreshKidsContinueWatchingFromStoreIfNeeded();
        homeViewModel2.appliedBecauseYouWatchedDepsKey = homeViewModel2.buildBecauseYouWatchedCacheKey();
        return C3137A.f25453a;
    }

    private final void applyMainCatalogLayoutPreservingStableRows(List<? extends AbstractC0742y1> list, final Set<String> set) {
        c0 c0Var;
        Object value;
        MultiTabHomeUiState multiTabHomeUiState;
        ArrayList arrayList;
        this.configsMainList = list;
        final HashSet hashSet = new HashSet(list.size());
        Iterator<? extends AbstractC0742y1> it = list.iterator();
        while (it.hasNext()) {
            hashSet.add(it.next().a());
        }
        H h5 = this._uiState;
        do {
            c0Var = (c0) h5;
            value = c0Var.getValue();
            multiTabHomeUiState = (MultiTabHomeUiState) value;
            List<HomeSection> sections = multiTabHomeUiState.getMain().getSections();
            int iU = AbstractC3229F.u(AbstractC3253s.G(sections, 10));
            if (iU < 16) {
                iU = 16;
            }
            LinkedHashMap linkedHashMap = new LinkedHashMap(iU);
            for (Object obj : sections) {
                linkedHashMap.put(((HomeSection) obj).getId(), obj);
            }
            arrayList = new ArrayList(AbstractC3253s.G(list, 10));
            for (AbstractC0742y1 abstractC0742y1 : list) {
                HomeSection homeSection = (HomeSection) linkedHashMap.get(abstractC0742y1.a());
                boolean zContains = set.contains(abstractC0742y1.a());
                y yVar = y.f26065a;
                if (zContains) {
                    homeSection = new HomeSection(abstractC0742y1.a(), mainSectionTitle(abstractC0742y1, homeSection != null ? homeSection.getTitle() : null), yVar);
                } else if (homeSection == null) {
                    homeSection = new HomeSection(abstractC0742y1.a(), mainSectionTitle(abstractC0742y1, null), yVar);
                }
                arrayList.add(homeSection);
            }
        } while (!c0Var.i(value, MultiTabHomeUiState.copy$default(multiTabHomeUiState, HomeUiState.copy$default(multiTabHomeUiState.getMain(), arrayList, false, null, 6, null), null, null, 6, null)));
        final int i6 = 0;
        AbstractC3257w.Q(this.loadedMain, new c() { // from class: V2.G1
            @Override // J4.c
            public final Object invoke(Object obj2) {
                String str = (String) obj2;
                switch (i6) {
                    case 0:
                        return Boolean.valueOf(HomeViewModel.applyMainCatalogLayoutPreservingStableRows$lambda$9(hashSet, set, str));
                    default:
                        return Boolean.valueOf(HomeViewModel.applyMainCatalogLayoutPreservingStableRows$lambda$10(hashSet, set, str));
                }
            }
        });
        final int i7 = 1;
        AbstractC3257w.Q(this.loadingMain, new c() { // from class: V2.G1
            @Override // J4.c
            public final Object invoke(Object obj2) {
                String str = (String) obj2;
                switch (i7) {
                    case 0:
                        return Boolean.valueOf(HomeViewModel.applyMainCatalogLayoutPreservingStableRows$lambda$9(hashSet, set, str));
                    default:
                        return Boolean.valueOf(HomeViewModel.applyMainCatalogLayoutPreservingStableRows$lambda$10(hashSet, set, str));
                }
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final boolean applyMainCatalogLayoutPreservingStableRows$lambda$10(HashSet hashSet, Set set, String it) {
        kotlin.jvm.internal.o.h(it, "it");
        return !hashSet.contains(it) || set.contains(it);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final boolean applyMainCatalogLayoutPreservingStableRows$lambda$9(HashSet hashSet, Set set, String it) {
        kotlin.jvm.internal.o.h(it, "it");
        return !hashSet.contains(it) || set.contains(it);
    }

    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:167:0x02b5  */
    /* JADX WARN: Removed duplicated region for block: B:174:0x02d1  */
    /* JADX WARN: Removed duplicated region for block: B:175:0x02d4  */
    /* JADX WARN: Removed duplicated region for block: B:178:0x02ff  */
    /* JADX WARN: Removed duplicated region for block: B:179:0x0310  */
    /* JADX WARN: Removed duplicated region for block: B:204:0x0398  */
    /* JADX WARN: Removed duplicated region for block: B:211:0x03b7  */
    /* JADX WARN: Removed duplicated region for block: B:222:0x03d8  */
    /* JADX WARN: Removed duplicated region for block: B:231:0x03f4  */
    /* JADX WARN: Removed duplicated region for block: B:24:0x0060  */
    /* JADX WARN: Type inference failed for: r1v0 */
    /* JADX WARN: Type inference failed for: r1v1, types: [boolean, int] */
    /* JADX WARN: Type inference failed for: r1v13 */
    /* JADX WARN: Type inference failed for: r5v42, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r5v49 */
    /* JADX WARN: Type inference failed for: r5v50 */
    /* JADX WARN: Type inference failed for: r5v51 */
    /* JADX WARN: Type inference failed for: r8v22 */
    /* JADX WARN: Type inference failed for: r8v23, types: [int] */
    /* JADX WARN: Type inference failed for: r8v25 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private final List<AbstractC0742y1> assembleMainCatalogEntries(List<? extends Map<String, ? extends Object>> catalogs, List<C0718s1> list) {
        int size;
        int i6;
        List listY0;
        int i7;
        String lowerCase;
        String lowerCase2;
        String str;
        String string;
        Iterator it;
        String string2;
        String string3;
        String string4;
        ArrayList arrayList;
        String string5;
        String str2;
        String strConcat;
        String strConcat2;
        AbstractC0742y1 c0734w1;
        String strA;
        ?? X02;
        String string6;
        String string7;
        String string8;
        ?? r12 = 0;
        int i8 = 1;
        TimeZone timeZone = AbstractC0711q1.f8021a;
        kotlin.jvm.internal.o.h(catalogs, "catalogs");
        ArrayList arrayList2 = new ArrayList();
        Iterator it2 = catalogs.iterator();
        while (it2.hasNext()) {
            Map map = (Map) it2.next();
            Object obj = map.get("type");
            String str3 = obj instanceof String ? (String) obj : null;
            if (str3 != null) {
                lowerCase = str3.toLowerCase(Locale.ROOT);
                kotlin.jvm.internal.o.g(lowerCase, "toLowerCase(...)");
            } else {
                lowerCase = null;
            }
            Object obj2 = map.get("itemKey");
            String string9 = (obj2 == null || (string8 = obj2.toString()) == null) ? null : p.o1(string8).toString();
            Object objSubSequence = "";
            if (string9 == null) {
                string9 = "";
            }
            if (string9.length() != 0) {
                Object obj3 = map.get("title");
                String string10 = (obj3 == null || (string7 = obj3.toString()) == null) ? null : p.o1(string7).toString();
                String str4 = string10 == null ? "" : string10;
                if (str4.length() != 0) {
                    if (kotlin.jvm.internal.o.c(lowerCase, "trakt")) {
                        Object obj4 = map.get(ImagesContract.URL);
                        String string11 = (obj4 == null || (string6 = obj4.toString()) == null) ? null : p.o1(string6).toString();
                        if (string11 == null) {
                            string11 = "";
                        }
                        if (string11.length() == 0) {
                            arrayList = arrayList2;
                            it = it2;
                            c0734w1 = null;
                        } else {
                            String string12 = p.o1(string11).toString();
                            int iO0 = p.O0(string12, "/users/", r12, r12, 6);
                            if (iO0 >= 0) {
                                String strSubstring = string12.substring(iO0 + 7);
                                kotlin.jvm.internal.o.g(strSubstring, "substring(...)");
                                X02 = strSubstring;
                            } else {
                                boolean zA0 = w.A0(string12, "users/", r12);
                                X02 = string12;
                                if (zA0) {
                                    X02 = p.X0(string12, "users/");
                                }
                            }
                            char[] cArr = new char[i8];
                            cArr[r12] = '/';
                            int length = X02.length();
                            ?? r8 = r12;
                            while (true) {
                                if (r8 < length) {
                                    if (AbstractC3250p.t(cArr, X02.charAt(r8))) {
                                        r8 += i8;
                                    } else {
                                        objSubSequence = X02.subSequence(r8, X02.length());
                                    }
                                }
                            }
                            arrayList = arrayList2;
                            it = it2;
                            c0734w1 = new C0738x1("custom-".concat(string9), str4, objSubSequence.toString(), "random", null, null, false);
                        }
                    } else {
                        Object obj5 = map.get("videoType");
                        String str5 = obj5 instanceof String ? (String) obj5 : null;
                        if (str5 != null) {
                            lowerCase2 = str5.toLowerCase(Locale.ROOT);
                            kotlin.jvm.internal.o.g(lowerCase2, "toLowerCase(...)");
                        } else {
                            lowerCase2 = "movie";
                        }
                        String str6 = lowerCase2.equals("tv") ? "tv" : "movie";
                        Object obj6 = map.get("with_watch_providers");
                        if (kotlin.jvm.internal.o.c(obj6 instanceof String ? (String) obj6 : null, TtmlNode.COMBINE_ALL)) {
                            str = "&with_watch_monetization_types=flatrate|free|ads|rent|buy";
                        } else {
                            Object obj7 = map.get("with_watch_providers");
                            if (obj7 == null) {
                                obj7 = "";
                            }
                            str = "&with_watch_providers=" + obj7;
                        }
                        TimeZone timeZone2 = AbstractC0711q1.f8021a;
                        Calendar calendar = Calendar.getInstance(timeZone2);
                        kotlin.jvm.internal.o.g(calendar, "getInstance(...)");
                        String strA2 = AbstractC0711q1.a(calendar);
                        Object obj8 = map.get("vCount");
                        if (obj8 == null || (string = obj8.toString()) == null) {
                            string = "0";
                        }
                        it = it2;
                        Object obj9 = map.get("rCount");
                        if (obj9 == null || (string2 = obj9.toString()) == null) {
                            string2 = "0";
                        }
                        Object obj10 = map.get("sort_by");
                        if (obj10 == null || (string3 = obj10.toString()) == null) {
                            string3 = "primary_release_date.desc";
                        }
                        Object obj11 = map.get("with_original_language");
                        if (obj11 == null || (string4 = obj11.toString()) == null) {
                            string4 = "en";
                        }
                        arrayList = arrayList2;
                        Object obj12 = map.get("watch_region");
                        if (obj12 == null || (string5 = obj12.toString()) == null) {
                            string5 = "US";
                        }
                        String str7 = str4;
                        Object obj13 = map.get("genre");
                        String string13 = obj13 != null ? obj13.toString() : null;
                        if (string13 == null || p.Q0(string13) || string13.equals(TtmlNode.COMBINE_ALL)) {
                            str2 = string9;
                            strConcat = "";
                        } else {
                            str2 = string9;
                            boolean z6 = false;
                            if (w.A0(string13, "|", false)) {
                                string13 = p.G0(1, string13);
                                z6 = false;
                            }
                            if (w.s0(string13, "|", z6)) {
                                string13 = p.H0(string13);
                            }
                            strConcat = "&with_genres=".concat(string13);
                        }
                        Object obj14 = map.get("timeFrame");
                        String string14 = obj14 != null ? obj14.toString() : null;
                        if (string14 == null || p.Q0(string14) || string14.equals("any")) {
                            strConcat2 = "";
                            String str8 = !str6.equals("tv") ? "first_air_date" : "primary_release_date";
                            StringBuilder sbI = AbstractC2761L.i("discover/", str6, "?include_adult=false&include_video=false&language=en-US&vote_count.gte=", string, "&vote_average.gte=");
                            A0.a.w(sbI, string2, "&page=1&", str8, ".lte=");
                            A0.a.w(sbI, strA2, "&sort_by=", string3, "&with_original_language=");
                            A0.a.w(sbI, string4, str, "&watch_region=", string5);
                            String strN = com.google.android.recaptcha.internal.a.n(sbI, strConcat, strConcat2);
                            c0734w1 = !lowerCase2.equals("tv") ? new C0734w1("custom-".concat(str2), str7, strN, false) : new C0730v1("custom-".concat(str2), str7, strN, false);
                        } else {
                            Calendar calendar2 = Calendar.getInstance(timeZone2);
                            String lowerCase3 = string14.toLowerCase(Locale.ROOT);
                            kotlin.jvm.internal.o.g(lowerCase3, "toLowerCase(...)");
                            switch (lowerCase3.hashCode()) {
                                case -1335730848:
                                    if (lowerCase3.equals("decade")) {
                                        calendar2.add(1, -10);
                                        strA = AbstractC0711q1.a(calendar2);
                                    } else {
                                        strA = "";
                                    }
                                    break;
                                case 3645428:
                                    if (lowerCase3.equals("week")) {
                                        calendar2.add(6, -7);
                                        strA = AbstractC0711q1.a(calendar2);
                                    } else {
                                        strA = "";
                                    }
                                    break;
                                case 3704893:
                                    if (lowerCase3.equals("year")) {
                                        calendar2.add(1, -1);
                                        strA = AbstractC0711q1.a(calendar2);
                                    } else {
                                        strA = "";
                                    }
                                    break;
                                case 104080000:
                                    if (lowerCase3.equals("month")) {
                                        calendar2.add(2, -1);
                                        strA = AbstractC0711q1.a(calendar2);
                                    } else {
                                        strA = "";
                                    }
                                    break;
                                default:
                                    strA = "";
                                    break;
                            }
                            if (strA.length() != 0) {
                                strConcat2 = lowerCase2.equals("tv") ? "&first_air_date.gte=".concat(strA) : "&primary_release_date.gte=".concat(strA);
                            }
                            if (!str6.equals("tv")) {
                            }
                            StringBuilder sbI2 = AbstractC2761L.i("discover/", str6, "?include_adult=false&include_video=false&language=en-US&vote_count.gte=", string, "&vote_average.gte=");
                            A0.a.w(sbI2, string2, "&page=1&", str8, ".lte=");
                            A0.a.w(sbI2, strA2, "&sort_by=", string3, "&with_original_language=");
                            A0.a.w(sbI2, string4, str, "&watch_region=", string5);
                            String strN2 = com.google.android.recaptcha.internal.a.n(sbI2, strConcat, strConcat2);
                            if (!lowerCase2.equals("tv")) {
                            }
                        }
                    }
                }
            }
            ArrayList arrayList3 = arrayList;
            if (c0734w1 != null) {
                arrayList3.add(c0734w1);
            }
            arrayList2 = arrayList3;
            it2 = it;
            r12 = 0;
            i8 = 1;
        }
        ArrayList<AbstractC0742y1> arrayList4 = arrayList2;
        int iCountLeadingInPlacePrefix = countLeadingInPlacePrefix(this.baseMainCatalogs);
        int size2 = list.size();
        if (size2 > 3) {
            size2 = 3;
        }
        List<AbstractC0742y1> listOrderedBaseMainCatalogs = orderedBaseMainCatalogs();
        while (listOrderedBaseMainCatalogs.size() + arrayList4.size() + 1 + size2 > 20 && !listOrderedBaseMainCatalogs.isEmpty()) {
            listOrderedBaseMainCatalogs = AbstractC3251q.b0(listOrderedBaseMainCatalogs);
        }
        int size3 = listOrderedBaseMainCatalogs.size();
        if (iCountLeadingInPlacePrefix > size3) {
            iCountLeadingInPlacePrefix = size3;
        }
        ArrayList arrayList5 = new ArrayList(20);
        arrayList5.add(C0726u1.f8101a);
        for (AbstractC0742y1 abstractC0742y1 : arrayList4) {
            if (listOrderedBaseMainCatalogs.size() + arrayList5.size() + size2 >= 20) {
                size = listOrderedBaseMainCatalogs.size();
                for (i6 = 0; i6 < size; i6++) {
                    if (arrayList5.size() < 20) {
                        arrayList5.add(listOrderedBaseMainCatalogs.get(i6));
                    }
                }
                listY0 = AbstractC3251q.y0(list, 3);
                if (!listY0.isEmpty()) {
                    int size4 = (arrayList5.size() - 1) - listOrderedBaseMainCatalogs.size();
                    if (size4 < 0) {
                        size4 = 0;
                    }
                    int i9 = size4 + 1 + iCountLeadingInPlacePrefix;
                    if (i9 <= arrayList5.size()) {
                        int size5 = listY0.size();
                        if (size5 != 1) {
                            if (size5 == 2) {
                                if (arrayList5.size() < i9 + 4) {
                                    if (arrayList5.size() >= i9) {
                                    }
                                }
                                i7 = 2;
                            } else if (size5 == 3) {
                                if (arrayList5.size() >= i9 + 7) {
                                    i7 = 3;
                                } else {
                                    if (arrayList5.size() < i9 + 4) {
                                        i7 = arrayList5.size() >= i9 ? 1 : 0;
                                    }
                                    i7 = 2;
                                }
                            }
                        } else if (arrayList5.size() >= i9) {
                        }
                        List listY02 = AbstractC3251q.y0(listY0, i7);
                        if (!listY02.isEmpty()) {
                            int size6 = listY02.size();
                            if (size6 == 1) {
                                arrayList5.add(i9, listY02.get(0));
                                return arrayList5;
                            }
                            if (size6 == 2) {
                                arrayList5.add(i9 + 4, listY02.get(1));
                                arrayList5.add(i9, listY02.get(0));
                                return arrayList5;
                            }
                            if (size6 == 3) {
                                arrayList5.add(i9 + 7, listY02.get(2));
                                arrayList5.add(i9 + 4, listY02.get(1));
                                arrayList5.add(i9, listY02.get(0));
                                return arrayList5;
                            }
                        }
                    }
                }
                return arrayList5;
            }
            arrayList5.add(abstractC0742y1);
        }
        size = listOrderedBaseMainCatalogs.size();
        while (i6 < size) {
        }
        listY0 = AbstractC3251q.y0(list, 3);
        if (!listY0.isEmpty()) {
        }
        return arrayList5;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Object assembleMainCatalogs(List<? extends Map<String, ? extends Object>> list, List<C0718s1> list2, A4.d dVar) {
        return assembleMainCatalogEntries(list, list2);
    }

    private final String baseMainCatalogsLayoutKey() {
        if (this.baseMainCatalogs.isEmpty()) {
            return "";
        }
        Iterator<? extends AbstractC0742y1> it = this.baseMainCatalogs.iterator();
        long jHashCode = 1469598103934665603L;
        while (it.hasNext()) {
            jHashCode = (jHashCode ^ ((long) it.next().a().hashCode())) * 1099511628211L;
        }
        int size = this.baseMainCatalogs.size();
        AbstractC0872a.w(16);
        return size + "|" + AbstractC2612c.w(16, jHashCode);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:11:0x0043  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final String buildBecauseYouWatchedCacheKey() {
        boolean z6;
        Set set;
        Application application = getApplication();
        String string = p.o1((String) ((c0) z3.f8213b.f8871a).getValue()).toString();
        if (p.Q0(string)) {
            string = "main";
        }
        boolean z7 = ((n3) ((c0) u3.f8112c.f8871a).getValue()).f7972b.f7757a;
        if (string.equals("main") && z7) {
            C0716s c0716s = C0716s.f8049a;
            if (C0716s.j(application)) {
                z6 = true;
            }
        } else {
            z6 = false;
        }
        if (z6) {
            set = (Set) M.f18902f.getValue();
        } else {
            set = (Set) ((Map) k.f16506g.getValue()).get(string);
            if (set == null) {
                set = C3224A.f26032a;
            }
        }
        Iterator it = set.iterator();
        long jIntValue = 1469598103934665603L;
        while (it.hasNext()) {
            jIntValue = (jIntValue ^ ((long) ((Number) it.next()).intValue())) * 1099511628211L;
        }
        int size = set.size();
        AbstractC0872a.w(16);
        String strW = AbstractC2612c.w(16, jIntValue);
        StringBuilder sb = new StringBuilder();
        sb.append(string);
        sb.append("|");
        sb.append(z6);
        sb.append("|");
        sb.append(size);
        return com.google.android.recaptcha.internal.a.n(sb, "|", strW);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object computeMainCatalogs(List<? extends Map<String, ? extends Object>> list, A4.d dVar) throws Throwable {
        Z1 z12;
        HomeViewModel homeViewModel;
        if (dVar instanceof Z1) {
            z12 = (Z1) dVar;
            int i6 = z12.f7660e;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                z12.f7660e = i6 - Integer.MIN_VALUE;
            } else {
                z12 = new Z1(this, dVar);
            }
        }
        Object objResolveBecauseYouWatchedCatalogEntries = z12.f7658c;
        B4.a aVar = B4.a.f492a;
        int i7 = z12.f7660e;
        if (i7 == 0) {
            AbstractC2467b.l(objResolveBecauseYouWatchedCatalogEntries);
            z12.f7656a = this;
            z12.f7657b = list;
            z12.f7660e = 1;
            objResolveBecauseYouWatchedCatalogEntries = resolveBecauseYouWatchedCatalogEntries(z12);
            if (objResolveBecauseYouWatchedCatalogEntries == aVar) {
                return aVar;
            }
            homeViewModel = this;
        } else {
            if (i7 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            list = z12.f7657b;
            homeViewModel = z12.f7656a;
            AbstractC2467b.l(objResolveBecauseYouWatchedCatalogEntries);
        }
        return homeViewModel.assembleMainCatalogEntries(list, (List) objResolveBecauseYouWatchedCatalogEntries);
    }

    private final List<AbstractC0742y1> computeMainCatalogsWithoutBecause(List<? extends Map<String, ? extends Object>> list) {
        return assembleMainCatalogEntries(list, y.f26065a);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final String continueWatchingSectionTitle(boolean z6, List<? extends JSONObject> list) {
        return (!z6 || list.isEmpty()) ? "Continue Watching" : "Continue Watching - Trakt";
    }

    private final String continueWatchingSectionTitleFromStore() {
        return continueWatchingSectionTitle(((n3) ((c0) u3.f8112c.f8871a).getValue()).f7972b.f7759c && kotlin.jvm.internal.o.c((String) ((c0) z3.f8213b.f8871a).getValue(), "main"), (List) ((c0) C0706p0.f8003h.f8871a).getValue());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final U1 continueWatchingSnapshotFromStore() {
        String str = (String) ((c0) z3.f8213b.f8871a).getValue();
        boolean z6 = ((n3) ((c0) u3.f8112c.f8871a).getValue()).f7972b.f7759c && kotlin.jvm.internal.o.c(str, "main");
        c0 c0Var = C0706p0.f7996a;
        List<? extends JSONObject> list = (List) ((c0) C0706p0.f8003h.f8871a).getValue();
        return new U1(continueWatchingSectionTitle(z6, list), AbstractC0696m3.a(C0706p0.b(str), list, z6));
    }

    private final int countLeadingInPlacePrefix(List<? extends AbstractC0742y1> list) {
        Iterator<? extends AbstractC0742y1> it = list.iterator();
        int i6 = 0;
        while (it.hasNext() && it.next().b()) {
            i6++;
        }
        return i6;
    }

    private final void filterBecauseYouWatchedItemsInPlace() {
        c0 c0Var;
        Object value;
        MultiTabHomeUiState multiTabHomeUiStateCopy$default;
        Set<Integer> setWatchedMovieTmdbIdsForBecauseRow = watchedMovieTmdbIdsForBecauseRow();
        if (setWatchedMovieTmdbIdsForBecauseRow.isEmpty()) {
            return;
        }
        H h5 = this._uiState;
        do {
            c0Var = (c0) h5;
            value = c0Var.getValue();
            multiTabHomeUiStateCopy$default = (MultiTabHomeUiState) value;
            List<HomeSection> sections = multiTabHomeUiStateCopy$default.getMain().getSections();
            ArrayList arrayList = new ArrayList(AbstractC3253s.G(sections, 10));
            boolean z6 = false;
            for (HomeSection homeSectionCopy$default : sections) {
                if (isBecauseYouWatchedSectionId(homeSectionCopy$default.getId())) {
                    List<HomeMetaItem> items = homeSectionCopy$default.getItems();
                    ArrayList arrayList2 = new ArrayList();
                    for (Object obj : items) {
                        HomeMetaItem homeMetaItem = (HomeMetaItem) obj;
                        if (homeMetaItem.getTmdbId() <= 0 || !setWatchedMovieTmdbIdsForBecauseRow.contains(Integer.valueOf(homeMetaItem.getTmdbId()))) {
                            arrayList2.add(obj);
                        }
                    }
                    if (arrayList2.size() != homeSectionCopy$default.getItems().size()) {
                        homeSectionCopy$default = HomeSection.copy$default(homeSectionCopy$default, null, null, arrayList2, 3, null);
                        z6 = true;
                    }
                }
                arrayList.add(homeSectionCopy$default);
            }
            if (z6) {
                multiTabHomeUiStateCopy$default = MultiTabHomeUiState.copy$default(multiTabHomeUiStateCopy$default, HomeUiState.copy$default(multiTabHomeUiStateCopy$default.getMain(), arrayList, false, null, 6, null), null, null, 6, null);
            }
        } while (!c0Var.i(value, multiTabHomeUiStateCopy$default));
    }

    public static /* synthetic */ AbstractC0742y1 findCatalogEntry$default(HomeViewModel homeViewModel, F1 f12, String str, boolean z6, int i6, Object obj) {
        if ((i6 & 4) != 0) {
            z6 = false;
        }
        return homeViewModel.findCatalogEntry(f12, str, z6);
    }

    private final boolean hasRatingAndLogo(HomeMetaItem homeMetaItem) {
        String logoUrl;
        return (homeMetaItem.getRating() <= 5.5d || (logoUrl = homeMetaItem.getLogoUrl()) == null || p.Q0(logoUrl)) ? false : true;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX INFO: renamed from: heroGradientColorForMeta-XeAY9LY, reason: not valid java name */
    public final Object m344heroGradientColorForMetaXeAY9LY(Context context, HomeMetaItem homeMetaItem, A4.d dVar) {
        if (homeMetaItem == null) {
            return new C2714u(f.f13293a);
        }
        String backdropUrl = homeMetaItem.getBackdropUrl();
        if (backdropUrl == null) {
            backdropUrl = homeMetaItem.getPosterUrl();
        }
        return (backdropUrl == null || p.Q0(backdropUrl)) ? new C2714u(f.f13293a) : f.a(context, backdropUrl, dVar, 100);
    }

    private final void invalidateShuffledBaseMainCatalogs() {
        this.shuffledBaseMainCatalogs = y.f26065a;
        this.shuffledBaseMainCatalogsKey = null;
    }

    private final boolean isBecauseYouWatchedSectionId(String str) {
        return w.A0(str, "because_you_watched", false);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void loadHome() {
        InterfaceC0765i0 interfaceC0765i0 = this.loadJob;
        if (interfaceC0765i0 != null) {
            interfaceC0765i0.cancel(null);
        }
        this.loadJob = E.y(X.h(this), null, null, new C0650d2(this, null), 3);
    }

    private final Set<String> loadedSetFor(F1 f12) {
        int iOrdinal = f12.ordinal();
        if (iOrdinal == 0) {
            return this.loadedMain;
        }
        if (iOrdinal == 1) {
            return this.loadedMovies;
        }
        if (iOrdinal == 2) {
            return this.loadedTv;
        }
        throw new v();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Set<String> loadingSetFor(F1 f12) {
        int iOrdinal = f12.ordinal();
        if (iOrdinal == 0) {
            return this.loadingMain;
        }
        if (iOrdinal == 1) {
            return this.loadingMovies;
        }
        if (iOrdinal == 2) {
            return this.loadingTv;
        }
        throw new v();
    }

    private final String mainSectionTitle(AbstractC0742y1 abstractC0742y1, String str) {
        if (abstractC0742y1 instanceof C0726u1) {
            return continueWatchingSectionTitleFromStore();
        }
        if (!(abstractC0742y1 instanceof C0718s1)) {
            return abstractC0742y1.c();
        }
        if (str != null) {
            if (str.equals("Because you watched …") || str.equals("We think you will like this")) {
                str = null;
            }
            if (str != null) {
                return str;
            }
        }
        return ((C0718s1) abstractC0742y1).f8058b;
    }

    private final List<AbstractC0742y1> orderedBaseMainCatalogs() {
        if (this.baseMainCatalogs.isEmpty()) {
            invalidateShuffledBaseMainCatalogs();
            return y.f26065a;
        }
        String strBaseMainCatalogsLayoutKey = baseMainCatalogsLayoutKey();
        if (kotlin.jvm.internal.o.c(strBaseMainCatalogsLayoutKey, this.shuffledBaseMainCatalogsKey) && !this.shuffledBaseMainCatalogs.isEmpty()) {
            return this.shuffledBaseMainCatalogs;
        }
        List<AbstractC0742y1> listQ = AbstractC0696m3.q(this.baseMainCatalogs);
        this.shuffledBaseMainCatalogsKey = strBaseMainCatalogsLayoutKey;
        this.shuffledBaseMainCatalogs = listQ;
        return listQ;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v5, types: [V2.y1] */
    /* JADX WARN: Type inference failed for: r0v6, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r0v7, types: [V2.s1] */
    /* JADX WARN: Type inference failed for: r0v8 */
    /* JADX WARN: Type inference failed for: r5v0, types: [java.lang.Iterable, java.util.List<? extends V2.y1>, java.util.List<V2.y1>] */
    private final List<AbstractC0742y1> patchBecauseEntriesInConfigs(List<? extends AbstractC0742y1> list, List<C0718s1> list2) {
        if (list2.isEmpty()) {
            return list;
        }
        int iU = AbstractC3229F.u(AbstractC3253s.G(list2, 10));
        if (iU < 16) {
            iU = 16;
        }
        LinkedHashMap linkedHashMap = new LinkedHashMap(iU);
        for (Object obj : list2) {
            linkedHashMap.put(((C0718s1) obj).f8057a, obj);
        }
        ArrayList arrayList = new ArrayList(AbstractC3253s.G(list, 10));
        for (?? r02 : list) {
            if (r02 instanceof C0718s1) {
                r02 = (C0718s1) r02;
                C0718s1 c0718s1 = (C0718s1) linkedHashMap.get(r02.f8057a);
                if (c0718s1 != null) {
                    r02 = c0718s1;
                }
            }
            arrayList.add(r02);
        }
        return arrayList;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void patchBecauseYouWatchedInConfigs(int i6, String str, String str2, EnumC0722t1 enumC0722t1) {
        String strN;
        String strL = Z0.o.l("because_you_watched_", i6);
        Iterator<? extends AbstractC0742y1> it = this.configsMainList.iterator();
        int i7 = 0;
        while (true) {
            if (!it.hasNext()) {
                i7 = -1;
                break;
            } else if (kotlin.jvm.internal.o.c(it.next().a(), strL)) {
                break;
            } else {
                i7++;
            }
        }
        if (i7 < 0) {
            return;
        }
        AbstractC0742y1 abstractC0742y1 = this.configsMainList.get(i7);
        kotlin.jvm.internal.o.f(abstractC0742y1, "null cannot be cast to non-null type com.debridstream.tv.HomeCatalogEntry.BecauseYouWatched");
        C0718s1 c0718s1 = (C0718s1) abstractC0742y1;
        int iOrdinal = enumC0722t1.ordinal();
        if (iOrdinal == 0) {
            strN = A0.a.n("Because you watched ", str2);
        } else {
            if (iOrdinal != 1) {
                throw new v();
            }
            strN = "We think you will like this";
        }
        C0718s1 c0718s1D = C0718s1.d(c0718s1, null, strN, str, null, null, 117);
        ArrayList arrayListE0 = AbstractC3251q.E0(this.configsMainList);
        arrayListE0.set(i7, c0718s1D);
        this.configsMainList = arrayListE0;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final HomeMetaItem pickHeroItem(List<HomeMetaItem> list) {
        if (list.isEmpty()) {
            return null;
        }
        ArrayList arrayList = new ArrayList();
        for (Object obj : list) {
            if (hasRatingAndLogo((HomeMetaItem) obj)) {
                arrayList.add(obj);
            }
        }
        if (!arrayList.isEmpty()) {
            list = arrayList;
        }
        N4.a aVar = N4.d.f5273a;
        return list.isEmpty() ? null : list.get(N4.d.f5273a.c(list.size()));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final w4.k pickTwoHeroItems(List<HomeMetaItem> list) {
        if (list.isEmpty()) {
            return new w4.k(null, null);
        }
        ArrayList arrayList = new ArrayList();
        for (Object obj : list) {
            if (hasRatingAndLogo((HomeMetaItem) obj)) {
                arrayList.add(obj);
            }
        }
        if (!arrayList.isEmpty()) {
            list = arrayList;
        }
        if (list.isEmpty()) {
            return new w4.k(null, null);
        }
        if (list.size() == 1) {
            return new w4.k(list.get(0), null);
        }
        N4.a aVar = N4.d.f5273a;
        int size = list.size();
        N4.a aVar2 = N4.d.f5273a;
        int iC = aVar2.c(size);
        int iC2 = aVar2.c(list.size() - 1);
        if (iC2 >= iC) {
            iC2++;
        }
        return new w4.k(list.get(iC), list.get(iC2));
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Code restructure failed: missing block: B:21:0x0057, code lost:
    
        if (r2.applyCatalogConfigs((V2.C0739x2) r7, r0) == r1) goto L22;
     */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object refreshCatalogConfigsFromRemote(A4.d dVar) {
        C0655e2 c0655e2;
        HomeViewModel homeViewModel;
        if (dVar instanceof C0655e2) {
            c0655e2 = (C0655e2) dVar;
            int i6 = c0655e2.f7747d;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                c0655e2.f7747d = i6 - Integer.MIN_VALUE;
            } else {
                c0655e2 = new C0655e2(this, dVar);
            }
        }
        Object objK = c0655e2.f7745b;
        B4.a aVar = B4.a.f492a;
        int i7 = c0655e2.f7747d;
        if (i7 == 0) {
            AbstractC2467b.l(objK);
            c0655e2.f7744a = this;
            c0655e2.f7747d = 1;
            objK = E.k(new H2(2, null), c0655e2);
            if (objK != aVar) {
                homeViewModel = this;
            }
            return aVar;
        }
        if (i7 != 1) {
            if (i7 != 2) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            AbstractC2467b.l(objK);
            return C3137A.f25453a;
        }
        homeViewModel = c0655e2.f7744a;
        AbstractC2467b.l(objK);
        c0655e2.f7744a = null;
        c0655e2.f7747d = 2;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void refreshContinueWatchingFromStore() {
        U1 u1ContinueWatchingSnapshotFromStore = continueWatchingSnapshotFromStore();
        F1 f12 = F1.f7316a;
        String str = u1ContinueWatchingSnapshotFromStore.f7563a;
        ArrayList arrayList = u1ContinueWatchingSnapshotFromStore.f7564b;
        updateTabSections$default(this, f12, "continue_watching", str, arrayList, false, 16, null);
        syncKidsContinueWatchingRow(arrayList);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void refreshHeroes() {
        E.y(X.h(this), null, null, new C0695m2(this, null), 3);
    }

    private final void refreshKidsContinueWatchingFromStoreIfNeeded() {
        List<? extends AbstractC0742y1> list = this.configsKidsMain;
        if (list == null || !list.isEmpty()) {
            Iterator<T> it = list.iterator();
            while (it.hasNext()) {
                if (((AbstractC0742y1) it.next()) instanceof C0726u1) {
                    U1 u1ContinueWatchingSnapshotFromStore = continueWatchingSnapshotFromStore();
                    updateKidsSections("continue_watching", u1ContinueWatchingSnapshotFromStore.f7563a, u1ContinueWatchingSnapshotFromStore.f7564b);
                    return;
                }
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void removeBecauseYouWatchedSection(F1 f12, String str) {
        c0 c0Var;
        Object value;
        MultiTabHomeUiState multiTabHomeUiState;
        HomeUiState main;
        ArrayList arrayList;
        if (f12 != F1.f7316a) {
            return;
        }
        List<? extends AbstractC0742y1> list = this.configsMainList;
        ArrayList arrayList2 = new ArrayList();
        for (Object obj : list) {
            if (!kotlin.jvm.internal.o.c(((AbstractC0742y1) obj).a(), str)) {
                arrayList2.add(obj);
            }
        }
        this.configsMainList = arrayList2;
        H h5 = this._uiState;
        do {
            c0Var = (c0) h5;
            value = c0Var.getValue();
            multiTabHomeUiState = (MultiTabHomeUiState) value;
            main = multiTabHomeUiState.getMain();
            List<HomeSection> sections = multiTabHomeUiState.getMain().getSections();
            arrayList = new ArrayList();
            for (Object obj2 : sections) {
                if (!kotlin.jvm.internal.o.c(((HomeSection) obj2).getId(), str)) {
                    arrayList.add(obj2);
                }
            }
        } while (!c0Var.i(value, MultiTabHomeUiState.copy$default(multiTabHomeUiState, HomeUiState.copy$default(main, arrayList, false, null, 6, null), null, null, 6, null)));
    }

    public static /* synthetic */ void requestSectionsAround$default(HomeViewModel homeViewModel, F1 f12, int i6, int i7, int i8, Object obj) {
        if ((i8 & 4) != 0) {
            i7 = 2;
        }
        homeViewModel.requestSectionsAround(f12, i6, i7);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Path cross not found for [B:27:0x00a4, B:24:0x0093], limit reached: 227 */
    /* JADX WARN: Removed duplicated region for block: B:111:0x023e  */
    /* JADX WARN: Removed duplicated region for block: B:115:0x0245  */
    /* JADX WARN: Removed duplicated region for block: B:175:0x038a A[PHI: r4
      0x038a: PHI (r4v14 ??) = (r4v13 ??), (r4v17 ??) binds: [B:181:0x03a0, B:173:0x0387] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:176:0x038d  */
    /* JADX WARN: Removed duplicated region for block: B:202:0x0248 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:32:0x00bc  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x00c1  */
    /* JADX WARN: Removed duplicated region for block: B:47:0x00fc  */
    /* JADX WARN: Removed duplicated region for block: B:74:0x0199  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0018  */
    /* JADX WARN: Removed duplicated region for block: B:82:0x01cb  */
    /* JADX WARN: Removed duplicated region for block: B:84:0x01d0  */
    /* JADX WARN: Type inference failed for: r19v0 */
    /* JADX WARN: Type inference failed for: r19v1, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r19v2, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r19v3 */
    /* JADX WARN: Type inference failed for: r19v4 */
    /* JADX WARN: Type inference failed for: r20v1 */
    /* JADX WARN: Type inference failed for: r20v2, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r20v3 */
    /* JADX WARN: Type inference failed for: r21v0 */
    /* JADX WARN: Type inference failed for: r21v1, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r21v2 */
    /* JADX WARN: Type inference failed for: r4v13, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r4v14 */
    /* JADX WARN: Type inference failed for: r4v17 */
    /* JADX WARN: Type inference failed for: r4v18 */
    /* JADX WARN: Type inference failed for: r4v22 */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:77:0x01bf -> B:79:0x01c2). Please report as a decompilation issue!!! */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object resolveBecauseYouWatchedCatalogEntries(A4.d dVar) throws Throwable {
        C0727u2 c0727u2;
        Set set;
        HomeViewModel homeViewModel;
        String str;
        Set set2;
        Iterator it;
        List<C0718s1> list;
        LinkedHashMap linkedHashMap;
        r rVar;
        Integer num;
        boolean z6;
        int i6;
        ?? r21;
        C0718s1 c0718s1;
        String string;
        ?? string2;
        String string3;
        boolean z7;
        Integer num2;
        int i7 = 1;
        if (dVar instanceof C0727u2) {
            c0727u2 = (C0727u2) dVar;
            int i8 = c0727u2.l;
            if ((i8 & Integer.MIN_VALUE) != 0) {
                c0727u2.l = i8 - Integer.MIN_VALUE;
            } else {
                c0727u2 = new C0727u2(this, dVar);
            }
        }
        Object obj = c0727u2.f8108j;
        B4.a aVar = B4.a.f492a;
        int i9 = c0727u2.l;
        y yVar = y.f26065a;
        C3296a c3296a = C3296a.f26323c;
        if (i9 != 0) {
            if (i9 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            it = c0727u2.f8107f;
            linkedHashMap = c0727u2.f8106e;
            list = c0727u2.f8105d;
            set2 = c0727u2.f8104c;
            str = c0727u2.f8103b;
            homeViewModel = c0727u2.f8102a;
            AbstractC2467b.l(obj);
            Throwable th = null;
            if (it.hasNext()) {
                List list2 = (List) it.next();
                if (linkedHashMap.size() < 3) {
                    C0735w2 c0735w2 = new C0735w2(list2, homeViewModel, linkedHashMap, null);
                    c0727u2.f8102a = homeViewModel;
                    c0727u2.f8103b = str;
                    c0727u2.f8104c = set2;
                    c0727u2.f8105d = list;
                    c0727u2.f8106e = linkedHashMap;
                    c0727u2.f8107f = it;
                    c0727u2.l = 1;
                    if (E.k(c0735w2, c0727u2) == aVar) {
                        return aVar;
                    }
                    Throwable th2 = null;
                    if (it.hasNext()) {
                    }
                }
            }
            if (!linkedHashMap.isEmpty()) {
                homeViewModel.cachedBecauseYouWatchedKey = str;
                homeViewModel.cachedBecauseYouWatchedEntries = yVar;
                return yVar;
            }
            Set setKeySet = linkedHashMap.keySet();
            kotlin.jvm.internal.o.g(setKeySet, "<get-keys>(...)");
            int i10 = 2;
            int i11 = setKeySet.size() < 3 ? setKeySet.size() == 2 ? 2 : 1 : 3;
            ArrayList arrayList = new ArrayList();
            for (Object obj2 : list) {
                C0718s1 c0718s12 = (C0718s1) obj2;
                Throwable th3 = th2;
                if (set2.contains(new Integer(c0718s12.f8059c))) {
                    r rVar2 = (r) linkedHashMap.get(new Integer(c0718s12.f8059c));
                    if (rVar2 == null || (num2 = rVar2.f8786c) == null) {
                        num2 = c0718s12.f8061e.f8786c;
                    }
                    if (num2 != null) {
                        boolean z8 = num2.intValue() > 1990;
                        z7 = z8 ? false : true;
                        if (z7) {
                            arrayList.add(obj2);
                        }
                        th2 = th3;
                    }
                    if (z8) {
                    }
                    if (z7) {
                    }
                    th2 = th3;
                }
                if (z7) {
                }
                th2 = th3;
            }
            Throwable th4 = th2;
            List listY0 = AbstractC3251q.y0(arrayList, i11);
            ArrayList arrayList2 = new ArrayList(AbstractC3253s.G(listY0, 10));
            Iterator it2 = listY0.iterator();
            while (it2.hasNext()) {
                arrayList2.add(new Integer(((C0718s1) it2.next()).f8059c));
            }
            Set setH0 = AbstractC3251q.H0(arrayList2);
            int size = i11 - listY0.size();
            if (size < 0) {
                size = 0;
            }
            ArrayList arrayList3 = new ArrayList();
            for (Object obj3 : setKeySet) {
                if (!setH0.contains((Integer) obj3)) {
                    arrayList3.add(obj3);
                }
            }
            List listY02 = AbstractC3251q.y0(AbstractC3251q.x0(c3296a, arrayList3), size);
            ArrayList arrayList4 = new ArrayList(AbstractC3253s.G(listY0, 10));
            Iterator it3 = listY0.iterator();
            while (it3.hasNext()) {
                arrayList4.add(new Integer(((C0718s1) it3.next()).f8059c));
            }
            ArrayList arrayListS0 = AbstractC3251q.s0(listY02, arrayList4);
            int iU = AbstractC3229F.u(AbstractC3253s.G(listY0, 10));
            if (iU < 16) {
                iU = 16;
            }
            LinkedHashMap linkedHashMap2 = new LinkedHashMap(iU);
            for (Object obj4 : listY0) {
                linkedHashMap2.put(new Integer(((C0718s1) obj4).f8059c), obj4);
            }
            ArrayList arrayList5 = new ArrayList(AbstractC3253s.G(arrayListS0, 10));
            int i12 = 0;
            for (Object obj5 : arrayListS0) {
                int i13 = i12 + 1;
                if (i12 < 0) {
                    AbstractC3252r.F();
                    throw th4;
                }
                int iIntValue = ((Number) obj5).intValue();
                r rVar3 = (r) AbstractC3229F.t(new Integer(iIntValue), linkedHashMap);
                EnumC0722t1 enumC0722t1 = (i12 != i7 || arrayListS0.size() < i10) ? EnumC0722t1.f8079a : EnumC0722t1.f8080b;
                String str2 = enumC0722t1 == EnumC0722t1.f8079a ? "Because you watched …" : "We think you will like this";
                C0718s1 c0718s13 = (C0718s1) linkedHashMap2.get(new Integer(iIntValue));
                if (c0718s13 != null) {
                    String strL = Z0.o.l("because_you_watched_", iIntValue);
                    Object obj6 = c0718s13.f8058b;
                    if (obj6.equals("Because you watched …")) {
                        obj6 = th4;
                    }
                    if (obj6 != null) {
                        str2 = obj6;
                    }
                    String str3 = c0718s13.f8060d;
                    if (str3 == null || (string3 = p.o1(str3).toString()) == null) {
                        String str4 = rVar3.f8785b;
                        ?? r20 = (str4 == null || (string2 = p.o1(str4).toString()) == 0 || !w.A0(string2, TtmlNode.TAG_TT, true)) ? th4 : string2;
                        c0718s1 = C0718s1.d(c0718s13, strL, str2, r20, rVar3, enumC0722t1, 68);
                        i6 = 1;
                    } else {
                        boolean zA0 = w.A0(string3, TtmlNode.TAG_TT, true);
                        string2 = string3;
                        if (!zA0) {
                            string2 = th4;
                        }
                        if (string2 == 0) {
                        }
                    }
                } else {
                    EnumC0722t1 enumC0722t12 = enumC0722t1;
                    String strL2 = Z0.o.l("because_you_watched_", iIntValue);
                    String str5 = rVar3.f8785b;
                    if (str5 == null || (string = p.o1(str5).toString()) == null) {
                        i6 = 1;
                    } else {
                        i6 = 1;
                        if (w.A0(string, TtmlNode.TAG_TT, true)) {
                            r21 = string;
                        }
                        c0718s1 = new C0718s1(strL2, str2, iIntValue, r21, rVar3, enumC0722t12);
                    }
                    r21 = th4;
                    c0718s1 = new C0718s1(strL2, str2, iIntValue, r21, rVar3, enumC0722t12);
                }
                arrayList5.add(c0718s1);
                i7 = i6;
                i10 = 2;
                i12 = i13;
            }
            homeViewModel.cachedBecauseYouWatchedKey = str;
            homeViewModel.cachedBecauseYouWatchedEntries = arrayList5;
            return arrayList5;
        }
        AbstractC2467b.l(obj);
        String strBuildBecauseYouWatchedCacheKey = buildBecauseYouWatchedCacheKey();
        if (kotlin.jvm.internal.o.c(strBuildBecauseYouWatchedCacheKey, this.cachedBecauseYouWatchedKey)) {
            return this.cachedBecauseYouWatchedEntries;
        }
        Application application = getApplication();
        String string4 = p.o1((String) ((c0) z3.f8213b.f8871a).getValue()).toString();
        if (p.Q0(string4)) {
            string4 = "main";
        }
        boolean z9 = ((n3) ((c0) u3.f8112c.f8871a).getValue()).f7972b.f7757a;
        if (string4.equals("main") && z9) {
            C0716s c0716s = C0716s.f8049a;
            if (C0716s.j(application)) {
                set = (Set) M.f18902f.getValue();
            }
            if (!set.isEmpty()) {
                this.cachedBecauseYouWatchedKey = strBuildBecauseYouWatchedCacheKey;
                this.cachedBecauseYouWatchedEntries = yVar;
                return yVar;
            }
            List<C0718s1> list3 = this.cachedBecauseYouWatchedEntries;
            if (!list3.isEmpty()) {
                ArrayList arrayList6 = new ArrayList();
                for (Object obj7 : list3) {
                    C0718s1 c0718s14 = (C0718s1) obj7;
                    if (set.contains(new Integer(c0718s14.f8059c))) {
                        Integer num3 = c0718s14.f8061e.f8786c;
                        if ((num3 != null ? num3.intValue() : 0) > 1990) {
                            z6 = true;
                        }
                    } else {
                        z6 = false;
                    }
                    if (z6) {
                        arrayList6.add(obj7);
                    }
                }
                if (arrayList6.size() == list3.size()) {
                    this.cachedBecauseYouWatchedKey = strBuildBecauseYouWatchedCacheKey;
                    this.cachedBecauseYouWatchedEntries = arrayList6;
                    return arrayList6;
                }
            }
            LinkedHashMap linkedHashMap3 = new LinkedHashMap();
            for (C0718s1 c0718s15 : list3) {
                if (set.contains(new Integer(c0718s15.f8059c)) && (num = (rVar = c0718s15.f8061e).f8786c) != null && num.intValue() > 1990) {
                    linkedHashMap3.putIfAbsent(new Integer(c0718s15.f8059c), rVar);
                }
            }
            ArrayList arrayList7 = new ArrayList();
            for (Object obj8 : set) {
                if (!linkedHashMap3.containsKey(new Integer(((Number) obj8).intValue()))) {
                    arrayList7.add(obj8);
                }
            }
            Iterator it4 = AbstractC3251q.I0(AbstractC3251q.y0(AbstractC3251q.x0(c3296a, arrayList7), 48), 4, 4).iterator();
            homeViewModel = this;
            str = strBuildBecauseYouWatchedCacheKey;
            set2 = set;
            it = it4;
            list = list3;
            linkedHashMap = linkedHashMap3;
            Throwable th22 = null;
            if (it.hasNext()) {
            }
            if (!linkedHashMap.isEmpty()) {
            }
        }
        set = (Set) ((Map) k.f16506g.getValue()).get(string4);
        if (set == null) {
            set = C3224A.f26032a;
        }
        if (!set.isEmpty()) {
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean sameCatalogIds(List<? extends AbstractC0742y1> list, List<? extends AbstractC0742y1> list2) {
        if (list.size() == list2.size()) {
            int size = list.size();
            for (int i6 = 0; i6 < size; i6++) {
                if (kotlin.jvm.internal.o.c(list.get(i6).a(), list2.get(i6).a())) {
                }
            }
            return true;
        }
        return false;
    }

    /* JADX WARN: Code restructure failed: missing block: B:27:0x0072, code lost:
    
        if (r1 >= r6.size()) goto L44;
     */
    /* JADX WARN: Code restructure failed: missing block: B:29:0x0082, code lost:
    
        if (isBecauseYouWatchedSectionId(r6.get(r1).a()) != false) goto L31;
     */
    /* JADX WARN: Code restructure failed: missing block: B:31:0x0085, code lost:
    
        r1 = r1 + 1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:33:0x008c, code lost:
    
        if (r2 >= r7.size()) goto L47;
     */
    /* JADX WARN: Code restructure failed: missing block: B:35:0x009c, code lost:
    
        if (isBecauseYouWatchedSectionId(r7.get(r2).a()) != false) goto L37;
     */
    /* JADX WARN: Code restructure failed: missing block: B:37:0x009f, code lost:
    
        r2 = r2 + 1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:38:0x00a2, code lost:
    
        return true;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private final boolean sameNonBecauseSectionIdsInOrder(List<? extends AbstractC0742y1> list, List<? extends AbstractC0742y1> list2) {
        int i6 = 0;
        int i7 = 0;
        while (true) {
            if (i6 >= list.size() && i7 >= list2.size()) {
                break;
            }
            while (i6 < list.size() && isBecauseYouWatchedSectionId(list.get(i6).a())) {
                i6++;
            }
            while (i7 < list2.size() && isBecauseYouWatchedSectionId(list2.get(i7).a())) {
                i7++;
            }
            if (i6 >= list.size() || i7 >= list2.size()) {
                break;
            }
            if (!kotlin.jvm.internal.o.c(list.get(i6).a(), list2.get(i7).a())) {
                break;
            }
            i6++;
            i7++;
        }
        return false;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final HomeUiState shellState(List<? extends AbstractC0742y1> list) {
        ArrayList arrayList = new ArrayList(AbstractC3253s.G(list, 10));
        for (AbstractC0742y1 abstractC0742y1 : list) {
            arrayList.add(new HomeSection(abstractC0742y1.a(), abstractC0742y1 instanceof C0726u1 ? continueWatchingSectionTitleFromStore() : abstractC0742y1.c(), y.f26065a));
        }
        return new HomeUiState(arrayList, false, null);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void syncKidsContinueWatchingRow(List<HomeMetaItem> list) {
        if (this.configsKidsMain.isEmpty()) {
            return;
        }
        List<? extends AbstractC0742y1> list2 = this.configsKidsMain;
        if (list2 == null || !list2.isEmpty()) {
            Iterator<T> it = list2.iterator();
            while (it.hasNext()) {
                if (((AbstractC0742y1) it.next()) instanceof C0726u1) {
                    updateKidsSections("continue_watching", continueWatchingSectionTitleFromStore(), list);
                    return;
                }
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void updateKidsSections(String str, String str2, List<HomeMetaItem> list) {
        c0 c0Var;
        Object value;
        HomeUiState homeUiState;
        ArrayList arrayListE0;
        H h5 = this._kidsHomeState;
        do {
            c0Var = (c0) h5;
            value = c0Var.getValue();
            homeUiState = (HomeUiState) value;
            arrayListE0 = AbstractC3251q.E0(homeUiState.getSections());
            Iterator it = arrayListE0.iterator();
            int i6 = 0;
            while (true) {
                if (!it.hasNext()) {
                    i6 = -1;
                    break;
                } else if (kotlin.jvm.internal.o.c(((HomeSection) it.next()).getId(), str)) {
                    break;
                } else {
                    i6++;
                }
            }
            HomeSection homeSection = new HomeSection(str, str2, W.a.a0(list));
            if (i6 >= 0) {
                arrayListE0.set(i6, homeSection);
            } else {
                arrayListE0.add(homeSection);
            }
        } while (!c0Var.i(value, HomeUiState.copy$default(homeUiState, arrayListE0, false, null, 6, null)));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void updateTabSections(F1 f12, String str, String str2, List<HomeMetaItem> list, boolean z6) {
        c0 c0Var;
        Object value;
        MultiTabHomeUiState multiTabHomeUiStateCopy$default;
        H h5 = this._uiState;
        do {
            c0Var = (c0) h5;
            value = c0Var.getValue();
            MultiTabHomeUiState multiTabHomeUiState = (MultiTabHomeUiState) value;
            int iOrdinal = f12.ordinal();
            if (iOrdinal == 0) {
                multiTabHomeUiStateCopy$default = MultiTabHomeUiState.copy$default(multiTabHomeUiState, updateTabSections$lambda$52$patch(str, str2, z6, list, multiTabHomeUiState.getMain()), null, null, 6, null);
            } else if (iOrdinal == 1) {
                multiTabHomeUiStateCopy$default = MultiTabHomeUiState.copy$default(multiTabHomeUiState, null, updateTabSections$lambda$52$patch(str, str2, z6, list, multiTabHomeUiState.getMovies()), null, 5, null);
            } else {
                if (iOrdinal != 2) {
                    throw new v();
                }
                multiTabHomeUiStateCopy$default = MultiTabHomeUiState.copy$default(multiTabHomeUiState, null, null, updateTabSections$lambda$52$patch(str, str2, z6, list, multiTabHomeUiState.getTvShows()), 3, null);
            }
        } while (!c0Var.i(value, multiTabHomeUiStateCopy$default));
    }

    public static /* synthetic */ void updateTabSections$default(HomeViewModel homeViewModel, F1 f12, String str, String str2, List list, boolean z6, int i6, Object obj) {
        if ((i6 & 16) != 0) {
            z6 = false;
        }
        homeViewModel.updateTabSections(f12, str, str2, list, z6);
    }

    private static final HomeUiState updateTabSections$lambda$52$patch(String str, String str2, boolean z6, List<HomeMetaItem> list, HomeUiState homeUiState) {
        ArrayList arrayListE0 = AbstractC3251q.E0(homeUiState.getSections());
        Iterator it = arrayListE0.iterator();
        int i6 = 0;
        while (true) {
            if (!it.hasNext()) {
                i6 = -1;
                break;
            }
            if (kotlin.jvm.internal.o.c(((HomeSection) it.next()).getId(), str)) {
                break;
            }
            i6++;
        }
        if (!z6) {
            list = W.a.a0(list);
        }
        HomeSection homeSection = new HomeSection(str, str2, list);
        if (i6 >= 0) {
            arrayListE0.set(i6, homeSection);
        } else {
            arrayListE0.add(homeSection);
        }
        return HomeUiState.copy$default(homeUiState, arrayListE0, false, null, 6, null);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Set<Integer> watchedMovieTmdbIdsForBecauseRow() {
        Application application = getApplication();
        String string = p.o1((String) ((c0) z3.f8213b.f8871a).getValue()).toString();
        if (p.Q0(string)) {
            string = "main";
        }
        if (string.equals("main") && ((n3) ((c0) u3.f8112c.f8871a).getValue()).f7972b.f7757a) {
            C0716s c0716s = C0716s.f8049a;
            if (C0716s.j(application)) {
                return (Set) M.f18902f.getValue();
            }
        }
        Set<Integer> set = (Set) ((Map) k.f16506g.getValue()).get(string);
        return set == null ? C3224A.f26032a : set;
    }

    public final void ensureKidsHomeLoaded() {
        if (this.configsKidsMain.isEmpty()) {
            return;
        }
        E.y(X.h(this), null, null, new C0645c2(this, null), 3);
    }

    public final AbstractC0742y1 findCatalogEntry(F1 tab, String sectionId, boolean z6) {
        List<? extends AbstractC0742y1> list;
        kotlin.jvm.internal.o.h(tab, "tab");
        kotlin.jvm.internal.o.h(sectionId, "sectionId");
        Object obj = null;
        if (z6 && tab == F1.f7316a) {
            Iterator<T> it = this.configsKidsMain.iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                Object next = it.next();
                if (kotlin.jvm.internal.o.c(((AbstractC0742y1) next).a(), sectionId)) {
                    obj = next;
                    break;
                }
            }
            return (AbstractC0742y1) obj;
        }
        int iOrdinal = tab.ordinal();
        if (iOrdinal == 0) {
            list = this.configsMainList;
        } else if (iOrdinal == 1) {
            list = this.configsMovies;
        } else {
            if (iOrdinal != 2) {
                throw new v();
            }
            list = this.configsTv;
        }
        Iterator<T> it2 = list.iterator();
        while (true) {
            if (!it2.hasNext()) {
                break;
            }
            Object next2 = it2.next();
            if (kotlin.jvm.internal.o.c(((AbstractC0742y1) next2).a(), sectionId)) {
                obj = next2;
                break;
            }
        }
        return (AbstractC0742y1) obj;
    }

    public final a0 getHeroUiState() {
        return this.heroUiState;
    }

    public final a0 getKidsHomeState() {
        return this.kidsHomeState;
    }

    public final a0 getUiState() {
        return this.uiState;
    }

    public final void requestSectionsAround(F1 tab, int i6, int i7) {
        List<? extends AbstractC0742y1> list;
        kotlin.jvm.internal.o.h(tab, "tab");
        int iOrdinal = tab.ordinal();
        if (iOrdinal == 0) {
            list = this.configsMainList;
        } else if (iOrdinal == 1) {
            list = this.configsMovies;
        } else {
            if (iOrdinal != 2) {
                throw new v();
            }
            list = this.configsTv;
        }
        List<? extends AbstractC0742y1> list2 = list;
        if (list2.isEmpty()) {
            return;
        }
        int i8 = i6 - i7;
        if (i8 < 0) {
            i8 = 0;
        }
        int i9 = i8;
        int i10 = i6 + i7;
        int iA = AbstractC3252r.A(list2);
        int i11 = i10 > iA ? iA : i10;
        if (i9 > i11) {
            return;
        }
        Set<String> setLoadedSetFor = loadedSetFor(tab);
        if (i9 <= i11) {
            int i12 = i9;
            while (setLoadedSetFor.contains(list2.get(i12).a())) {
                F1 f12 = tab;
                if (i12 == i11) {
                    return;
                }
                i12++;
                tab = f12;
            }
            E.y(X.h(this), null, null, new C0723t2(this, tab, i11, i9, list2, setLoadedSetFor, null), 3);
        }
    }
}
