package com.strmr.ps.data.repository;

import android.util.Log;
import com.strmr.ps.data.model.ContentItem;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.ik2;
import defpackage.q38;
import defpackage.s38;
import defpackage.sq3;
import java.util.Collection;
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.ContentRepository$getPagedContent$2", f = "ContentRepository.kt", i = {1, 2, 3, 4}, l = {182, 183, 209, 211, 222}, m = "invokeSuspend", n = {"cachedPage", "cachedPage", "freshData", "e"}, s = {"L$0", "L$0", "L$0", "L$0"})
public final class ContentRepository$getPagedContent$2 extends SuspendLambda implements gr3<ak1, Continuation<? super q38<? extends List<? extends ContentItem>>>, Object> {
    final /* synthetic */ String $category;
    final /* synthetic */ sq3<Continuation<? super List<ContentItem>>, Object> $fetcher;
    final /* synthetic */ boolean $forceRefresh;
    final /* synthetic */ int $page;
    final /* synthetic */ int $pageSize;
    Object L$0;
    int label;
    final /* synthetic */ ContentRepository this$0;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    /* JADX WARN: Multi-variable type inference failed */
    public ContentRepository$getPagedContent$2(ContentRepository contentRepository, String str, int i, int i2, boolean z, sq3<? super Continuation<? super List<ContentItem>>, ? extends Object> sq3Var, Continuation<? super ContentRepository$getPagedContent$2> continuation) {
        super(2, continuation);
        this.this$0 = contentRepository;
        this.$category = str;
        this.$page = i;
        this.$pageSize = i2;
        this.$forceRefresh = z;
        this.$fetcher = sq3Var;
    }

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

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

    /* JADX WARN: Code restructure failed: missing block: B:67:0x0123, code lost:
    
        if (r12 == r1) goto L68;
     */
    /* JADX WARN: Removed duplicated region for block: B:34:0x008b  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x008c  */
    /* JADX WARN: Removed duplicated region for block: B:47:0x00b2  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x00bf A[Catch: Exception -> 0x00df, TRY_LEAVE, TryCatch #0 {Exception -> 0x00df, blocks: (B:48:0x00b3, B:50:0x00bf, B:32:0x007d, B:36:0x008d, B:45:0x00a3, B:28:0x0065, B:25:0x004e), top: B:75:0x004e }] */
    /* JADX WARN: Removed duplicated region for block: B:61:0x00e2 A[Catch: Exception -> 0x00dc, TryCatch #2 {Exception -> 0x00dc, blocks: (B:56:0x00d8, B:52:0x00d0, B:61:0x00e2, B:64:0x00ed), top: B:79:0x0009 }] */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        ContentRepository$getPagedContent$2 contentRepository$getPagedContent$2;
        Object obj2;
        List list;
        List list2;
        List<ContentItem> list3;
        List<ContentItem> list4;
        ck1 ck1Var = ck1.a;
        int i = this.label;
        boolean z = true;
        try {
            try {
            } catch (Exception e) {
                e = e;
            }
        } catch (Exception e2) {
            e = e2;
            contentRepository$getPagedContent$2 = this;
        }
        if (i == 0) {
            s38.b(obj);
            try {
                CacheRepository cacheRepository = this.this$0.cacheRepository;
                String str = this.$category;
                int i2 = this.$page;
                int i3 = this.$pageSize;
                this.label = 1;
                obj = cacheRepository.getCachedPage(str, i2, i3, this);
                if (obj != ck1Var) {
                }
            } catch (Exception e3) {
                e = e3;
                contentRepository$getPagedContent$2 = this;
                Log.e("ContentRepository", "Error fetching " + contentRepository$getPagedContent$2.$category + " page " + contentRepository$getPagedContent$2.$page, e);
                CacheRepository cacheRepository2 = contentRepository$getPagedContent$2.this$0.cacheRepository;
                String str2 = contentRepository$getPagedContent$2.$category;
                int i4 = contentRepository$getPagedContent$2.$page;
                int i5 = contentRepository$getPagedContent$2.$pageSize;
                contentRepository$getPagedContent$2.L$0 = e;
                contentRepository$getPagedContent$2.label = 5;
                obj = cacheRepository2.getCachedPage(str2, i4, i5, this);
            }
            return ck1Var;
        }
        if (i == 1) {
            s38.b(obj);
        } else {
            if (i != 2) {
                if (i != 3) {
                    if (i == 4) {
                        List<ContentItem> list5 = (List) this.L$0;
                        s38.b(obj);
                        list4 = list5;
                        list4.size();
                        obj2 = list4;
                        return new q38(obj2);
                    }
                    if (i != 5) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    e = (Exception) this.L$0;
                    s38.b(obj);
                    Object objA = (List) obj;
                    if (((Collection) objA).isEmpty()) {
                        objA = s38.a(e);
                    }
                    obj2 = objA;
                    return new q38(obj2);
                }
                List list6 = (List) this.L$0;
                s38.b(obj);
                list2 = list6;
                list3 = (List) obj;
                if (list3.isEmpty()) {
                    obj2 = !list2.isEmpty() ? list2 : ik2.a;
                    return new q38(obj2);
                }
                CacheRepository cacheRepository3 = this.this$0.cacheRepository;
                String str3 = this.$category;
                int i6 = this.$page;
                int i7 = this.$pageSize;
                this.L$0 = list3;
                this.label = 4;
                if (cacheRepository3.cacheContentPage(str3, list3, i6, i7, this) == ck1Var) {
                    return ck1Var;
                }
                list4 = list3;
                list4.size();
                obj2 = list4;
                return new q38(obj2);
            }
            List list7 = (List) this.L$0;
            s38.b(obj);
            list = list7;
            boolean zBooleanValue = ((Boolean) obj).booleanValue();
            if (list.size() >= this.$pageSize) {
                z = false;
            }
            if (this.$forceRefresh && z && zBooleanValue) {
                list.size();
                try {
                    return new q38(list);
                } catch (Exception e4) {
                    contentRepository$getPagedContent$2 = this;
                    e = e4;
                    Log.e("ContentRepository", "Error fetching " + contentRepository$getPagedContent$2.$category + " page " + contentRepository$getPagedContent$2.$page, e);
                    CacheRepository cacheRepository22 = contentRepository$getPagedContent$2.this$0.cacheRepository;
                    String str22 = contentRepository$getPagedContent$2.$category;
                    int i42 = contentRepository$getPagedContent$2.$page;
                    int i52 = contentRepository$getPagedContent$2.$pageSize;
                    contentRepository$getPagedContent$2.L$0 = e;
                    contentRepository$getPagedContent$2.label = 5;
                    obj = cacheRepository22.getCachedPage(str22, i42, i52, this);
                }
            } else {
                list.size();
                sq3<Continuation<? super List<ContentItem>>, Object> sq3Var = this.$fetcher;
                this.L$0 = list;
                this.label = 3;
                obj = sq3Var.invoke(this);
                list2 = list;
                if (obj == ck1Var) {
                    return ck1Var;
                }
                list3 = (List) obj;
                if (list3.isEmpty()) {
                }
            }
        }
        List list8 = (List) obj;
        CacheRepository cacheRepository4 = this.this$0.cacheRepository;
        String str4 = this.$category;
        this.L$0 = list8;
        this.label = 2;
        Object objIsCacheFresh = cacheRepository4.isCacheFresh(str4, this);
        if (objIsCacheFresh == ck1Var) {
            return ck1Var;
        }
        list = list8;
        obj = objIsCacheFresh;
        boolean zBooleanValue2 = ((Boolean) obj).booleanValue();
        if (list.size() >= this.$pageSize) {
        }
        if (this.$forceRefresh) {
        }
        list.size();
        sq3<Continuation<? super List<ContentItem>>, Object> sq3Var2 = this.$fetcher;
        this.L$0 = list;
        this.label = 3;
        obj = sq3Var2.invoke(this);
        list2 = list;
        if (obj == ck1Var) {
        }
        list3 = (List) obj;
        if (list3.isEmpty()) {
        }
    }
}
