package com.strmr.ps.ui.settings.viewmodel;

import androidx.media3.extractor.text.ttml.TtmlNode;
import com.strmr.ps.data.local.entity.RowConfigEntity;
import com.strmr.ps.data.repository.ScreenConfigRepository;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.h2a;
import defpackage.ik2;
import defpackage.re6;
import defpackage.s38;
import defpackage.vx8;
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\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.viewmodel.RowCustomizationViewModel$addPredefinedRow$1", f = "RowCustomizationViewModel.kt", i = {1, 2}, l = {231, 246, 252, 277}, m = "invokeSuspend", n = {"profileSlug", "profileSlug"}, s = {"L$0", "L$0"})
@vx8
final class a extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
    public String a;
    public int b;
    public final /* synthetic */ RowCustomizationViewModel c;
    public final /* synthetic */ String d;
    public final /* synthetic */ ScreenConfigRepository.ScreenType e;
    public final /* synthetic */ String f;
    public final /* synthetic */ String i;
    public final /* synthetic */ String j;
    public final /* synthetic */ String k;
    public final /* synthetic */ boolean l;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public a(RowCustomizationViewModel rowCustomizationViewModel, String str, ScreenConfigRepository.ScreenType screenType, String str2, String str3, String str4, String str5, boolean z, Continuation continuation) {
        super(2, continuation);
        this.c = rowCustomizationViewModel;
        this.d = str;
        this.e = screenType;
        this.f = str2;
        this.i = str3;
        this.j = str4;
        this.k = str5;
        this.l = z;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        return new a(this.c, this.d, this.e, this.f, this.i, this.j, this.k, this.l, continuation);
    }

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

    /* JADX WARN: Removed duplicated region for block: B:52:0x00e0 A[Catch: Exception -> 0x002a, TryCatch #0 {Exception -> 0x002a, blocks: (B:8:0x0026, B:15:0x0037, B:57:0x0102, B:60:0x010c, B:64:0x0116, B:67:0x0166, B:66:0x0143, B:18:0x0041, B:50:0x00dc, B:52:0x00e0, B:54:0x00f5, B:19:0x0049, B:25:0x005c, B:27:0x0068, B:28:0x006a, B:30:0x0070, B:47:0x00cc, B:33:0x007a, B:34:0x007e, B:36:0x0084, B:38:0x0094, B:40:0x009e, B:42:0x00a4, B:44:0x00ae, B:22:0x0052), top: B:73:0x001c }] */
    /* JADX WARN: Removed duplicated region for block: B:54:0x00f5 A[Catch: Exception -> 0x002a, TryCatch #0 {Exception -> 0x002a, blocks: (B:8:0x0026, B:15:0x0037, B:57:0x0102, B:60:0x010c, B:64:0x0116, B:67:0x0166, B:66:0x0143, B:18:0x0041, B:50:0x00dc, B:52:0x00e0, B:54:0x00f5, B:19:0x0049, B:25:0x005c, B:27:0x0068, B:28:0x006a, B:30:0x0070, B:47:0x00cc, B:33:0x007a, B:34:0x007e, B:36:0x0084, B:38:0x0094, B:40:0x009e, B:42:0x00a4, B:44:0x00ae, B:22:0x0052), top: B:73:0x001c }] */
    /* JADX WARN: Removed duplicated region for block: B:59:0x010a  */
    /* JADX WARN: Removed duplicated region for block: B:66:0x0143 A[Catch: Exception -> 0x002a, TryCatch #0 {Exception -> 0x002a, blocks: (B:8:0x0026, B:15:0x0037, B:57:0x0102, B:60:0x010c, B:64:0x0116, B:67:0x0166, B:66:0x0143, B:18:0x0041, B:50:0x00dc, B:52:0x00e0, B:54:0x00f5, B:19:0x0049, B:25:0x005c, B:27:0x0068, B:28:0x006a, B:30:0x0070, B:47:0x00cc, B:33:0x007a, B:34:0x007e, B:36:0x0084, B:38:0x0094, B:40:0x009e, B:42:0x00a4, B:44:0x00ae, B:22:0x0052), top: B:73:0x001c }] */
    /* JADX WARN: Removed duplicated region for block: B:70:0x01ab A[RETURN] */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        Object profileSlugForNewRow;
        String str;
        Object objCheckRowLimits;
        String str2;
        Object nextPosition;
        RowCustomizationViewModel rowCustomizationViewModel = this.c;
        re6 re6Var = rowCustomizationViewModel.e;
        ScreenConfigRepository screenConfigRepository = rowCustomizationViewModel.a;
        ck1 ck1Var = ck1.a;
        int i = this.b;
        String str3 = this.j;
        String str4 = this.f;
        e6a e6aVar = e6a.a;
        String str5 = this.i;
        ScreenConfigRepository.ScreenType screenType = this.e;
        try {
            if (i == 0) {
                s38.b(obj);
                this.b = 1;
                profileSlugForNewRow = screenConfigRepository.getProfileSlugForNewRow(this);
                if (profileSlugForNewRow == ck1Var) {
                }
            }
            if (i != 1) {
                if (i == 2) {
                    String str6 = this.a;
                    s38.b(obj);
                    str = str6;
                    objCheckRowLimits = obj;
                    str2 = (String) objCheckRowLimits;
                    if (str2 == null) {
                        re6Var.l("Cannot add row: " + str2);
                        return e6aVar;
                    }
                    this.a = str;
                    this.b = 3;
                    nextPosition = screenConfigRepository.getNextPosition(screenType, this);
                    if (nextPosition != ck1Var) {
                        int iIntValue = ((Number) nextPosition).intValue();
                        if (str4 == null) {
                        }
                        if (cr4.b(str5, "trakt_list")) {
                            RowConfigEntity rowConfigEntity = new RowConfigEntity((cr4.b(str5, "trakt_list") || str3 == null) ? str5 + "_" + str4 + "_" + screenType.getKey() + "_" + str : str5 + "_" + h2a.a(str3.hashCode()) + "_" + screenType.getKey() + "_" + str, str, screenType.getKey(), this.d, this.i, this.f, this.k, this.j, iIntValue, iIntValue, true, this.l, 20, false, null, null, null, 114688, null);
                            this.a = null;
                            this.b = 4;
                            if (screenConfigRepository.insertRow(rowConfigEntity, this) != ck1Var) {
                            }
                        }
                    }
                }
                if (i != 3) {
                    if (i != 4) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    s38.b(obj);
                    return e6aVar;
                }
                String str7 = this.a;
                s38.b(obj);
                str = str7;
                nextPosition = obj;
                int iIntValue2 = ((Number) nextPosition).intValue();
                if (str4 == null) {
                    str4 = TtmlNode.COMBINE_ALL;
                }
                RowConfigEntity rowConfigEntity2 = new RowConfigEntity((cr4.b(str5, "trakt_list") || str3 == null) ? str5 + "_" + str4 + "_" + screenType.getKey() + "_" + str : str5 + "_" + h2a.a(str3.hashCode()) + "_" + screenType.getKey() + "_" + str, str, screenType.getKey(), this.d, this.i, this.f, this.k, this.j, iIntValue2, iIntValue2, true, this.l, 20, false, null, null, null, 114688, null);
                this.a = null;
                this.b = 4;
                return screenConfigRepository.insertRow(rowConfigEntity2, this) != ck1Var ? ck1Var : e6aVar;
            }
            s38.b(obj);
            profileSlugForNewRow = obj;
            str = (String) profileSlugForNewRow;
            Iterable iterable = (List) rowCustomizationViewModel.c.e();
            if (iterable == null) {
                iterable = ik2.a;
            }
            Iterable<RowConfigEntity> iterable2 = iterable;
            if (!(iterable2 instanceof Collection) || !((Collection) iterable2).isEmpty()) {
                for (RowConfigEntity rowConfigEntity3 : iterable2) {
                    if (cr4.b(rowConfigEntity3.getRowType(), str5) && cr4.b(rowConfigEntity3.getContentType(), str4) && (!cr4.b(str5, "trakt_list") || cr4.b(rowConfigEntity3.getDataSourceUrl(), str3))) {
                        re6Var.l("\"" + this.d + "\" is already on this page");
                        return e6aVar;
                    }
                }
            }
            String key = screenType.getKey();
            this.a = str;
            this.b = 2;
            objCheckRowLimits = screenConfigRepository.checkRowLimits(str, 1, key, this);
            if (objCheckRowLimits != ck1Var) {
                str2 = (String) objCheckRowLimits;
                if (str2 == null) {
                }
            }
        } catch (Exception e) {
            re6Var.l("Failed to add row: " + e.getMessage());
            return e6aVar;
        }
    }
}
