package d3;

import V2.M3;
import V2.P2;
import V2.Q2;
import androidx.compose.runtime.MutableState;
import androidx.compose.runtime.State;
import androidx.media3.common.TrackSelectionParameters;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.extractor.text.ttml.TtmlNode;
import com.debridstream.tv.PlayerViewModel;
import f3.AbstractC2045j;
import f3.C2041f;
import f3.C2042g;
import f3.C2043h;
import f3.C2044i;
import j$.time.format.DateTimeFormatter;
import java.util.Iterator;
import java.util.List;
import m3.AbstractC2467b;
import okhttp3.OkHttpClient;
import w4.C3137A;

/* JADX INFO: renamed from: d3.p1, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1915p1 extends C4.j implements J4.e {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ M3 f15895c;

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

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

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final /* synthetic */ MutableState f15900k;
    public final /* synthetic */ String l;

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

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

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

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

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

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

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

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C1915p1(M3 m32, List list, ExoPlayer exoPlayer, MutableState mutableState, MutableState mutableState2, MutableState mutableState3, String str, N2.f fVar, PlayerViewModel playerViewModel, MutableState mutableState4, State state, String str2, MutableState mutableState5, MutableState mutableState6, A4.d dVar) {
        super(2, dVar);
        this.f15895c = m32;
        this.f15896d = list;
        this.f15897e = exoPlayer;
        this.f15898f = mutableState;
        this.f15899j = mutableState2;
        this.f15900k = mutableState3;
        this.l = str;
        this.f15901m = fVar;
        this.f15902n = playerViewModel;
        this.f15903o = mutableState4;
        this.f15904p = state;
        this.f15905q = str2;
        this.f15906r = mutableState5;
        this.f15907s = mutableState6;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:51:0x00c8  */
    /* JADX WARN: Removed duplicated region for block: B:60:0x00e4  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x00e7  */
    /* JADX WARN: Removed duplicated region for block: B:64:0x00ed  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x001e  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object d(String str, N2.f fVar, PlayerViewModel playerViewModel, MutableState mutableState, State state, String str2, MutableState mutableState2, String str3, String str4, C4.c cVar) {
        C1912o1 c1912o1;
        W.d c2041f;
        String string;
        PlayerViewModel playerViewModel2;
        MutableState mutableState3;
        Object obj;
        String str5;
        String string2;
        MutableState mutableState4 = mutableState;
        String str6 = str4;
        if (cVar instanceof C1912o1) {
            c1912o1 = (C1912o1) cVar;
            int i6 = c1912o1.f15876j;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                c1912o1.f15876j = i6 - Integer.MIN_VALUE;
            } else {
                c1912o1 = new C1912o1(cVar);
            }
        }
        C1912o1 c1912o12 = c1912o1;
        Object obj2 = c1912o12.f15875f;
        B4.a aVar = B4.a.f492a;
        int i7 = c1912o12.f15876j;
        C3137A c3137a = C3137A.f25453a;
        if (i7 == 0) {
            AbstractC2467b.l(obj2);
            DateTimeFormatter dateTimeFormatter = v2.f16084a;
            if (((Boolean) mutableState4.getValue()).booleanValue()) {
                return c3137a;
            }
            String str7 = ((Q2) state.getValue()).f7503h;
            if (str7 != null && !S4.p.Q0(str7)) {
                mutableState4.setValue(Boolean.TRUE);
                return c3137a;
            }
            if (kotlin.jvm.internal.o.c(str3, "none") && kotlin.jvm.internal.o.c(str6, "none")) {
                mutableState4.setValue(Boolean.TRUE);
                return c3137a;
            }
            P2 p22 = ((Q2) state.getValue()).f7500e;
            if (p22 != null) {
                String str8 = p22.f7479b;
                if (str8 == null || (string2 = S4.p.o1(str8).toString()) == null || !S4.w.A0(string2, TtmlNode.TAG_TT, true)) {
                    string2 = null;
                }
                c2041f = (!p22.f7480c || string2 == null || S4.p.Q0(string2)) ? null : new C2042g(string2, p22.f7481d, p22.f7482e);
                if (c2041f == null) {
                }
                if (c2041f == null) {
                }
            } else if (str == null || (string = S4.p.o1(str).toString()) == null) {
                c2041f = null;
                if (c2041f == null) {
                    mutableState4.setValue(Boolean.TRUE);
                    return c3137a;
                }
                String string3 = fVar != null ? S4.p.o1(v2.w0(fVar)).toString() : null;
                if (string3 == null) {
                    string3 = "";
                }
                String str9 = S4.p.Q0(string3) ? str2 : string3;
                Long l = fVar != null ? new Long(fVar.f5148f) : null;
                OkHttpClient okHttpClient = AbstractC2045j.f16431a;
                String str10 = !kotlin.jvm.internal.o.c(str6, "none") ? str6 : null;
                playerViewModel2 = playerViewModel;
                c1912o12.f15870a = playerViewModel2;
                c1912o12.f15871b = mutableState4;
                mutableState3 = mutableState2;
                c1912o12.f15872c = mutableState3;
                c1912o12.f15873d = str3;
                c1912o12.f15874e = str6;
                c1912o12.f15876j = 1;
                c5.e eVar = V4.N.f8259a;
                Object objH = V4.E.H(c5.d.f13466b, new C2044i(str9, c2041f, l, str3, str10, null), c1912o12);
                if (objH == aVar) {
                    return aVar;
                }
                obj = objH;
                str5 = str3;
            } else {
                if (string.length() <= 0) {
                    string = null;
                }
                if (string != null) {
                    c2041f = new C2041f(string);
                }
                if (c2041f == null) {
                }
            }
        } else {
            if (i7 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            String str11 = c1912o12.f15874e;
            String str12 = c1912o12.f15873d;
            MutableState mutableState5 = c1912o12.f15872c;
            MutableState mutableState6 = c1912o12.f15871b;
            PlayerViewModel playerViewModel3 = c1912o12.f15870a;
            AbstractC2467b.l(obj2);
            str6 = str11;
            mutableState3 = mutableState5;
            playerViewModel2 = playerViewModel3;
            obj = obj2;
            str5 = str12;
            mutableState4 = mutableState6;
        }
        C2043h c2043h = (C2043h) obj;
        if (c2043h != null) {
            playerViewModel2.setExternalSubtitle(c2043h.f16424b, c2043h.f16423a);
            String str13 = !kotlin.jvm.internal.o.c(str5, "none") ? str5 : (str6 == null || S4.p.Q0(str6) || str6.equals("none")) ? null : str6;
            DateTimeFormatter dateTimeFormatter2 = v2.f16084a;
            mutableState3.setValue(str13);
        }
        DateTimeFormatter dateTimeFormatter3 = v2.f16084a;
        mutableState4.setValue(Boolean.TRUE);
        return c3137a;
    }

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        return new C1915p1(this.f15895c, this.f15896d, this.f15897e, this.f15898f, this.f15899j, this.f15900k, this.l, this.f15901m, this.f15902n, this.f15903o, this.f15904p, this.f15905q, this.f15906r, this.f15907s, dVar);
    }

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

    /* JADX WARN: Code restructure failed: missing block: B:25:0x00a9, code lost:
    
        if (d(r20.l, r20.f15901m, r2, r20.f15903o, r15, r14, r6, r7, r8, r20) == r10) goto L77;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:41:0x00f7  */
    @Override // C4.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        String str;
        State state;
        int i6;
        int i7;
        B4.a aVar = B4.a.f492a;
        int i8 = this.f15894b;
        C3137A c3137a = C3137A.f25453a;
        MutableState mutableState = this.f15899j;
        if (i8 == 0) {
            AbstractC2467b.l(obj);
            MutableState mutableState2 = this.f15898f;
            DateTimeFormatter dateTimeFormatter = v2.f16084a;
            if (!((Boolean) mutableState2.getValue()).booleanValue() && ((Integer) mutableState.getValue()) == null) {
                MutableState mutableState3 = this.f15900k;
                if (((Number) mutableState3.getValue()).intValue() == 3 || ((Number) mutableState3.getValue()).intValue() == 4) {
                    M3 m32 = this.f15895c;
                    String strZ0 = v2.z0(m32.l);
                    String strZ02 = v2.z0(m32.f7447m);
                    List list = this.f15896d;
                    boolean zIsEmpty = list.isEmpty();
                    ExoPlayer exoPlayer = this.f15897e;
                    MutableState mutableState4 = this.f15906r;
                    String str2 = this.f15905q;
                    State state2 = this.f15904p;
                    PlayerViewModel playerViewModel = this.f15902n;
                    if (zIsEmpty) {
                        TrackSelectionParameters.Builder builderBuildUpon = exoPlayer.getTrackSelectionParameters().buildUpon();
                        kotlin.jvm.internal.o.g(builderBuildUpon, "buildUpon(...)");
                        builderBuildUpon.setTrackTypeDisabled(3, true);
                        builderBuildUpon.clearOverridesOfType(3);
                        exoPlayer.setTrackSelectionParameters(builderBuildUpon.build());
                        this.f15894b = 1;
                    } else {
                        String str3 = str2;
                        State state3 = state2;
                        if (strZ0.equals("none") && strZ02.equals("none")) {
                            Iterator it = list.iterator();
                            int i9 = 0;
                            while (true) {
                                if (!it.hasNext()) {
                                    str = str3;
                                    state = state3;
                                    i9 = -1;
                                    break;
                                }
                                C c6 = (C) it.next();
                                String str4 = c6.f15033c;
                                str = str3;
                                state = state3;
                                if (S4.p.D0(str4, "forced", true) || S4.p.D0(str4, "force", true)) {
                                    String str5 = c6.f15031a.getFormat(c6.f15032b).language;
                                    if (str5 == null) {
                                        str5 = "";
                                    }
                                    String strZ03 = v2.z0(str5);
                                    if (!S4.p.Q0(strZ03) && !strZ03.equals(androidx.media3.common.C.LANGUAGE_UNDETERMINED)) {
                                        if (strZ03.equals("en") || strZ03.equals("eng") || S4.w.A0(strZ03, "en-", false)) {
                                            break;
                                        }
                                    }
                                }
                                i9++;
                                str3 = str;
                                state3 = state;
                            }
                            i6 = i9;
                        } else {
                            str = str3;
                            state = state3;
                            int iF0 = !strZ0.equals("none") ? v2.f0(strZ0, list) : -1;
                            if (iF0 < 0) {
                                iF0 = !strZ02.equals("none") ? v2.f0(strZ02, list) : -1;
                            }
                            i6 = iF0;
                        }
                        if (i6 >= 0) {
                            v2.k0(exoPlayer, list, i6, 3);
                            this.f15907s.setValue(0L);
                            this.f15903o.setValue(Boolean.TRUE);
                        } else {
                            TrackSelectionParameters.Builder builderBuildUpon2 = exoPlayer.getTrackSelectionParameters().buildUpon();
                            kotlin.jvm.internal.o.g(builderBuildUpon2, "buildUpon(...)");
                            builderBuildUpon2.setTrackTypeDisabled(3, true);
                            builderBuildUpon2.clearOverridesOfType(3);
                            exoPlayer.setTrackSelectionParameters(builderBuildUpon2.build());
                            this.f15893a = i6;
                            this.f15894b = 2;
                            if (d(this.l, this.f15901m, playerViewModel, this.f15903o, state, str, mutableState4, strZ0, strZ02, this) != aVar) {
                                i7 = i6;
                                i6 = i7;
                            }
                        }
                    }
                    return aVar;
                }
            }
            return c3137a;
        }
        if (i8 == 1) {
            AbstractC2467b.l(obj);
            Integer num = new Integer(-1);
            DateTimeFormatter dateTimeFormatter2 = v2.f16084a;
            mutableState.setValue(num);
            return c3137a;
        }
        if (i8 != 2) {
            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
        i7 = this.f15893a;
        AbstractC2467b.l(obj);
        i6 = i7;
        Integer num2 = i6 >= 0 ? new Integer(i6) : new Integer(-1);
        DateTimeFormatter dateTimeFormatter3 = v2.f16084a;
        mutableState.setValue(num2);
        return c3137a;
    }
}
