package d3;

import V2.C0636a3;
import V2.P2;
import V2.Q2;
import V2.n3;
import a3.C0963b;
import androidx.compose.runtime.MutableState;
import androidx.compose.runtime.State;
import androidx.media3.exoplayer.ExoPlayer;
import com.debridstream.tv.PlayerViewModel;
import j$.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import m3.AbstractC2467b;
import n2.AbstractC2612c;
import okhttp3.OkHttpClient;
import org.json.JSONException;
import w4.C3137A;

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final /* synthetic */ P2 f15241b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ N2.f f15242c;

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

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

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final /* synthetic */ N2.r f15246j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final /* synthetic */ OkHttpClient f15247k;
    public final /* synthetic */ PlayerViewModel l;

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

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

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

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

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

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

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public N1(P2 p22, N2.f fVar, int i6, int i7, boolean z6, N2.r rVar, OkHttpClient okHttpClient, PlayerViewModel playerViewModel, State state, State state2, MutableState mutableState, MutableState mutableState2, MutableState mutableState3, MutableState mutableState4, A4.d dVar) {
        super(2, dVar);
        this.f15241b = p22;
        this.f15242c = fVar;
        this.f15243d = i6;
        this.f15244e = i7;
        this.f15245f = z6;
        this.f15246j = rVar;
        this.f15247k = okHttpClient;
        this.l = playerViewModel;
        this.f15248m = state;
        this.f15249n = state2;
        this.f15250o = mutableState;
        this.f15251p = mutableState2;
        this.f15252q = mutableState3;
        this.f15253r = mutableState4;
    }

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        return new N1(this.f15241b, this.f15242c, this.f15243d, this.f15244e, this.f15245f, this.f15246j, this.f15247k, this.l, this.f15248m, this.f15249n, this.f15250o, this.f15251p, this.f15252q, this.f15253r, dVar);
    }

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

    /* JADX WARN: Removed duplicated region for block: B:53:0x00e1  */
    @Override // C4.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) throws JSONException {
        Object objD0;
        P2 p22;
        Long l;
        String str;
        B4.a aVar = B4.a.f492a;
        int i6 = this.f15240a;
        if (i6 == 0) {
            AbstractC2467b.l(obj);
            State state = this.f15248m;
            DateTimeFormatter dateTimeFormatter = v2.f16084a;
            boolean z6 = kotlin.jvm.internal.o.c(((C0636a3) state.getValue()).f7683b, "tv") || ((p22 = this.f15241b) != null && p22.f7480c);
            V2.O0 o02 = ((n3) this.f15249n.getValue()).f7975e;
            List listQ = AbstractC2612c.q(this.f15242c);
            String str2 = z6 ? "tv" : "movie";
            Integer num = z6 ? new Integer(this.f15243d) : null;
            Integer num2 = z6 ? new Integer(this.f15244e) : null;
            boolean z7 = this.f15245f;
            String str3 = str2;
            Integer num3 = num;
            Map map = N2.q.f5245b;
            C0963b c0963b = new C0963b(o02.f7461b, o02.f7463d, o02.f7462c);
            N2.r rVar = this.f15246j;
            OkHttpClient okHttpClient = this.f15247k;
            this.f15240a = 1;
            objD0 = W.a.d0(listQ, str3, num3, num2, z7, 1, map, c0963b, rVar, okHttpClient, this);
            if (objD0 == aVar) {
                return aVar;
            }
        } else {
            if (i6 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            AbstractC2467b.l(obj);
            objD0 = obj;
        }
        a3.P p6 = (a3.P) objD0;
        MutableState mutableState = this.f15250o;
        DateTimeFormatter dateTimeFormatter2 = v2.f16084a;
        mutableState.setValue(null);
        String str4 = p6.f10574a;
        if (str4 == null || S4.p.Q0(str4)) {
            a5.c cVar = K2.p.f4116a;
            K2.p.a("No download link", (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);
        } else {
            MutableState mutableState2 = this.f15252q;
            ExoPlayer exoPlayer = (ExoPlayer) this.f15251p.getValue();
            if (exoPlayer != null) {
                long currentPosition = exoPlayer.getCurrentPosition();
                if (currentPosition < 0) {
                    currentPosition = 0;
                }
                l = new Long(currentPosition);
            } else {
                l = null;
            }
            mutableState2.setValue(l);
            PlayerViewModel playerViewModel = this.l;
            String str5 = p6.f10574a;
            String str6 = p6.f10578e;
            if (str6 == null) {
                str6 = this.f15242c.f5143a;
            }
            String str7 = str6;
            String str8 = p6.f10577d;
            if (str8 == null) {
                str = this.f15242c.f5144b;
                PlayerViewModel.prepare$default(playerViewModel, str5, str7, str, null, true, null, ((Q2) this.l.getUiState().getValue()).f7502g, null, false, 424, null);
                this.f15253r.setValue(Boolean.FALSE);
            } else {
                str = S4.p.Q0(str8) ? null : str8;
                if (str == null) {
                }
                PlayerViewModel.prepare$default(playerViewModel, str5, str7, str, null, true, null, ((Q2) this.l.getUiState().getValue()).f7502g, null, false, 424, null);
                this.f15253r.setValue(Boolean.FALSE);
            }
        }
        return C3137A.f25453a;
    }
}
