package com.strmr.ps.data.repository;

import androidx.media3.extractor.ts.TsExtractor;
import com.strmr.ps.data.local.dao.TraktUserItemDao;
import com.strmr.ps.data.local.entity.TraktAccount;
import com.strmr.ps.data.model.ContentItem;
import com.strmr.ps.data.model.trakt.TraktMediaList;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.ik2;
import defpackage.q38;
import defpackage.s38;
import java.util.List;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\u0014\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0004\u001a\u000e\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00030\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0004\u0010\u0005"}, d2 = {"Lak1;", "Lq38;", "", "Lcom/strmr/ps/data/model/ContentItem;", "<anonymous>", "(Lak1;)Lq38;"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.data.repository.TraktMediaRepository$getMediaListPaged$2", f = "TraktMediaRepository.kt", i = {1, 2}, l = {59, 64, 66, TsExtractor.TS_SYNC_BYTE, 79}, m = "invokeSuspend", n = {"userSlug", "userSlug"}, s = {"L$0", "L$0"})
public final class TraktMediaRepository$getMediaListPaged$2 extends SuspendLambda implements gr3<ak1, Continuation<? super q38<? extends List<? extends ContentItem>>>, Object> {
    final /* synthetic */ TraktMediaList $category;
    final /* synthetic */ boolean $forceRefresh;
    final /* synthetic */ int $page;
    final /* synthetic */ int $pageSize;
    Object L$0;
    int label;
    final /* synthetic */ TraktMediaRepository this$0;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public TraktMediaRepository$getMediaListPaged$2(TraktMediaRepository traktMediaRepository, int i, TraktMediaList traktMediaList, boolean z, int i2, Continuation<? super TraktMediaRepository$getMediaListPaged$2> continuation) {
        super(2, continuation);
        this.this$0 = traktMediaRepository;
        this.$page = i;
        this.$category = traktMediaList;
        this.$forceRefresh = z;
        this.$pageSize = i2;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation<e6a> create(Object obj, Continuation<?> continuation) {
        return new TraktMediaRepository$getMediaListPaged$2(this.this$0, this.$page, this.$category, this.$forceRefresh, this.$pageSize, continuation);
    }

    @Override // defpackage.gr3
    public final Object invoke(ak1 ak1Var, Continuation<? super q38<? extends List<ContentItem>>> continuation) {
        return ((TraktMediaRepository$getMediaListPaged$2) create(ak1Var, continuation)).invokeSuspend(e6a.a);
    }

    /* JADX WARN: Code restructure failed: missing block: B:41:0x00d6, code lost:
    
        if (r0 != r7) goto L43;
     */
    /* JADX WARN: Removed duplicated region for block: B:33:0x008d A[PHI: r0
      0x008d: PHI (r0v9 java.lang.String) = (r0v7 java.lang.String), (r0v8 java.lang.String), (r0v8 java.lang.String), (r0v24 java.lang.String) binds: [B:25:0x0061, B:35:0x009d, B:31:0x008a, B:13:0x002a] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:40:0x00ca A[PHI: r0
      0x00ca: PHI (r0v15 java.lang.Object) = (r0v14 java.lang.Object), (r0v25 java.lang.Object) binds: [B:38:0x00c7, B:12:0x0024] A[DONT_GENERATE, DONT_INLINE]] */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        Object activeAccount;
        String userSlug;
        Object objCountItems;
        TraktSyncRepository traktSyncRepository;
        Object itemsPaged;
        Object objBuildContentItems;
        ck1 ck1Var = ck1.a;
        int i = this.label;
        if (i == 0) {
            s38.b(obj);
            TraktAccountRepository traktAccountRepository = this.this$0.accountRepository;
            this.label = 1;
            activeAccount = traktAccountRepository.getActiveAccount(this);
            if (activeAccount != ck1Var) {
            }
            return ck1Var;
        }
        if (i == 1) {
            s38.b(obj);
            activeAccount = obj;
        } else {
            if (i == 2) {
                userSlug = (String) this.L$0;
                s38.b(obj);
                objCountItems = obj;
                int iIntValue = ((Number) objCountItems).intValue();
                if (!this.$forceRefresh || iIntValue == 0) {
                    traktSyncRepository = this.this$0.traktSyncRepository;
                    this.L$0 = userSlug;
                    this.label = 3;
                    if (TraktSyncRepository.syncAll$default(traktSyncRepository, null, this, 1, null) != ck1Var) {
                    }
                    return ck1Var;
                }
                String str = userSlug;
                int i2 = (this.$page - 1) * this.$pageSize;
                TraktUserItemDao traktUserItemDao = this.this$0.traktUserItemDao;
                String listType = this.$category.getListType();
                String itemType = this.$category.getItemType();
                int i3 = this.$pageSize;
                this.L$0 = null;
                this.label = 4;
                itemsPaged = traktUserItemDao.getItemsPaged(listType, itemType, str, i3, i2, this);
                if (itemsPaged != ck1Var) {
                }
                return ck1Var;
            }
            if (i == 3) {
                userSlug = (String) this.L$0;
                s38.b(obj);
                String str2 = userSlug;
                int i22 = (this.$page - 1) * this.$pageSize;
                TraktUserItemDao traktUserItemDao2 = this.this$0.traktUserItemDao;
                String listType2 = this.$category.getListType();
                String itemType2 = this.$category.getItemType();
                int i32 = this.$pageSize;
                this.L$0 = null;
                this.label = 4;
                itemsPaged = traktUserItemDao2.getItemsPaged(listType2, itemType2, str2, i32, i22, this);
                if (itemsPaged != ck1Var) {
                    TraktMediaRepository traktMediaRepository = this.this$0;
                    TraktMediaList traktMediaList = this.$category;
                    this.label = 5;
                    objBuildContentItems = traktMediaRepository.buildContentItems((List) itemsPaged, traktMediaList, this);
                }
                return ck1Var;
            }
            if (i != 4) {
                if (i != 5) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
                objBuildContentItems = obj;
                return new q38((List) objBuildContentItems);
            }
            s38.b(obj);
            itemsPaged = obj;
            TraktMediaRepository traktMediaRepository2 = this.this$0;
            TraktMediaList traktMediaList2 = this.$category;
            this.label = 5;
            objBuildContentItems = traktMediaRepository2.buildContentItems((List) itemsPaged, traktMediaList2, this);
        }
        TraktAccount traktAccount = (TraktAccount) activeAccount;
        if (traktAccount == null || (userSlug = traktAccount.getUserSlug()) == null) {
            return new q38(ik2.a);
        }
        if (this.$page == 1) {
            TraktUserItemDao traktUserItemDao3 = this.this$0.traktUserItemDao;
            String listType3 = this.$category.getListType();
            String itemType3 = this.$category.getItemType();
            this.L$0 = userSlug;
            this.label = 2;
            objCountItems = traktUserItemDao3.countItems(listType3, itemType3, userSlug, this);
            if (objCountItems != ck1Var) {
                int iIntValue2 = ((Number) objCountItems).intValue();
                if (!this.$forceRefresh) {
                }
                traktSyncRepository = this.this$0.traktSyncRepository;
                this.L$0 = userSlug;
                this.label = 3;
                if (TraktSyncRepository.syncAll$default(traktSyncRepository, null, this, 1, null) != ck1Var) {
                    String str22 = userSlug;
                    int i222 = (this.$page - 1) * this.$pageSize;
                    TraktUserItemDao traktUserItemDao22 = this.this$0.traktUserItemDao;
                    String listType22 = this.$category.getListType();
                    String itemType22 = this.$category.getItemType();
                    int i322 = this.$pageSize;
                    this.L$0 = null;
                    this.label = 4;
                    itemsPaged = traktUserItemDao22.getItemsPaged(listType22, itemType22, str22, i322, i222, this);
                    if (itemsPaged != ck1Var) {
                    }
                }
            }
        }
        return ck1Var;
    }
}
