package com.strmr.ps.ui.profile;

import android.view.View;
import androidx.leanback.widget.HorizontalGridView;
import androidx.media3.container.MdtaMetadataEntry;
import androidx.media3.extractor.ts.TsExtractor;
import com.strmr.ps.data.local.entity.TraktAccount;
import com.strmr.ps.ui.profile.ProfilePickerActivity;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.co;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.m02;
import defpackage.m12;
import defpackage.px;
import defpackage.s38;
import defpackage.sc2;
import defpackage.vx8;
import defpackage.wj0;
import java.util.Iterator;
import java.util.List;
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;
import net.zetetic.database.DatabaseUtils;

/* 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.profile.ProfilePickerActivity$loadProfiles$1", f = "ProfilePickerActivity.kt", i = {}, l = {MdtaMetadataEntry.TYPE_INDICATOR_8_BIT_UNSIGNED_INT, TsExtractor.TS_STREAM_TYPE_DVBSUBS, DatabaseUtils.STATEMENT_OTHER, 112}, m = "invokeSuspend", n = {}, s = {})
@vx8
final class e extends SuspendLambda implements gr3<ak1, Continuation<? super e6a>, Object> {
    public ProfilePickerActivity a;
    public int b;
    public final /* synthetic */ ProfilePickerActivity c;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public e(ProfilePickerActivity profilePickerActivity, Continuation continuation) {
        super(2, continuation);
        this.c = profilePickerActivity;
    }

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

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

    /* JADX WARN: Code restructure failed: missing block: B:27:0x0081, code lost:
    
        if (defpackage.wj0.f(r13, r1, r12) == r0) goto L40;
     */
    /* JADX WARN: Code restructure failed: missing block: B:39:0x00cb, code lost:
    
        if (r13 == r0) goto L40;
     */
    /* JADX WARN: Removed duplicated region for block: B:38:0x00b9  */
    /* JADX WARN: Removed duplicated region for block: B:65:0x011d  */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) throws Throwable {
        ProfilePickerActivity profilePickerActivity;
        HorizontalGridView horizontalGridView;
        ck1 ck1Var = ck1.a;
        int i = this.b;
        int i2 = 3;
        int i3 = 2;
        e6a e6aVar = e6a.a;
        ProfilePickerActivity profilePickerActivity2 = this.c;
        if (i == 0) {
            s38.b(obj);
            m12 m12Var = sc2.a;
            m02 m02Var = m02.c;
            a aVar = new a(profilePickerActivity2, null);
            this.a = profilePickerActivity2;
            this.b = 1;
            obj = wj0.f(m02Var, aVar, this);
            if (obj != ck1Var) {
                profilePickerActivity = profilePickerActivity2;
            }
            return ck1Var;
        }
        if (i == 1) {
            profilePickerActivity = this.a;
            s38.b(obj);
        } else {
            if (i == 2) {
                s38.b(obj);
                ProfilePickerActivity.h(profilePickerActivity2);
                return e6aVar;
            }
            if (i != 3) {
                if (i != 4) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                s38.b(obj);
                TraktAccount traktAccount = (TraktAccount) obj;
                Iterator it = profilePickerActivity2.m.iterator();
                int i4 = 0;
                while (true) {
                    if (!it.hasNext()) {
                        i4 = -1;
                        break;
                    }
                    if (cr4.b(((TraktAccount) it.next()).getUserSlug(), traktAccount != null ? traktAccount.getUserSlug() : null)) {
                        break;
                    }
                    i4++;
                }
                Integer numBoxInt = Boxing.boxInt(i4);
                if (numBoxInt.intValue() < 0) {
                    numBoxInt = null;
                }
                int iIntValue = numBoxInt != null ? numBoxInt.intValue() : 0;
                HorizontalGridView horizontalGridView2 = profilePickerActivity2.j;
                if (horizontalGridView2 != null) {
                    horizontalGridView2.post(new px(profilePickerActivity2, iIntValue, i2));
                    return e6aVar;
                }
                cr4.n("profileGrid");
                throw null;
            }
            s38.b(obj);
            ProfilePickerActivity.a aVar2 = new ProfilePickerActivity.a(profilePickerActivity2.m, ((Boolean) obj).booleanValue(), new co(profilePickerActivity2, i3));
            horizontalGridView = profilePickerActivity2.j;
            if (horizontalGridView != null) {
                cr4.n("profileGrid");
                throw null;
            }
            horizontalGridView.setAdapter(aVar2);
            m12 m12Var2 = sc2.a;
            m02 m02Var2 = m02.c;
            c cVar = new c(profilePickerActivity2, null);
            this.b = 4;
            obj = wj0.f(m02Var2, cVar, this);
        }
        profilePickerActivity.m = (List) obj;
        View view = profilePickerActivity2.l;
        if (view == null) {
            cr4.n("progressBar");
            throw null;
        }
        view.setVisibility(8);
        if (profilePickerActivity2.m.isEmpty()) {
            ProfilePickerActivity.h(profilePickerActivity2);
            return e6aVar;
        }
        if (profilePickerActivity2.m.size() == 1) {
            m12 m12Var3 = sc2.a;
            m02 m02Var3 = m02.c;
            b bVar = new b(profilePickerActivity2, null);
            this.a = null;
            this.b = 2;
        } else {
            HorizontalGridView horizontalGridView3 = profilePickerActivity2.j;
            if (horizontalGridView3 == null) {
                cr4.n("profileGrid");
                throw null;
            }
            horizontalGridView3.setVisibility(0);
            m12 m12Var4 = sc2.a;
            m02 m02Var4 = m02.c;
            d dVar = new d(profilePickerActivity2, null);
            this.a = null;
            this.b = 3;
            obj = wj0.f(m02Var4, dVar, this);
            if (obj != ck1Var) {
                ProfilePickerActivity.a aVar22 = new ProfilePickerActivity.a(profilePickerActivity2.m, ((Boolean) obj).booleanValue(), new co(profilePickerActivity2, i3));
                horizontalGridView = profilePickerActivity2.j;
                if (horizontalGridView != null) {
                }
            }
        }
        return ck1Var;
    }
}
