package M2;

import android.content.Context;
import androidx.compose.runtime.MutableState;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import m3.AbstractC2467b;
import w4.C3137A;

/* JADX INFO: loaded from: classes.dex */
public final class R1 extends C4.j implements J4.e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int f4529a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public g3.n f4530b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f4531c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final /* synthetic */ X2.g f4532d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final /* synthetic */ X2.f f4533e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ int f4534f;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final /* synthetic */ int f4535j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final /* synthetic */ Context f4536k;
    public final /* synthetic */ int l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final /* synthetic */ MutableState f4537m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final /* synthetic */ MutableState f4538n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final /* synthetic */ MutableState f4539o;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public R1(X2.g gVar, X2.f fVar, int i6, int i7, Context context, int i8, MutableState mutableState, MutableState mutableState2, MutableState mutableState3, A4.d dVar) {
        super(2, dVar);
        this.f4532d = gVar;
        this.f4533e = fVar;
        this.f4534f = i6;
        this.f4535j = i7;
        this.f4536k = context;
        this.l = i8;
        this.f4537m = mutableState;
        this.f4538n = mutableState2;
        this.f4539o = mutableState3;
    }

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        return new R1(this.f4532d, this.f4533e, this.f4534f, this.f4535j, this.f4536k, this.l, this.f4537m, this.f4538n, this.f4539o, dVar);
    }

    @Override // J4.e
    public final Object invoke(Object obj, Object obj2) {
        return ((R1) create((V4.C) obj, (A4.d) obj2)).invokeSuspend(C3137A.f25453a);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:100:0x01d4  */
    /* JADX WARN: Removed duplicated region for block: B:51:0x00df  */
    /* JADX WARN: Removed duplicated region for block: B:59:0x00f8  */
    /* JADX WARN: Removed duplicated region for block: B:77:0x013f A[Catch: all -> 0x002b, Exception -> 0x00c9, TryCatch #1 {Exception -> 0x00c9, blocks: (B:37:0x00b1, B:38:0x00b7, B:40:0x00bd, B:46:0x00cd, B:48:0x00d1, B:53:0x00e2, B:58:0x00f3, B:65:0x0107, B:70:0x011c, B:75:0x012a, B:77:0x013f, B:79:0x0149, B:81:0x0151, B:83:0x015b, B:91:0x0191, B:33:0x00a6), top: B:105:0x00a6 }] */
    /* JADX WARN: Removed duplicated region for block: B:78:0x0147  */
    /* JADX WARN: Removed duplicated region for block: B:81:0x0151 A[Catch: all -> 0x002b, Exception -> 0x00c9, TryCatch #1 {Exception -> 0x00c9, blocks: (B:37:0x00b1, B:38:0x00b7, B:40:0x00bd, B:46:0x00cd, B:48:0x00d1, B:53:0x00e2, B:58:0x00f3, B:65:0x0107, B:70:0x011c, B:75:0x012a, B:77:0x013f, B:79:0x0149, B:81:0x0151, B:83:0x015b, B:91:0x0191, B:33:0x00a6), top: B:105:0x00a6 }] */
    /* JADX WARN: Removed duplicated region for block: B:82:0x0159  */
    /* JADX WARN: Removed duplicated region for block: B:86:0x0186  */
    /* JADX WARN: Removed duplicated region for block: B:89:0x018a  */
    @Override // C4.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        int i6;
        int i7;
        g3.n nVarM;
        int i8;
        int i9;
        Object objF;
        int i10;
        double d6;
        int i11;
        Integer num;
        g3.n nVar;
        double d7;
        Object objH;
        Object next;
        int i12;
        MutableState mutableState = this.f4538n;
        B4.a aVar = B4.a.f492a;
        int i13 = this.f4531c;
        C3137A c3137a = C3137A.f25453a;
        X2.g gVar = this.f4532d;
        MutableState mutableState2 = this.f4537m;
        MutableState mutableState3 = this.f4539o;
        int i14 = this.f4534f;
        int i15 = this.f4535j;
        int i16 = this.l;
        int i17 = gVar.f8576b;
        try {
            try {
            } catch (Exception e6) {
                e = e6;
                i6 = 1;
            }
            if (i13 == 0) {
                AbstractC2467b.l(obj);
                L1 l12 = (L1) mutableState2.getValue();
                L1 l13 = L1.f4394a;
                nVarM = L4.a.m(((Number) mutableState.getValue()).intValue(), l12 == l13 ? "movie" : "tv", gVar);
                if (((L1) mutableState2.getValue()) == l13) {
                    double d8 = ((double) i17) * 60.0d;
                    if (d8 <= 60.0d) {
                        d8 = 6000.0d;
                    }
                    d6 = d8;
                    i8 = i14;
                    i11 = 0;
                    num = null;
                    nVar = nVarM;
                    d7 = (((double) i15) * d6) / 100.0d;
                    if (i15 > 0 && d7 >= 60.0d) {
                        Context applicationContext = this.f4536k.getApplicationContext();
                        kotlin.jvm.internal.o.g(applicationContext, "getApplicationContext(...)");
                        L1 l14 = (L1) mutableState2.getValue();
                        L1 l15 = L1.f4395b;
                        Integer num2 = l14 != l15 ? new Integer(i8) : null;
                        Integer num3 = ((L1) mutableState2.getValue()) != l15 ? new Integer(i16) : null;
                        AtomicBoolean atomicBoolean = new AtomicBoolean(false);
                        this.f4530b = null;
                        this.f4529a = i11;
                        this.f4531c = 2;
                        c5.e eVar = V4.N.f8259a;
                        objH = V4.E.H(c5.d.f13466b, new g3.t(nVar, d7, d6, num2, num3, applicationContext, null, true, atomicBoolean, num, null), this);
                        if (objH != B4.a.f492a) {
                            objH = c3137a;
                        }
                        if (objH != aVar) {
                            i7 = i11;
                            if (i7 == 0) {
                            }
                            return c3137a;
                        }
                        return aVar;
                    }
                    a5.c cVar = K2.p.f4116a;
                    K2.p.a("Use at least 1% (requires ≥60s watched)", (10 & 2) != 0 ? "" : "Could not resolve a playable download URL for this link.", K2.r.f4129d, (10 & 8) != 0 ? androidx.media3.common.C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS : 4000L);
                    Boolean bool = Boolean.FALSE;
                    mutableState3.setValue(bool);
                    mutableState3.setValue(bool);
                    return c3137a;
                }
                X2.f fVar = this.f4533e;
                int iIntValue = ((Number) mutableState.getValue()).intValue();
                this.f4530b = nVarM;
                this.f4529a = 0;
                this.f4531c = 1;
                i8 = i14;
                i9 = i17;
                i6 = 1;
                try {
                    objF = fVar.f(iIntValue, i8, false, null, "en", this);
                    if (objF == aVar) {
                        return aVar;
                    }
                    i10 = 0;
                } catch (Exception e7) {
                    e = e7;
                    a5.c cVar2 = K2.p.f4116a;
                    String message = e.getMessage();
                    if (message == null) {
                        message = "Save error: " + e.getClass().getSimpleName();
                    }
                    K2.p.a(message, (10 & 2) != 0 ? "" : "Could not resolve a playable download URL for this link.", K2.r.f4127b, (10 & 8) != 0 ? androidx.media3.common.C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS : 4000L);
                    mutableState3.setValue(Boolean.FALSE);
                    i7 = i6;
                }
            } else {
                if (i13 != 1) {
                    if (i13 != 2) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    int i18 = this.f4529a;
                    AbstractC2467b.l(obj);
                    i7 = i18;
                    if (i7 == 0) {
                        a5.c cVar3 = K2.p.f4116a;
                        K2.p.a(Z0.o.j(i15, "Player path finished (", "%) — check Continue Watching / Trakt logs"), (10 & 2) != 0 ? "" : "Could not resolve a playable download URL for this link.", K2.r.f4128c, (10 & 8) != 0 ? androidx.media3.common.C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS : 4000L);
                    }
                    return c3137a;
                }
                int i19 = this.f4529a;
                g3.n nVar2 = this.f4530b;
                AbstractC2467b.l(obj);
                nVarM = nVar2;
                i8 = i14;
                i9 = i17;
                i10 = i19;
                objF = obj;
            }
            Iterator it = ((List) objF).iterator();
            while (true) {
                if (!it.hasNext()) {
                    next = null;
                    break;
                }
                next = it.next();
                if (((X2.i) next).f8597e == i16) {
                    break;
                }
            }
            X2.i iVar = (X2.i) next;
            if (iVar != null) {
                Integer num4 = new Integer(iVar.f8593a);
                if (num4.intValue() <= 0) {
                    num4 = null;
                }
                if (iVar != null) {
                    Integer num5 = new Integer(iVar.f8599g);
                    if (num5.intValue() <= 0) {
                        num5 = null;
                    }
                    int iIntValue2 = num5 != null ? num5.intValue() : 0;
                    if (iIntValue2 > 0) {
                        i12 = i10;
                    } else if (i9 > 0) {
                        i12 = i10;
                        iIntValue2 = i9;
                    } else {
                        i12 = i10;
                        iIntValue2 = 0;
                    }
                    double d9 = ((double) iIntValue2) * 60.0d;
                    if (d9 <= 60.0d) {
                        d9 = 6000.0d;
                    }
                    d6 = d9;
                    num = num4;
                    i11 = i12;
                    nVar = nVarM;
                    d7 = (((double) i15) * d6) / 100.0d;
                    if (i15 > 0) {
                        Context applicationContext2 = this.f4536k.getApplicationContext();
                        kotlin.jvm.internal.o.g(applicationContext2, "getApplicationContext(...)");
                        L1 l142 = (L1) mutableState2.getValue();
                        L1 l152 = L1.f4395b;
                        if (l142 != l152) {
                        }
                        if (((L1) mutableState2.getValue()) != l152) {
                        }
                        AtomicBoolean atomicBoolean2 = new AtomicBoolean(false);
                        this.f4530b = null;
                        this.f4529a = i11;
                        this.f4531c = 2;
                        c5.e eVar2 = V4.N.f8259a;
                        objH = V4.E.H(c5.d.f13466b, new g3.t(nVar, d7, d6, num2, num3, applicationContext2, null, true, atomicBoolean2, num, null), this);
                        if (objH != B4.a.f492a) {
                        }
                        if (objH != aVar) {
                        }
                        return aVar;
                    }
                    a5.c cVar4 = K2.p.f4116a;
                    K2.p.a("Use at least 1% (requires ≥60s watched)", (10 & 2) != 0 ? "" : "Could not resolve a playable download URL for this link.", K2.r.f4129d, (10 & 8) != 0 ? androidx.media3.common.C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS : 4000L);
                    Boolean bool2 = Boolean.FALSE;
                    mutableState3.setValue(bool2);
                    mutableState3.setValue(bool2);
                    return c3137a;
                }
            }
            if (i7 == 0) {
            }
            return c3137a;
        } finally {
            mutableState3.setValue(Boolean.FALSE);
        }
    }
}
