package h3;

import com.debridstream.tv.data.home.HomeMetaItem;
import com.debridstream.tv.screens.SearchRecommendationsViewModel;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import m3.AbstractC2467b;
import w4.C3137A;

/* JADX INFO: renamed from: h3.g2, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C2117g2 extends C4.j implements J4.e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int f17949a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public /* synthetic */ Object f17950b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ SearchRecommendationsViewModel f17951c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final /* synthetic */ C2099d2 f17952d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final /* synthetic */ int f17953e;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C2117g2(SearchRecommendationsViewModel searchRecommendationsViewModel, C2099d2 c2099d2, int i6, A4.d dVar) {
        super(2, dVar);
        this.f17951c = searchRecommendationsViewModel;
        this.f17952d = c2099d2;
        this.f17953e = i6;
    }

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        C2117g2 c2117g2 = new C2117g2(this.f17951c, this.f17952d, this.f17953e, dVar);
        c2117g2.f17950b = obj;
        return c2117g2;
    }

    @Override // J4.e
    public final Object invoke(Object obj, Object obj2) {
        return ((C2117g2) create((V4.C) obj, (A4.d) obj2)).invokeSuspend(C3137A.f25453a);
    }

    @Override // C4.a
    public final Object invokeSuspend(Object obj) {
        Object objD;
        Y4.c0 c0Var;
        Object value;
        Y4.c0 c0Var2;
        Object value2;
        C2105e2 c2105e2;
        ArrayList arrayList;
        boolean z6;
        boolean z7;
        Object objN;
        C2117g2 c2117g2 = this;
        B4.a aVar = B4.a.f492a;
        int i6 = c2117g2.f17949a;
        SearchRecommendationsViewModel searchRecommendationsViewModel = c2117g2.f17951c;
        int i7 = c2117g2.f17953e;
        C2099d2 c2099d2 = c2117g2.f17952d;
        try {
            if (i6 == 0) {
                AbstractC2467b.l(obj);
                Y4.H h5 = searchRecommendationsViewModel._ui;
                while (true) {
                    Y4.c0 c0Var3 = (Y4.c0) h5;
                    Object value3 = c0Var3.getValue();
                    if (c0Var3.i(value3, C2105e2.a((C2105e2) value3, null, null, null, false, true, null, false, 0, 239))) {
                        break;
                    }
                    c2117g2 = this;
                }
                Y2.o oVar = searchRecommendationsViewModel.repository;
                boolean z8 = searchRecommendationsViewModel.kidsCatalogFriendlyOnly;
                c2117g2.f17949a = 1;
                objN = T2.n(oVar, c2099d2, i7, z8, c2117g2);
                if (objN == aVar) {
                    return aVar;
                }
            } else {
                if (i6 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                AbstractC2467b.l(obj);
                objN = obj;
            }
            objD = (Y2.a) objN;
        } catch (Throwable th) {
            objD = AbstractC2467b.d(th);
        }
        if (!(objD instanceof w4.m)) {
            Y2.a aVar2 = (Y2.a) objD;
            List<HomeMetaItem> list = aVar2.f8714a;
            Y4.H h6 = searchRecommendationsViewModel._ui;
            do {
                c0Var2 = (Y4.c0) h6;
                value2 = c0Var2.getValue();
                c2105e2 = (C2105e2) value2;
                List list2 = c2105e2.f17893c;
                HashSet hashSet = new HashSet(list.size() + list2.size());
                Iterator it = list2.iterator();
                while (it.hasNext()) {
                    hashSet.add(new Integer(((HomeMetaItem) it.next()).getTmdbId()));
                }
                arrayList = new ArrayList(list.size() + list2.size());
                arrayList.addAll(list2);
                for (HomeMetaItem homeMetaItem : list) {
                    if (hashSet.add(new Integer(homeMetaItem.getTmdbId()))) {
                        arrayList.add(homeMetaItem);
                    }
                }
                EnumC2085b2 enumC2085b2 = c2099d2.f17851d;
                boolean z9 = enumC2085b2 != EnumC2085b2.f17747a && i7 < 8;
                int iOrdinal = enumC2085b2.ordinal();
                boolean z10 = aVar2.f8715b;
                if (iOrdinal != 0) {
                    z6 = true;
                    if (iOrdinal != 1 && iOrdinal != 2) {
                        throw new E3.v();
                    }
                    z7 = z10 && z9;
                } else {
                    z6 = true;
                    z7 = z10;
                }
            } while (!c0Var2.i(value2, C2105e2.a(c2105e2, null, null, arrayList, false, false, null, z7, i7 + 1, 43)));
        }
        if (w4.n.a(objD) != null) {
            Y4.H h7 = searchRecommendationsViewModel._ui;
            do {
                c0Var = (Y4.c0) h7;
                value = c0Var.getValue();
            } while (!c0Var.i(value, C2105e2.a((C2105e2) value, null, null, null, false, false, null, false, 0, 175)));
        }
        return C3137A.f25453a;
    }
}
