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 com.strmr.ps.ui.mobile.settings.MobileAddonsFragment;
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.mobile.settings.MobileAddonsFragment$createCatalogRows$1", f = "MobileAddonsFragment.kt", i = {1, 1, 3, 3, 4, 4, 4, 4}, l = {617, 628, 630, 640, 677, 682}, m = "invokeSuspend", n = {"profileSlugs", "rowsByScreen", "profileSlug", "page", "profileSlug", "page", "currentRowCount", "index$iv"}, s = {"L$0", "L$1", "L$1", "L$3", "L$1", "L$3", "I$0", "I$1"})
@vx8
final class a16 extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
    public Object a;
    public Object b;
    public Iterator c;
    public String d;
    public InstalledAddon e;
    public MobileAddonsFragment f;
    public Iterator i;
    public int j;
    public int k;
    public int l;
    public final /* synthetic */ MobileAddonsFragment m;
    public final /* synthetic */ ArrayList n;
    public final /* synthetic */ ArrayList o;
    public final /* synthetic */ InstalledAddon p;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public a16(MobileAddonsFragment mobileAddonsFragment, ArrayList arrayList, ArrayList arrayList2, InstalledAddon installedAddon, Continuation continuation) {
        super(2, continuation);
        this.m = mobileAddonsFragment;
        this.n = arrayList;
        this.o = arrayList2;
        this.p = installedAddon;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        return new a16(this.m, this.n, this.o, this.p, continuation);
    }

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

    /* JADX WARN: Code restructure failed: missing block: B:17:0x008b, code lost:
    
        if (r2 == r1) goto L85;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:34:0x00fa A[PHI: r2 r8 r9
      0x00fa: PHI (r2v11 java.util.Iterator) = (r2v7 java.util.Iterator), (r2v13 java.util.Iterator) binds: [B:33:0x00f4, B:42:0x011d] A[DONT_GENERATE, DONT_INLINE]
      0x00fa: PHI (r8v7 java.util.Map<java.lang.String, java.lang.Integer>) = (r8v5 java.util.Map<java.lang.String, java.lang.Integer>), (r8v8 java.util.Map<java.lang.String, java.lang.Integer>) binds: [B:33:0x00f4, B:42:0x011d] A[DONT_GENERATE, DONT_INLINE]
      0x00fa: PHI (r9v7 ??) = (r9v5 ??), (r9v25 ??) binds: [B:33:0x00f4, B:42:0x011d] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:36:0x0100  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x011f  */
    /* JADX WARN: Removed duplicated region for block: B:49:0x0145  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x0149 A[PHI: r2 r3 r4 r5 r6
      0x0149: PHI (r2v19 java.util.Iterator) = (r2v12 java.util.Iterator), (r2v23 java.util.Iterator) binds: [B:49:0x0145, B:54:0x0162] A[DONT_GENERATE, DONT_INLINE]
      0x0149: PHI (r3v1 e6a) = (r3v0 e6a), (r3v3 e6a) binds: [B:49:0x0145, B:54:0x0162] A[DONT_GENERATE, DONT_INLINE]
      0x0149: PHI (r4v2 java.util.ArrayList) = (r4v0 java.util.ArrayList), (r4v4 java.util.ArrayList) binds: [B:49:0x0145, B:54:0x0162] A[DONT_GENERATE, DONT_INLINE]
      0x0149: PHI (r5v2 java.util.ArrayList) = (r5v0 java.util.ArrayList), (r5v3 java.util.ArrayList) binds: [B:49:0x0145, B:54:0x0162] A[DONT_GENERATE, DONT_INLINE]
      0x0149: PHI (r6v1 boolean) = (r6v0 boolean), (r6v2 boolean) binds: [B:49:0x0145, B:54:0x0162] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:52:0x014f  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x0164  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x01a3  */
    /* JADX WARN: Removed duplicated region for block: B:78:0x0280  */
    /* JADX WARN: Removed duplicated region for block: B:82:0x0290  */
    /* JADX WARN: Removed duplicated region for block: B:83:0x0293  */
    /* JADX WARN: Type inference failed for: r8v3, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r8v4, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r8v6, types: [java.util.ArrayList] */
    /* JADX WARN: Type inference failed for: r9v23 */
    /* JADX WARN: Type inference failed for: r9v24 */
    /* JADX WARN: Type inference failed for: r9v25 */
    /* JADX WARN: Type inference failed for: r9v5 */
    /* JADX WARN: Type inference failed for: r9v7, types: [java.lang.Object, java.util.List] */
    /* JADX WARN: Type inference failed for: r9v8 */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:39:0x0117 -> B:41:0x011b). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:52:0x014f -> B:53:0x015e). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:78:0x0280 -> B:79:0x0281). 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) {
        Object allAccountsSync;
        ?? Am;
        Iterator it;
        ?? r9;
        Map<String, Integer> map;
        Object objCheckRowLimitsByScreen;
        ?? r92;
        String str;
        String str2;
        Iterator it2;
        String str3;
        Iterator it3;
        int iIntValue;
        Iterator it4;
        int i;
        InstalledAddon installedAddon;
        MobileAddonsFragment mobileAddonsFragment;
        boolean z;
        e6a e6aVar;
        ArrayList arrayList;
        ArrayList arrayList2;
        StremioCatalog stremioCatalog;
        String str4;
        String str5;
        RowConfigEntity rowConfigEntity;
        RowConfigDao rowConfigDaoM;
        ck1 ck1Var = ck1.a;
        int i2 = this.l;
        e6a e6aVar2 = e6a.a;
        ArrayList arrayList3 = this.o;
        ArrayList arrayList4 = this.n;
        boolean z2 = true;
        MobileAddonsFragment mobileAddonsFragment2 = this.m;
        switch (i2) {
            case 0:
                s38.b(obj);
                fg4 fg4Var = mobileAddonsFragment2.n;
                if (fg4Var == null) {
                    cr4.n("traktAccountRepository");
                    throw null;
                }
                this.l = 1;
                allAccountsSync = fg4Var.getAllAccountsSync(this);
                break;
                break;
            case 1:
                s38.b(obj);
                allAccountsSync = obj;
                List list = (List) allAccountsSync;
                if (list.isEmpty()) {
                    Am = y41.am("");
                } else {
                    List list2 = list;
                    Am = new ArrayList(y41.p(list2, 10));
                    Iterator it5 = list2.iterator();
                    while (it5.hasNext()) {
                        Am.add(((TraktAccount) it5.next()).getUserSlug());
                    }
                }
                int size = arrayList4.size();
                int iH = wo5.h(y41.p(arrayList3, 10));
                if (iH < 16) {
                    iH = 16;
                }
                LinkedHashMap linkedHashMap = new LinkedHashMap(iH);
                for (Object obj2 : arrayList3) {
                    linkedHashMap.put(obj2, Boxing.boxInt(size));
                }
                it = Am.iterator();
                r9 = Am;
                map = linkedHashMap;
                if (!it.hasNext()) {
                    String str6 = (String) it.next();
                    ScreenConfigRepository screenConfigRepository = mobileAddonsFragment2.l;
                    if (screenConfigRepository == null) {
                        cr4.n("screenConfigRepository");
                        throw null;
                    }
                    this.a = r9;
                    this.b = map;
                    this.c = it;
                    this.l = 2;
                    objCheckRowLimitsByScreen = screenConfigRepository.checkRowLimitsByScreen(str6, map, this);
                    r92 = r9;
                    if (objCheckRowLimitsByScreen != ck1Var) {
                        str = (String) objCheckRowLimitsByScreen;
                        r9 = r92;
                        if (str == null) {
                            m12 m12Var = sc2.a;
                            qm5 qm5Var = sm5.a;
                            y06 y06Var = new y06(mobileAddonsFragment2, str, null);
                            this.a = null;
                            this.b = null;
                            this.c = null;
                            this.l = 3;
                            if (wj0.f(qm5Var, y06Var, this) != ck1Var) {
                                return e6aVar2;
                            }
                        } else if (!it.hasNext()) {
                            Iterator it6 = r9.iterator();
                            if (!it6.hasNext()) {
                                str3 = (String) it6.next();
                                it2 = arrayList3.iterator();
                                if (!it2.hasNext()) {
                                    String str7 = (String) it2.next();
                                    RowConfigDao rowConfigDaoM2 = mobileAddonsFragment2.m();
                                    this.a = it6;
                                    this.b = str3;
                                    this.c = it2;
                                    this.d = str7;
                                    this.e = null;
                                    this.f = null;
                                    this.i = null;
                                    this.l = 4;
                                    Object rowCountForProfile = rowConfigDaoM2.getRowCountForProfile(str3, str7, this);
                                    if (rowCountForProfile != ck1Var) {
                                        it3 = it6;
                                        str2 = str7;
                                        iIntValue = ((Number) rowCountForProfile).intValue();
                                        it4 = arrayList4.iterator();
                                        i = 0;
                                        installedAddon = this.p;
                                        mobileAddonsFragment = mobileAddonsFragment2;
                                        if (!it4.hasNext()) {
                                            Object next = it4.next();
                                            z = z2;
                                            int i3 = i + 1;
                                            if (i < 0) {
                                                y41.bm();
                                                throw null;
                                            }
                                            StremioCatalog stremioCatalog2 = (StremioCatalog) next;
                                            e6aVar = e6aVar2;
                                            String instanceId = installedAddon.getInstanceId();
                                            int i4 = i;
                                            String type = stremioCatalog2.getType();
                                            arrayList = arrayList3;
                                            String id = stremioCatalog2.getId();
                                            arrayList2 = arrayList4;
                                            StringBuilder sb = new StringBuilder();
                                            sb.append(str3);
                                            String str8 = str3;
                                            sb.append("_addon_");
                                            sb.append(instanceId);
                                            sb.append("_");
                                            sb.append(type);
                                            String strU = n41.u(sb, "_", id, "_", str2);
                                            String name = stremioCatalog2.getName();
                                            if (name == null) {
                                                name = vw2.l(installedAddon.getDisplayName(), " - ", stremioCatalog2.getId());
                                            }
                                            String str9 = name;
                                            int i5 = iIntValue + i4 + 1;
                                            String type2 = stremioCatalog2.getType();
                                            if (cr4.b(type2, PlaybackProgress.TYPE_MOVIE)) {
                                                str5 = "movies";
                                            } else if (cr4.b(type2, "series")) {
                                                str5 = "shows";
                                            } else {
                                                stremioCatalog = stremioCatalog2;
                                                str4 = null;
                                                String instanceId2 = installedAddon.getInstanceId();
                                                String type3 = stremioCatalog.getType();
                                                String id2 = stremioCatalog.getId();
                                                String str10 = str2;
                                                StringBuilder sbM = fi7.m("addon_catalog:", instanceId2, ":", type3, ":");
                                                sbM.append(id2);
                                                rowConfigEntity = new RowConfigEntity(strU, str8, str10, str9, "addon_catalog", str4, "portrait", sbM.toString(), i5, i5, true, false, stremioCatalog.getEffectivePageSize(), false, null, null, null, 114688, null);
                                                str3 = str8;
                                                str2 = str10;
                                                rowConfigDaoM = mobileAddonsFragment.m();
                                                this.a = it3;
                                                this.b = str3;
                                                this.c = it2;
                                                this.d = str2;
                                                this.e = installedAddon;
                                                this.f = mobileAddonsFragment;
                                                this.i = it4;
                                                this.j = iIntValue;
                                                this.k = i3;
                                                this.l = 5;
                                                if (rowConfigDaoM.insert(rowConfigEntity, this) != ck1Var) {
                                                    i = i3;
                                                    z2 = z;
                                                    e6aVar2 = e6aVar;
                                                    arrayList3 = arrayList;
                                                    arrayList4 = arrayList2;
                                                    if (!it4.hasNext()) {
                                                        it6 = it3;
                                                        if (!it2.hasNext()) {
                                                            if (!it6.hasNext()) {
                                                                e6a e6aVar3 = e6aVar2;
                                                                m12 m12Var2 = sc2.a;
                                                                qm5 qm5Var2 = sm5.a;
                                                                z06 z06Var = new z06(mobileAddonsFragment2, arrayList4, arrayList3, null);
                                                                this.a = null;
                                                                this.b = null;
                                                                this.c = null;
                                                                this.d = null;
                                                                this.e = null;
                                                                this.f = null;
                                                                this.i = null;
                                                                this.l = 6;
                                                                if (wj0.f(qm5Var2, z06Var, this) != ck1Var) {
                                                                    return e6aVar3;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            str4 = str5;
                                            stremioCatalog = stremioCatalog2;
                                            String instanceId22 = installedAddon.getInstanceId();
                                            String type32 = stremioCatalog.getType();
                                            String id22 = stremioCatalog.getId();
                                            String str102 = str2;
                                            StringBuilder sbM2 = fi7.m("addon_catalog:", instanceId22, ":", type32, ":");
                                            sbM2.append(id22);
                                            rowConfigEntity = new RowConfigEntity(strU, str8, str102, str9, "addon_catalog", str4, "portrait", sbM2.toString(), i5, i5, true, false, stremioCatalog.getEffectivePageSize(), false, null, null, null, 114688, null);
                                            str3 = str8;
                                            str2 = str102;
                                            rowConfigDaoM = mobileAddonsFragment.m();
                                            this.a = it3;
                                            this.b = str3;
                                            this.c = it2;
                                            this.d = str2;
                                            this.e = installedAddon;
                                            this.f = mobileAddonsFragment;
                                            this.i = it4;
                                            this.j = iIntValue;
                                            this.k = i3;
                                            this.l = 5;
                                            if (rowConfigDaoM.insert(rowConfigEntity, this) != ck1Var) {
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    return ck1Var;
                }
                break;
            case 2:
                it = this.c;
                map = (Map) this.b;
                List list3 = (List) this.a;
                s38.b(obj);
                objCheckRowLimitsByScreen = obj;
                r92 = list3;
                str = (String) objCheckRowLimitsByScreen;
                r9 = r92;
                if (str == null) {
                }
                return ck1Var;
            case 3:
                s38.b(obj);
                return e6aVar2;
            case 4:
                str2 = this.d;
                it2 = this.c;
                str3 = (String) this.b;
                it3 = (Iterator) this.a;
                s38.b(obj);
                iIntValue = ((Number) obj).intValue();
                it4 = arrayList4.iterator();
                i = 0;
                installedAddon = this.p;
                mobileAddonsFragment = mobileAddonsFragment2;
                if (!it4.hasNext()) {
                }
                break;
            case 5:
                int i6 = this.k;
                int i7 = this.j;
                Iterator it7 = this.i;
                MobileAddonsFragment mobileAddonsFragment3 = this.f;
                InstalledAddon installedAddon2 = this.e;
                String str11 = this.d;
                Iterator it8 = this.c;
                String str12 = (String) this.b;
                Iterator it9 = (Iterator) this.a;
                s38.b(obj);
                i = i6;
                str2 = str11;
                mobileAddonsFragment = mobileAddonsFragment3;
                iIntValue = i7;
                str3 = str12;
                it3 = it9;
                it2 = it8;
                installedAddon = installedAddon2;
                it4 = it7;
                e6aVar = e6aVar2;
                arrayList = arrayList3;
                arrayList2 = arrayList4;
                z = true;
                z2 = z;
                e6aVar2 = e6aVar;
                arrayList3 = arrayList;
                arrayList4 = arrayList2;
                if (!it4.hasNext()) {
                }
                break;
            case 6:
                s38.b(obj);
                return e6aVar2;
            default:
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
    }
}
