package com.strmr.ps.data.supabase;

import android.util.Log;
import androidx.media3.common.C;
import androidx.media3.extractor.ts.TsExtractor;
import com.strmr.ps.data.supabase.DeviceCodeAuthManager;
import defpackage.ck1;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.h32;
import defpackage.io6;
import defpackage.l43;
import defpackage.s38;
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\u0010\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0003\u001a\u00020\u0002*\b\u0012\u0004\u0012\u00020\u00010\u0000H\n¢\u0006\u0004\b\u0003\u0010\u0004"}, d2 = {"Ll43;", "Lcom/strmr/ps/data/supabase/DeviceCodeAuthManager$b;", "Le6a;", "<anonymous>", "(Ll43;)V"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.data.supabase.DeviceCodeAuthManager$pollForCompletion$1", f = "DeviceCodeAuthManager.kt", i = {0, 0, 1, 1, 1, 2, 2}, l = {110, 111, 131, TsExtractor.TS_STREAM_TYPE_DTS_HD}, m = "invokeSuspend", n = {"$this$flow", "attempts", "$this$flow", "result", "attempts", "$this$flow", "attempts"}, s = {"L$0", "I$0", "L$0", "L$1", "I$0", "L$0", "I$0"})
final class d extends SuspendLambda implements gr3<l43<? super DeviceCodeAuthManager.b>, Continuation<? super e6a>, Object> {
    public DeviceCodeAuthManager.b a;
    public int b;
    public int c;
    public /* synthetic */ Object d;
    public final /* synthetic */ String e;
    public final /* synthetic */ DeviceCodeAuthManager f;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public d(String str, DeviceCodeAuthManager deviceCodeAuthManager, Continuation continuation) {
        super(2, continuation);
        this.e = str;
        this.f = deviceCodeAuthManager;
    }

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

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

    /* JADX WARN: Removed duplicated region for block: B:18:0x004f  */
    /* JADX WARN: Removed duplicated region for block: B:24:0x0071  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x0082  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x009a  */
    /* JADX WARN: Removed duplicated region for block: B:44:0x00b8  */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:40:0x00af -> B:41:0x00b0). 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) {
        int i;
        l43 l43Var;
        l43 l43Var2;
        DeviceCodeAuthManager.b bVar;
        DeviceCodeAuthManager.b bVar2;
        ck1 ck1Var = ck1.a;
        int i2 = this.c;
        e6a e6aVar = e6a.a;
        if (i2 == 0) {
            s38.b(obj);
            i = 0;
            l43Var = (l43) this.d;
            if (i < 200) {
            }
            return ck1Var;
        }
        if (i2 == 1) {
            i = this.b;
            l43Var = (l43) this.d;
            s38.b(obj);
            bVar2 = (DeviceCodeAuthManager.b) obj;
            this.d = l43Var;
            this.a = bVar2;
            this.b = i;
            this.c = 2;
            if (l43Var.emit(bVar2, this) != ck1Var) {
            }
            return ck1Var;
        }
        if (i2 == 2) {
            i = this.b;
            bVar = this.a;
            l43Var2 = (l43) this.d;
            s38.b(obj);
            if (!(bVar instanceof DeviceCodeAuthManager.b.d)) {
                if (bVar instanceof DeviceCodeAuthManager.b.a) {
                }
            }
            return e6aVar;
        }
        if (i2 != 3) {
            if (i2 != 4) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(obj);
            return e6aVar;
        }
        i = this.b;
        l43Var = (l43) this.d;
        s38.b(obj);
        i++;
        if (i < 200) {
            this.d = l43Var;
            this.b = i;
            this.c = 1;
            obj = DeviceCodeAuthManager.a(this.f, this.e, this);
            if (obj != ck1Var) {
                bVar2 = (DeviceCodeAuthManager.b) obj;
                this.d = l43Var;
                this.a = bVar2;
                this.b = i;
                this.c = 2;
                if (l43Var.emit(bVar2, this) != ck1Var) {
                    l43Var2 = l43Var;
                    bVar = bVar2;
                    if (!(bVar instanceof DeviceCodeAuthManager.b.d) && !(bVar instanceof DeviceCodeAuthManager.b.C0104b)) {
                        if (bVar instanceof DeviceCodeAuthManager.b.a) {
                            Log.e("DeviceCodeAuthManager", "Poll error: " + ((DeviceCodeAuthManager.b.a) bVar).a);
                            return e6aVar;
                        }
                        if (!(bVar instanceof DeviceCodeAuthManager.b.c)) {
                            throw new io6();
                        }
                        this.d = l43Var2;
                        this.a = null;
                        this.b = i;
                        this.c = 3;
                        if (h32.a(C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS, this) != ck1Var) {
                            l43Var = l43Var2;
                            i++;
                            if (i < 200) {
                                this.d = null;
                                this.c = 4;
                                if (l43Var.emit(DeviceCodeAuthManager.b.C0104b.a, this) == ck1Var) {
                                }
                            }
                        }
                    }
                    return e6aVar;
                }
            }
        }
        return ck1Var;
    }
}
