package defpackage;

import com.strmr.ps.data.local.dao.RowConfigDao;
import com.strmr.ps.data.local.entity.PlaybackProgress;
import com.strmr.ps.data.local.entity.RowConfigEntity;
import com.strmr.ps.data.local.entity.TraktAccount;
import com.strmr.ps.data.model.addon.InstalledAddon;
import com.strmr.ps.data.model.addon.StremioCatalog;
import com.strmr.ps.data.repository.ScreenConfigRepository;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "Le6a;", "<anonymous>", "(Lak1;)V"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.ui.settings.fragments.AddonsFragment$createCatalogRows$1", f = "AddonsFragment.kt", i = {1, 1, 1, 1, 2}, l = {588, 604, 656, 658, 667, 669}, m = "invokeSuspend", n = {"profileSlugs", "allRows", "profileSlug", "page", "allRows"}, s = {"L$0", "L$1", "L$3", "L$5", "L$0"})
@vx8
final class je extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
    public List a;
    public Object b;
    public Iterator c;
    public String d;
    public Iterator e;
    public String f;
    public int i;
    public final /* synthetic */ ff j;
    public final /* synthetic */ ArrayList k;
    public final /* synthetic */ ArrayList l;
    public final /* synthetic */ InstalledAddon m;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public je(ff ffVar, ArrayList arrayList, ArrayList arrayList2, InstalledAddon installedAddon, Continuation continuation) {
        super(2, continuation);
        this.j = ffVar;
        this.k = arrayList;
        this.l = arrayList2;
        this.m = installedAddon;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        return new je(this.j, this.k, this.l, this.m, continuation);
    }

    @Override // defpackage.gr3
    public final Object invoke(Object obj, Object obj2) {
        return ((je) create((ak1) obj, (Continuation) obj2)).invokeSuspend(e6a.a);
    }

    /* JADX WARN: Code restructure failed: missing block: B:17:0x0065, code lost:
    
        if (r2 == r1) goto L97;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:102:0x02d4 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:29:0x00b4  */
    /* JADX WARN: Removed duplicated region for block: B:32:0x00cb  */
    /* JADX WARN: Removed duplicated region for block: B:39:0x0107  */
    /* JADX WARN: Removed duplicated region for block: B:56:0x01e1  */
    /* JADX WARN: Removed duplicated region for block: B:57:0x01e5  */
    /* JADX WARN: Removed duplicated region for block: B:60:0x01f5  */
    /* JADX WARN: Removed duplicated region for block: B:97:0x0302 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:98:0x0303 A[PHI: r39
      0x0303: PHI (r39v5 e6a) = (r39v3 e6a), (r39v6 e6a) binds: [B:87:0x02c5, B:96:0x0300] A[DONT_GENERATE, DONT_INLINE], RETURN] */
    /* JADX WARN: Type inference failed for: r10v10 */
    /* JADX WARN: Type inference failed for: r10v15 */
    /* JADX WARN: Type inference failed for: r10v20, types: [java.lang.Object, java.lang.String, java.util.Iterator, java.util.List] */
    /* JADX WARN: Type inference failed for: r10v29, types: [java.lang.String, java.util.Iterator] */
    /* JADX WARN: Type inference failed for: r10v40, types: [kotlin.coroutines.Continuation] */
    /* JADX WARN: Type inference failed for: r10v41 */
    /* JADX WARN: Type inference failed for: r10v42 */
    /* JADX WARN: Type inference failed for: r10v9 */
    /* JADX WARN: Type inference failed for: r13v3 */
    /* JADX WARN: Type inference failed for: r13v4 */
    /* JADX WARN: Type inference failed for: r13v7 */
    /* JADX WARN: Type inference failed for: r15v0 */
    /* JADX WARN: Type inference failed for: r9v20 */
    /* JADX WARN: Type inference failed for: r9v3, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r9v4, types: [java.lang.Object, java.util.List] */
    /* JADX WARN: Type inference failed for: r9v5, types: [java.util.ArrayList] */
    /* JADX WARN: Type inference failed for: r9v6, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r9v9 */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:29:0x00b4 -> B:30:0x00c5). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:35:0x00ef -> B:36:0x00f6). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:82:0x02a9 -> B:84:0x02ac). Please report as a decompilation issue!!! */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) throws Throwable {
        Object allAccountsSync;
        ?? Am;
        List<RowConfigEntity> arrayList;
        e6a e6aVar;
        Throwable th;
        List<RowConfigEntity> list;
        Iterator it;
        ?? r10;
        Iterator it2;
        String str;
        Iterator it3;
        Object rowCountForProfile;
        List<RowConfigEntity> list2;
        String str2;
        ?? r13;
        String str3;
        String str4;
        String str5;
        Object objCheckRowLimitsByScreen;
        ?? r102;
        ck1 ck1Var = ck1.a;
        int i = this.i;
        e6a e6aVar2 = e6a.a;
        ArrayList arrayList2 = this.l;
        ArrayList arrayList3 = this.k;
        boolean z = true;
        ff ffVar = this.j;
        switch (i) {
            case 0:
                s38.b(obj);
                fg4 fg4Var = ffVar.l;
                if (fg4Var == null) {
                    cr4.n("traktAccountRepository");
                    throw null;
                }
                this.i = 1;
                allAccountsSync = fg4Var.getAllAccountsSync(this);
                break;
                break;
            case 1:
                s38.b(obj);
                allAccountsSync = obj;
                List list3 = (List) allAccountsSync;
                if (list3.isEmpty()) {
                    Am = y41.am("");
                } else {
                    List list4 = list3;
                    Am = new ArrayList(y41.p(list4, 10));
                    Iterator it4 = list4.iterator();
                    while (it4.hasNext()) {
                        Am.add(((TraktAccount) it4.next()).getUserSlug());
                    }
                }
                Am.size();
                Am.toString();
                arrayList = new ArrayList<>();
                Iterator it5 = Am.iterator();
                ?? r9 = Am;
                if (!it5.hasNext()) {
                    String str6 = (String) it5.next();
                    Iterator it6 = it5;
                    r10 = r9;
                    it2 = arrayList3.iterator();
                    str = str6;
                    it3 = it6;
                    if (it2.hasNext()) {
                        String str7 = (String) it2.next();
                        RowConfigDao rowConfigDaoN = ffVar.n();
                        this.a = (List) r10;
                        this.b = arrayList;
                        this.c = it3;
                        this.d = str;
                        this.e = it2;
                        this.f = str7;
                        this.i = 2;
                        rowCountForProfile = rowConfigDaoN.getRowCountForProfile(str, str7, this);
                        if (rowCountForProfile != ck1Var) {
                            String str8 = str;
                            list2 = arrayList;
                            str2 = str7;
                            r13 = r10;
                            str3 = str8;
                            int iIntValue = ((Number) rowCountForProfile).intValue();
                            int i2 = 0;
                            for (Object obj2 : arrayList2) {
                                int i3 = i2 + 1;
                                if (i2 < 0) {
                                    y41.bm();
                                    throw null;
                                }
                                StremioCatalog stremioCatalog = (StremioCatalog) obj2;
                                boolean z2 = z;
                                InstalledAddon installedAddon = this.m;
                                String instanceId = installedAddon.getInstanceId();
                                e6a e6aVar3 = e6aVar2;
                                String type = stremioCatalog.getType();
                                String id = stremioCatalog.getId();
                                Iterator it7 = it2;
                                StringBuilder sb = new StringBuilder();
                                sb.append(str3);
                                String str9 = str3;
                                sb.append("_addon_");
                                sb.append(instanceId);
                                sb.append("_");
                                sb.append(type);
                                String strU = n41.u(sb, "_", id, "_", str2);
                                String name = stremioCatalog.getName();
                                if (name == null) {
                                    name = vw2.l(installedAddon.getDisplayName(), " - ", stremioCatalog.getId());
                                }
                                String str10 = name;
                                int i4 = i2 + iIntValue + 1;
                                String type2 = stremioCatalog.getType();
                                if (cr4.b(type2, PlaybackProgress.TYPE_MOVIE)) {
                                    str5 = "movies";
                                } else if (cr4.b(type2, "series")) {
                                    str5 = "shows";
                                } else {
                                    str4 = null;
                                    String instanceId2 = installedAddon.getInstanceId();
                                    String type3 = stremioCatalog.getType();
                                    String id2 = stremioCatalog.getId();
                                    String str11 = str2;
                                    StringBuilder sbM = fi7.m("addon_catalog:", instanceId2, ":", type3, ":");
                                    sbM.append(id2);
                                    RowConfigEntity rowConfigEntity = new RowConfigEntity(strU, str9, str11, str10, "addon_catalog", str4, "portrait", sbM.toString(), i4, i4, true, false, stremioCatalog.getEffectivePageSize(), false, null, null, null, 114688, null);
                                    installedAddon.getInstanceId();
                                    list2.add(rowConfigEntity);
                                    str3 = str9;
                                    str2 = str11;
                                    i2 = i3;
                                    z = z2;
                                    e6aVar2 = e6aVar3;
                                    it2 = it7;
                                }
                                str4 = str5;
                                String instanceId22 = installedAddon.getInstanceId();
                                String type32 = stremioCatalog.getType();
                                String id22 = stremioCatalog.getId();
                                String str112 = str2;
                                StringBuilder sbM2 = fi7.m("addon_catalog:", instanceId22, ":", type32, ":");
                                sbM2.append(id22);
                                RowConfigEntity rowConfigEntity2 = new RowConfigEntity(strU, str9, str112, str10, "addon_catalog", str4, "portrait", sbM2.toString(), i4, i4, true, false, stremioCatalog.getEffectivePageSize(), false, null, null, null, 114688, null);
                                installedAddon.getInstanceId();
                                list2.add(rowConfigEntity2);
                                str3 = str9;
                                str2 = str112;
                                i2 = i3;
                                z = z2;
                                e6aVar2 = e6aVar3;
                                it2 = it7;
                            }
                            String str12 = str3;
                            arrayList = list2;
                            r10 = r13;
                            str = str12;
                            if (it2.hasNext()) {
                                r9 = r10;
                                it5 = it3;
                                if (!it5.hasNext()) {
                                    e6aVar = e6aVar2;
                                    th = null;
                                    list = arrayList;
                                    it = r9.iterator();
                                    while (true) {
                                        if (it.hasNext()) {
                                            ?? r103 = th;
                                            RowConfigDao rowConfigDaoN2 = ffVar.n();
                                            this.a = r103;
                                            this.b = r103;
                                            this.c = r103;
                                            this.d = r103;
                                            this.e = r103;
                                            this.f = r103;
                                            this.i = 5;
                                            r102 = r103;
                                            if (rowConfigDaoN2.insertAll(list, this) != ck1Var) {
                                            }
                                        } else {
                                            String str13 = (String) it.next();
                                            ArrayList arrayList4 = new ArrayList();
                                            for (Object obj3 : list) {
                                                if (cr4.b(((RowConfigEntity) obj3).getProfileSlug(), str13)) {
                                                    arrayList4.add(obj3);
                                                }
                                            }
                                            LinkedHashMap linkedHashMap = new LinkedHashMap();
                                            for (Object obj4 : arrayList4) {
                                                String screenType = ((RowConfigEntity) obj4).getScreenType();
                                                Object arrayList5 = linkedHashMap.get(screenType);
                                                if (arrayList5 == null) {
                                                    arrayList5 = new ArrayList();
                                                    linkedHashMap.put(screenType, arrayList5);
                                                }
                                                ((List) arrayList5).add(obj4);
                                            }
                                            LinkedHashMap linkedHashMap2 = new LinkedHashMap(wo5.h(linkedHashMap.size()));
                                            for (Map.Entry entry : linkedHashMap.entrySet()) {
                                                linkedHashMap2.put(entry.getKey(), Boxing.boxInt(((List) entry.getValue()).size()));
                                            }
                                            if (!linkedHashMap2.isEmpty()) {
                                                ScreenConfigRepository screenConfigRepository = ffVar.m;
                                                if (screenConfigRepository == null) {
                                                    Throwable th2 = th;
                                                    cr4.n("screenConfigRepository");
                                                    throw th2;
                                                }
                                                this.a = list;
                                                this.b = it;
                                                ?? r104 = th;
                                                this.c = r104;
                                                this.d = r104;
                                                this.e = r104;
                                                this.f = r104;
                                                this.i = 3;
                                                objCheckRowLimitsByScreen = screenConfigRepository.checkRowLimitsByScreen(str13, linkedHashMap2, this);
                                                if (objCheckRowLimitsByScreen != ck1Var) {
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                break;
            case 2:
                str2 = this.f;
                it2 = this.e;
                str3 = this.d;
                it3 = this.c;
                list2 = (List) this.b;
                List list5 = this.a;
                s38.b(obj);
                rowCountForProfile = obj;
                r13 = list5;
                int iIntValue2 = ((Number) rowCountForProfile).intValue();
                int i22 = 0;
                while (r35.hasNext()) {
                }
                String str122 = str3;
                arrayList = list2;
                r10 = r13;
                str = str122;
                if (it2.hasNext()) {
                }
                break;
            case 3:
                it = (Iterator) this.b;
                list = this.a;
                s38.b(obj);
                e6aVar = e6aVar2;
                objCheckRowLimitsByScreen = obj;
                String str14 = (String) objCheckRowLimitsByScreen;
                if (str14 == null) {
                    th = null;
                    while (true) {
                        if (it.hasNext()) {
                        }
                    }
                }
                m12 m12Var = sc2.a;
                qm5 qm5Var = sm5.a;
                he heVar = new he(ffVar, str14, null);
                this.a = null;
                this.b = null;
                this.i = 4;
                return wj0.f(qm5Var, heVar, this) == ck1Var ? ck1Var : e6aVar;
            case 4:
                s38.b(obj);
                return e6aVar2;
            case 5:
                s38.b(obj);
                e6aVar = e6aVar2;
                r102 = 0;
                m12 m12Var2 = sc2.a;
                qm5 qm5Var2 = sm5.a;
                ie ieVar = new ie(arrayList2, arrayList3, ffVar, r102);
                this.i = 6;
                if (wj0.f(qm5Var2, ieVar, this) == ck1Var) {
                }
                break;
            case 6:
                s38.b(obj);
                return e6aVar2;
            default:
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
    }
}
