package com.strmr.ps.ui.usercollection;

import android.util.Log;
import androidx.media3.extractor.ts.PsExtractor;
import com.strmr.ps.data.model.trakt.TraktListItem;
import com.strmr.ps.ui.usercollection.UserCollectionContentViewModel;
import defpackage.ak1;
import defpackage.bk1;
import defpackage.ck1;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.pw7;
import defpackage.q07;
import defpackage.s38;
import defpackage.vx8;
import defpackage.y41;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.CancellationException;
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.usercollection.UserCollectionContentViewModel$loadMore$2", f = "UserCollectionContentViewModel.kt", i = {0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5}, l = {173, 180, PsExtractor.PRIVATE_STREAM_1, 200, 206, 214}, m = "invokeSuspend", n = {"state", "state", "state", "batch", "state", "username", "listId", "newItems", "state", "newItems", "state"}, s = {"L$1", "L$1", "L$1", "L$2", "L$1", "L$2", "L$3", "L$4", "L$1", "L$2", "L$1"})
@vx8
final class x extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
    public Iterator a;
    public Object b;
    public Object c;
    public String d;
    public ArrayList e;
    public int f;
    public final /* synthetic */ UserCollectionContentViewModel i;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public x(UserCollectionContentViewModel userCollectionContentViewModel, Continuation continuation) {
        super(2, continuation);
        this.i = userCollectionContentViewModel;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        return new x(this.i, continuation);
    }

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

    /* JADX WARN: Code restructure failed: missing block: B:103:0x0270, code lost:
    
        if (r2 == r0) goto L104;
     */
    /* JADX WARN: Removed duplicated region for block: B:34:0x009d A[Catch: all -> 0x002c, Exception -> 0x002f, CancellationException -> 0x0032, TRY_LEAVE, TryCatch #3 {CancellationException -> 0x0032, Exception -> 0x002f, blocks: (B:7:0x0020, B:105:0x0273, B:32:0x0097, B:34:0x009d, B:37:0x00b0, B:39:0x00b6, B:42:0x00d3, B:43:0x00dd, B:45:0x00e3, B:48:0x0101, B:49:0x010b, B:51:0x0111, B:54:0x0137, B:55:0x014d, B:58:0x0156, B:61:0x015b, B:63:0x0164, B:66:0x017b, B:68:0x0183, B:69:0x0185, B:71:0x018e, B:72:0x01a2, B:74:0x01a8, B:75:0x01c1, B:78:0x01cc, B:80:0x01d0, B:84:0x01e8, B:86:0x01f0, B:87:0x01f2, B:89:0x01fb, B:90:0x0212, B:92:0x0218, B:93:0x022b, B:97:0x0235, B:99:0x023e, B:101:0x024b, B:102:0x0258, B:107:0x0281, B:16:0x003f, B:19:0x0056, B:22:0x0067, B:25:0x0076, B:28:0x0085, B:31:0x0090), top: B:116:0x000f, outer: #2 }] */
    /* JADX WARN: Removed duplicated region for block: B:68:0x0183 A[Catch: all -> 0x002c, Exception -> 0x002f, CancellationException -> 0x0032, TryCatch #3 {CancellationException -> 0x0032, Exception -> 0x002f, blocks: (B:7:0x0020, B:105:0x0273, B:32:0x0097, B:34:0x009d, B:37:0x00b0, B:39:0x00b6, B:42:0x00d3, B:43:0x00dd, B:45:0x00e3, B:48:0x0101, B:49:0x010b, B:51:0x0111, B:54:0x0137, B:55:0x014d, B:58:0x0156, B:61:0x015b, B:63:0x0164, B:66:0x017b, B:68:0x0183, B:69:0x0185, B:71:0x018e, B:72:0x01a2, B:74:0x01a8, B:75:0x01c1, B:78:0x01cc, B:80:0x01d0, B:84:0x01e8, B:86:0x01f0, B:87:0x01f2, B:89:0x01fb, B:90:0x0212, B:92:0x0218, B:93:0x022b, B:97:0x0235, B:99:0x023e, B:101:0x024b, B:102:0x0258, B:107:0x0281, B:16:0x003f, B:19:0x0056, B:22:0x0067, B:25:0x0076, B:28:0x0085, B:31:0x0090), top: B:116:0x000f, outer: #2 }] */
    /* JADX WARN: Removed duplicated region for block: B:71:0x018e A[Catch: all -> 0x002c, Exception -> 0x002f, CancellationException -> 0x0032, TryCatch #3 {CancellationException -> 0x0032, Exception -> 0x002f, blocks: (B:7:0x0020, B:105:0x0273, B:32:0x0097, B:34:0x009d, B:37:0x00b0, B:39:0x00b6, B:42:0x00d3, B:43:0x00dd, B:45:0x00e3, B:48:0x0101, B:49:0x010b, B:51:0x0111, B:54:0x0137, B:55:0x014d, B:58:0x0156, B:61:0x015b, B:63:0x0164, B:66:0x017b, B:68:0x0183, B:69:0x0185, B:71:0x018e, B:72:0x01a2, B:74:0x01a8, B:75:0x01c1, B:78:0x01cc, B:80:0x01d0, B:84:0x01e8, B:86:0x01f0, B:87:0x01f2, B:89:0x01fb, B:90:0x0212, B:92:0x0218, B:93:0x022b, B:97:0x0235, B:99:0x023e, B:101:0x024b, B:102:0x0258, B:107:0x0281, B:16:0x003f, B:19:0x0056, B:22:0x0067, B:25:0x0076, B:28:0x0085, B:31:0x0090), top: B:116:0x000f, outer: #2 }] */
    /* JADX WARN: Removed duplicated region for block: B:80:0x01d0 A[Catch: all -> 0x002c, Exception -> 0x002f, CancellationException -> 0x0032, TryCatch #3 {CancellationException -> 0x0032, Exception -> 0x002f, blocks: (B:7:0x0020, B:105:0x0273, B:32:0x0097, B:34:0x009d, B:37:0x00b0, B:39:0x00b6, B:42:0x00d3, B:43:0x00dd, B:45:0x00e3, B:48:0x0101, B:49:0x010b, B:51:0x0111, B:54:0x0137, B:55:0x014d, B:58:0x0156, B:61:0x015b, B:63:0x0164, B:66:0x017b, B:68:0x0183, B:69:0x0185, B:71:0x018e, B:72:0x01a2, B:74:0x01a8, B:75:0x01c1, B:78:0x01cc, B:80:0x01d0, B:84:0x01e8, B:86:0x01f0, B:87:0x01f2, B:89:0x01fb, B:90:0x0212, B:92:0x0218, B:93:0x022b, B:97:0x0235, B:99:0x023e, B:101:0x024b, B:102:0x0258, B:107:0x0281, B:16:0x003f, B:19:0x0056, B:22:0x0067, B:25:0x0076, B:28:0x0085, B:31:0x0090), top: B:116:0x000f, outer: #2 }] */
    /* JADX WARN: Removed duplicated region for block: B:86:0x01f0 A[Catch: all -> 0x002c, Exception -> 0x002f, CancellationException -> 0x0032, TryCatch #3 {CancellationException -> 0x0032, Exception -> 0x002f, blocks: (B:7:0x0020, B:105:0x0273, B:32:0x0097, B:34:0x009d, B:37:0x00b0, B:39:0x00b6, B:42:0x00d3, B:43:0x00dd, B:45:0x00e3, B:48:0x0101, B:49:0x010b, B:51:0x0111, B:54:0x0137, B:55:0x014d, B:58:0x0156, B:61:0x015b, B:63:0x0164, B:66:0x017b, B:68:0x0183, B:69:0x0185, B:71:0x018e, B:72:0x01a2, B:74:0x01a8, B:75:0x01c1, B:78:0x01cc, B:80:0x01d0, B:84:0x01e8, B:86:0x01f0, B:87:0x01f2, B:89:0x01fb, B:90:0x0212, B:92:0x0218, B:93:0x022b, B:97:0x0235, B:99:0x023e, B:101:0x024b, B:102:0x0258, B:107:0x0281, B:16:0x003f, B:19:0x0056, B:22:0x0067, B:25:0x0076, B:28:0x0085, B:31:0x0090), top: B:116:0x000f, outer: #2 }] */
    /* JADX WARN: Removed duplicated region for block: B:89:0x01fb A[Catch: all -> 0x002c, Exception -> 0x002f, CancellationException -> 0x0032, TryCatch #3 {CancellationException -> 0x0032, Exception -> 0x002f, blocks: (B:7:0x0020, B:105:0x0273, B:32:0x0097, B:34:0x009d, B:37:0x00b0, B:39:0x00b6, B:42:0x00d3, B:43:0x00dd, B:45:0x00e3, B:48:0x0101, B:49:0x010b, B:51:0x0111, B:54:0x0137, B:55:0x014d, B:58:0x0156, B:61:0x015b, B:63:0x0164, B:66:0x017b, B:68:0x0183, B:69:0x0185, B:71:0x018e, B:72:0x01a2, B:74:0x01a8, B:75:0x01c1, B:78:0x01cc, B:80:0x01d0, B:84:0x01e8, B:86:0x01f0, B:87:0x01f2, B:89:0x01fb, B:90:0x0212, B:92:0x0218, B:93:0x022b, B:97:0x0235, B:99:0x023e, B:101:0x024b, B:102:0x0258, B:107:0x0281, B:16:0x003f, B:19:0x0056, B:22:0x0067, B:25:0x0076, B:28:0x0085, B:31:0x0090), top: B:116:0x000f, outer: #2 }] */
    /* JADX WARN: Removed duplicated region for block: B:94:0x022f  */
    /* JADX WARN: Removed duplicated region for block: B:96:0x0233  */
    /* JADX WARN: Removed duplicated region for block: B:99:0x023e A[Catch: all -> 0x002c, Exception -> 0x002f, CancellationException -> 0x0032, TryCatch #3 {CancellationException -> 0x0032, Exception -> 0x002f, blocks: (B:7:0x0020, B:105:0x0273, B:32:0x0097, B:34:0x009d, B:37:0x00b0, B:39:0x00b6, B:42:0x00d3, B:43:0x00dd, B:45:0x00e3, B:48:0x0101, B:49:0x010b, B:51:0x0111, B:54:0x0137, B:55:0x014d, B:58:0x0156, B:61:0x015b, B:63:0x0164, B:66:0x017b, B:68:0x0183, B:69:0x0185, B:71:0x018e, B:72:0x01a2, B:74:0x01a8, B:75:0x01c1, B:78:0x01cc, B:80:0x01d0, B:84:0x01e8, B:86:0x01f0, B:87:0x01f2, B:89:0x01fb, B:90:0x0212, B:92:0x0218, B:93:0x022b, B:97:0x0235, B:99:0x023e, B:101:0x024b, B:102:0x0258, B:107:0x0281, B:16:0x003f, B:19:0x0056, B:22:0x0067, B:25:0x0076, B:28:0x0085, B:31:0x0090), top: B:116:0x000f, outer: #2 }] */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:103:0x0270 -> B:105:0x0273). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:57:0x0151 -> B:106:0x027c). Please report as a decompilation issue!!! */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:98:0x023c -> B:106:0x027c). 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) {
        Iterator it;
        String str;
        String str2;
        UserCollectionContentViewModel.b bVar;
        Object objC;
        UserCollectionContentViewModel.b bVar2;
        Iterator it2;
        Object objD;
        boolean z;
        ArrayList arrayList;
        int i;
        List list;
        Object objC2;
        List list2;
        List list3;
        ArrayList arrayList2;
        ArrayList arrayList3;
        List list4;
        ck1 ck1Var = ck1.a;
        int i2 = this.f;
        int i3 = 10;
        boolean z2 = true;
        z2 = true;
        z2 = true;
        z2 = true;
        z2 = true;
        UserCollectionContentViewModel userCollectionContentViewModel = this.i;
        try {
            try {
            } catch (CancellationException e) {
                throw e;
            } catch (Exception e2) {
                Log.e("UserCollectionVM", "Error loading more content", e2);
            }
            switch (i2) {
                case 0:
                    s38.b(obj);
                    it = userCollectionContentViewModel.q.iterator();
                    while (it.hasNext()) {
                        bVar = (UserCollectionContentViewModel.b) it.next();
                        boolean zA = bVar.a();
                        ArrayList arrayList4 = bVar.n;
                        ArrayList arrayList5 = bVar.m;
                        ArrayList arrayList6 = bVar.l;
                        if (zA) {
                            if (!arrayList6.isEmpty()) {
                                ArrayList arrayListB = UserCollectionContentViewModel.b(userCollectionContentViewModel, arrayList6);
                                this.a = it;
                                this.b = bVar;
                                this.c = null;
                                this.d = null;
                                this.e = null;
                                this.f = z2 ? 1 : 0;
                                Object objC3 = bk1.c(new l(arrayListB, userCollectionContentViewModel, null), this);
                                if (objC3 == ck1Var) {
                                    return ck1Var;
                                }
                                bVar.k.addAll((List) objC3);
                            } else {
                                if (arrayList5.isEmpty()) {
                                    if (arrayList4.isEmpty()) {
                                        str2 = bVar.e;
                                        if (str2 != null && (str = bVar.f) != null) {
                                            ArrayList arrayList7 = new ArrayList();
                                            arrayList = arrayList7;
                                            if (bVar.i) {
                                                int i4 = bVar.g;
                                                this.a = it;
                                                this.b = bVar;
                                                this.c = str2;
                                                this.d = str;
                                                this.e = arrayList7;
                                                this.f = 4;
                                                objC = UserCollectionContentViewModel.c(userCollectionContentViewModel, str2, str, i4, this);
                                                arrayList3 = arrayList7;
                                                if (objC == ck1Var) {
                                                }
                                                list4 = (List) objC;
                                                if (list4.size() < 20) {
                                                    bVar.i = false;
                                                }
                                                arrayList = arrayList3;
                                                if (list4.isEmpty()) {
                                                    bVar.g += z2 ? 1 : 0;
                                                    List list5 = list4;
                                                    ArrayList arrayList8 = new ArrayList(y41.p(list5, i3));
                                                    Iterator it3 = list5.iterator();
                                                    while (it3.hasNext()) {
                                                        boolean z3 = z2;
                                                        arrayList8.add(new q07((TraktListItem) it3.next(), Boxing.boxBoolean(z3)));
                                                        z2 = z3 ? 1 : 0;
                                                    }
                                                    z = z2;
                                                    arrayList3.addAll(arrayList8);
                                                    arrayList2 = arrayList3;
                                                }
                                                String str3 = str;
                                                bVar2 = bVar;
                                                if (bVar2.j) {
                                                    int i5 = bVar2.h;
                                                    this.a = it;
                                                    this.b = bVar2;
                                                    this.c = arrayList2;
                                                    this.d = null;
                                                    this.e = null;
                                                    this.f = 5;
                                                    objD = UserCollectionContentViewModel.d(userCollectionContentViewModel, str2, str3, i5, this);
                                                    if (objD != ck1Var) {
                                                        it2 = it;
                                                        list2 = arrayList2;
                                                        list3 = (List) objD;
                                                        if (list3.size() < 20) {
                                                            bVar2.j = false;
                                                        }
                                                        if (list3.isEmpty()) {
                                                            bVar2.h++;
                                                            List list6 = list3;
                                                            i = 10;
                                                            ArrayList arrayList9 = new ArrayList(y41.p(list6, 10));
                                                            Iterator it4 = list6.iterator();
                                                            while (it4.hasNext()) {
                                                                arrayList9.add(new q07((TraktListItem) it4.next(), Boxing.boxBoolean(false)));
                                                            }
                                                            list2.addAll(arrayList9);
                                                        } else {
                                                            i = 10;
                                                        }
                                                        it = it2;
                                                        list = list2;
                                                        if (!list.isEmpty()) {
                                                            List listBk = y41.bk(list, 20);
                                                            if (list.size() > 20) {
                                                                bVar2.l.addAll(y41.u(list, 20));
                                                            }
                                                            this.a = it;
                                                            this.b = bVar2;
                                                            this.c = null;
                                                            this.d = null;
                                                            this.e = null;
                                                            this.f = 6;
                                                            pw7 pw7Var = UserCollectionContentViewModel.u;
                                                            objC2 = bk1.c(new l(listBk, userCollectionContentViewModel, null), this);
                                                        }
                                                        i3 = i;
                                                        z2 = z;
                                                        while (it.hasNext()) {
                                                        }
                                                        break;
                                                    }
                                                } else {
                                                    i = 10;
                                                    list = arrayList2;
                                                    if (!list.isEmpty()) {
                                                    }
                                                    i3 = i;
                                                    z2 = z;
                                                    while (it.hasNext()) {
                                                    }
                                                }
                                            }
                                            z = z2;
                                            arrayList2 = arrayList;
                                            String str32 = str;
                                            bVar2 = bVar;
                                            if (bVar2.j) {
                                            }
                                        }
                                    } else {
                                        ArrayList arrayListB2 = UserCollectionContentViewModel.b(userCollectionContentViewModel, arrayList4);
                                        bVar.k.addAll(arrayListB2);
                                        userCollectionContentViewModel.q();
                                        this.a = it;
                                        this.b = bVar;
                                        this.c = arrayListB2;
                                        this.d = null;
                                        this.e = null;
                                        this.f = 3;
                                        Object objC4 = bk1.c(new i(arrayListB2, userCollectionContentViewModel, null), this);
                                        if (objC4 != ck1Var) {
                                            bVar.k.removeAll(y41.br(arrayListB2));
                                            bVar.k.addAll((List) objC4);
                                        }
                                    }
                                    return ck1Var;
                                }
                                ArrayList arrayListB3 = UserCollectionContentViewModel.b(userCollectionContentViewModel, arrayList5);
                                this.a = it;
                                this.b = bVar;
                                this.c = null;
                                this.d = null;
                                this.e = null;
                                this.f = 2;
                                Object objC5 = bk1.c(new g(arrayListB3, userCollectionContentViewModel, null), this);
                                if (objC5 == ck1Var) {
                                    return ck1Var;
                                }
                                bVar.k.addAll((List) objC5);
                            }
                        }
                        i = i3;
                        z = z2 ? 1 : 0;
                        i3 = i;
                        z2 = z;
                        while (it.hasNext()) {
                        }
                    }
                    pw7 pw7Var2 = UserCollectionContentViewModel.u;
                    userCollectionContentViewModel.q();
                    return e6a.a;
                case 1:
                    UserCollectionContentViewModel.b bVar3 = (UserCollectionContentViewModel.b) this.b;
                    Iterator it5 = this.a;
                    s38.b(obj);
                    it = it5;
                    bVar3.k.addAll((List) obj);
                    while (it.hasNext()) {
                    }
                    pw7 pw7Var22 = UserCollectionContentViewModel.u;
                    userCollectionContentViewModel.q();
                    return e6a.a;
                case 2:
                    UserCollectionContentViewModel.b bVar4 = (UserCollectionContentViewModel.b) this.b;
                    Iterator it6 = this.a;
                    s38.b(obj);
                    it = it6;
                    bVar4.k.addAll((List) obj);
                    while (it.hasNext()) {
                    }
                    pw7 pw7Var222 = UserCollectionContentViewModel.u;
                    userCollectionContentViewModel.q();
                    return e6a.a;
                case 3:
                    List list7 = (List) this.c;
                    UserCollectionContentViewModel.b bVar5 = (UserCollectionContentViewModel.b) this.b;
                    Iterator it7 = this.a;
                    s38.b(obj);
                    it = it7;
                    bVar5.k.removeAll(y41.br(list7));
                    bVar5.k.addAll((List) obj);
                    while (it.hasNext()) {
                    }
                    pw7 pw7Var2222 = UserCollectionContentViewModel.u;
                    userCollectionContentViewModel.q();
                    return e6a.a;
                case 4:
                    ArrayList arrayList10 = this.e;
                    str = this.d;
                    str2 = (String) this.c;
                    bVar = (UserCollectionContentViewModel.b) this.b;
                    it = this.a;
                    s38.b(obj);
                    objC = obj;
                    arrayList3 = arrayList10;
                    list4 = (List) objC;
                    if (list4.size() < 20) {
                    }
                    arrayList = arrayList3;
                    if (list4.isEmpty()) {
                        z = z2;
                        arrayList2 = arrayList;
                    }
                    String str322 = str;
                    bVar2 = bVar;
                    if (bVar2.j) {
                    }
                    break;
                case 5:
                    List list8 = (List) this.c;
                    bVar2 = (UserCollectionContentViewModel.b) this.b;
                    it2 = this.a;
                    s38.b(obj);
                    objD = obj;
                    z = true;
                    list2 = list8;
                    list3 = (List) objD;
                    if (list3.size() < 20) {
                    }
                    if (list3.isEmpty()) {
                    }
                    it = it2;
                    list = list2;
                    if (!list.isEmpty()) {
                    }
                    i3 = i;
                    z2 = z;
                    while (it.hasNext()) {
                    }
                    pw7 pw7Var22222 = UserCollectionContentViewModel.u;
                    userCollectionContentViewModel.q();
                    return e6a.a;
                case 6:
                    UserCollectionContentViewModel.b bVar6 = (UserCollectionContentViewModel.b) this.b;
                    Iterator it8 = this.a;
                    s38.b(obj);
                    i = 10;
                    z = true;
                    it = it8;
                    bVar2 = bVar6;
                    objC2 = obj;
                    bVar2.k.addAll((List) objC2);
                    i3 = i;
                    z2 = z;
                    while (it.hasNext()) {
                    }
                    pw7 pw7Var222222 = UserCollectionContentViewModel.u;
                    userCollectionContentViewModel.q();
                    return e6a.a;
                default:
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
        } finally {
            userCollectionContentViewModel.r = false;
        }
    }
}
