package g3;

import V2.AbstractC0661f3;
import V2.C0636a3;
import V2.O0;
import V2.n3;
import V2.u3;
import V4.E;
import V4.N;
import Y4.c0;
import a3.AbstractC0978q;
import a3.C0963b;
import a3.P;
import a3.Y;
import androidx.media3.extractor.text.ttml.TtmlNode;
import com.debridstream.tv.data.home.HomeMetaItem;
import java.util.Iterator;
import java.util.Map;
import m3.AbstractC2467b;
import okhttp3.OkHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import w4.C3137A;

/* JADX INFO: renamed from: g3.f, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C2064f {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final C2064f f16487a = new C2064f();

    /* JADX WARN: Removed duplicated region for block: B:34:0x0076  */
    /* JADX WARN: Removed duplicated region for block: B:42:0x00aa A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00ab  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x00d5  */
    /* JADX WARN: Removed duplicated region for block: B:69:0x00e5  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /* JADX WARN: Removed duplicated region for block: B:88:0x0116 A[PHI: r0
      0x0116: PHI (r0v13 java.lang.String) = (r0v10 java.lang.String), (r0v14 java.lang.String) binds: [B:92:0x0122, B:86:0x0113] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:89:0x0118  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object a(int i6, String str, JSONObject jSONObject, C4.c cVar) throws JSONException {
        r rVar;
        int i7;
        boolean zQ0;
        int i8;
        boolean z6;
        String strA;
        if (cVar instanceof r) {
            rVar = (r) cVar;
            int i9 = rVar.f16553e;
            if ((i9 & Integer.MIN_VALUE) != 0) {
                rVar.f16553e = i9 - Integer.MIN_VALUE;
            } else {
                rVar = new r(cVar);
            }
        }
        Object objH = rVar.f16552d;
        B4.a aVar = B4.a.f492a;
        int i10 = rVar.f16553e;
        C3137A c3137a = C3137A.f25453a;
        String str2 = null;
        if (i10 == 0) {
            AbstractC2467b.l(objH);
            String strB = m.b(jSONObject);
            boolean z7 = strB == null || S4.p.Q0(strB) || (strA = m.a(jSONObject)) == null || S4.p.Q0(strA);
            if (kotlin.jvm.internal.o.c(str, "tv")) {
                JSONArray jSONArrayOptJSONArray = jSONObject.optJSONArray("originCountries");
                if ((jSONArrayOptJSONArray != null ? jSONArrayOptJSONArray.length() : 0) <= 0) {
                    i7 = 1;
                }
                String strOptString = jSONObject.optString("originalLanguage", "");
                kotlin.jvm.internal.o.g(strOptString, "optString(...)");
                zQ0 = S4.p.Q0(strOptString);
                if (!z7) {
                }
                Y2.o oVar = new Y2.o();
                rVar.f16549a = jSONObject;
                rVar.f16550b = i7;
                rVar.f16551c = zQ0;
                rVar.f16553e = 1;
                c5.e eVar = N.f8259a;
                objH = E.H(c5.d.f13466b, new Y2.c(i6, str, oVar, null), rVar);
                if (objH != aVar) {
                }
            } else {
                i7 = 0;
                String strOptString2 = jSONObject.optString("originalLanguage", "");
                kotlin.jvm.internal.o.g(strOptString2, "optString(...)");
                zQ0 = S4.p.Q0(strOptString2);
                if (!z7 || i7 != 0 || zQ0) {
                    Y2.o oVar2 = new Y2.o();
                    rVar.f16549a = jSONObject;
                    rVar.f16550b = i7;
                    rVar.f16551c = zQ0;
                    rVar.f16553e = 1;
                    c5.e eVar2 = N.f8259a;
                    objH = E.H(c5.d.f13466b, new Y2.c(i6, str, oVar2, null), rVar);
                    if (objH != aVar) {
                        return aVar;
                    }
                    i8 = i7;
                    z6 = zQ0;
                }
            }
            return c3137a;
        }
        if (i10 != 1) {
            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
        z6 = rVar.f16551c;
        i8 = rVar.f16550b;
        jSONObject = rVar.f16549a;
        AbstractC2467b.l(objH);
        HomeMetaItem homeMetaItem = (HomeMetaItem) objH;
        if (homeMetaItem != null) {
            String strB2 = m.b(jSONObject);
            if (strB2 == null || S4.p.Q0(strB2)) {
                String posterUrl = homeMetaItem.getPosterUrl();
                if (posterUrl == null) {
                    posterUrl = homeMetaItem.getBackdropUrl();
                    if (posterUrl == null || S4.p.Q0(posterUrl)) {
                        posterUrl = null;
                    }
                    if (posterUrl != null) {
                        String strA2 = u.a(posterUrl, false);
                        if (!S4.p.Q0(strA2)) {
                            posterUrl = strA2;
                        }
                        jSONObject.put("posterUrl", posterUrl);
                    }
                } else {
                    if (S4.p.Q0(posterUrl)) {
                        posterUrl = null;
                    }
                    if (posterUrl == null) {
                    }
                    if (posterUrl != null) {
                    }
                }
            }
            String strA3 = m.a(jSONObject);
            if (strA3 == null || S4.p.Q0(strA3)) {
                String backdropUrl = homeMetaItem.getBackdropUrl();
                if (backdropUrl == null) {
                    backdropUrl = homeMetaItem.getPosterUrl();
                    if (backdropUrl != null && !S4.p.Q0(backdropUrl)) {
                        str2 = backdropUrl;
                    }
                    if (str2 != null) {
                        String strA4 = u.a(str2, true);
                        if (!S4.p.Q0(strA4)) {
                            str2 = strA4;
                        }
                        jSONObject.put("backdropUrl", str2);
                    }
                } else {
                    if (S4.p.Q0(backdropUrl)) {
                        backdropUrl = null;
                    }
                    if (backdropUrl == null) {
                    }
                }
            }
            if (i8 != 0 && !homeMetaItem.getOriginCountries().isEmpty()) {
                JSONArray jSONArray = new JSONArray();
                Iterator<T> it = homeMetaItem.getOriginCountries().iterator();
                while (it.hasNext()) {
                    jSONArray.put((String) it.next());
                }
                jSONObject.put("originCountries", jSONArray);
            }
            if (z6 && !S4.p.Q0(homeMetaItem.getOriginalLanguage())) {
                jSONObject.put("originalLanguage", homeMetaItem.getOriginalLanguage());
            }
        }
        return c3137a;
    }

    /* JADX WARN: Removed duplicated region for block: B:8:0x0018  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object b(n nVar, int i6, int i7, String str, C4.c cVar) {
        s sVar;
        String str2;
        String string;
        String string2 = str;
        if (cVar instanceof s) {
            sVar = (s) cVar;
            int i8 = sVar.f16556c;
            if ((i8 & Integer.MIN_VALUE) != 0) {
                sVar.f16556c = i8 - Integer.MIN_VALUE;
            } else {
                sVar = new s(cVar);
            }
        }
        s sVar2 = sVar;
        Object objD = sVar2.f16555b;
        B4.a aVar = B4.a.f492a;
        int i9 = sVar2.f16556c;
        String str3 = null;
        if (i9 == 0) {
            AbstractC2467b.l(objD);
            String str4 = ((C0636a3) AbstractC0661f3.f7767d.getValue()).f7682a;
            String string3 = str4 != null ? S4.p.o1(str4).toString() : null;
            if (string3 != null && !S4.p.Q0(string3) && S4.w.A0(string3, TtmlNode.TAG_TT, true)) {
                string2 = string3;
            } else if (string2 == null || S4.p.Q0(string2) || !S4.w.A0(string2, TtmlNode.TAG_TT, true)) {
                Map map = X2.j.f8601a;
                String strB = X2.j.b(nVar.f16513a, nVar.f16514b);
                if (strB == null || (string2 = S4.p.o1(strB).toString()) == null || !S4.w.A0(string2, TtmlNode.TAG_TT, true)) {
                    string2 = null;
                }
            }
            if (string2 != null) {
                boolean zC = nVar.c();
                String string4 = S4.p.o1(string2).toString();
                Integer numValueOf = Integer.valueOf(i6 < 1 ? 1 : i6);
                int i10 = i7;
                if (i10 < 1) {
                    i10 = 1;
                }
                Y y6 = new Y(string4, "tv", numValueOf, Integer.valueOf(i10), zC);
                n3 n3Var = (n3) ((c0) u3.f8112c.f8871a).getValue();
                kotlin.jvm.internal.o.h(n3Var, "<this>");
                O0 o02 = n3Var.f7975e;
                kotlin.jvm.internal.o.h(o02, "<this>");
                C0963b c0963b = new C0963b(o02.f7461b, o02.f7463d, o02.f7462c);
                N2.r rVar = (N2.r) m.f16512b.getValue();
                OkHttpClient okHttpClient = (OkHttpClient) m.f16511a.getValue();
                sVar2.f16554a = string2;
                sVar2.f16556c = 1;
                objD = AbstractC0978q.d(y6, nVar.f16515c, c0963b, rVar, okHttpClient, 2750L, 250L, sVar2);
                if (objD == aVar) {
                    return aVar;
                }
                str2 = string2;
            }
            return null;
        }
        if (i9 != 1) {
            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
        str2 = sVar2.f16554a;
        AbstractC2467b.l(objD);
        P p6 = (P) objD;
        if (p6 != null) {
            String str5 = p6.f10574a;
            String string5 = str5 != null ? S4.p.o1(str5).toString() : null;
            if (string5 == null || string5.length() == 0) {
                string5 = null;
            }
            if (string5 != null) {
                String str6 = p6.f10577d;
                if (str6 != null && (string = S4.p.o1(str6).toString()) != null && string.length() > 0) {
                    str3 = string;
                }
                return new q(string5, p6.f10578e, str3, str2);
            }
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public Object c(String str, String str2, String str3, C4.c cVar) {
        C2061c c2061c;
        if (cVar instanceof C2061c) {
            c2061c = (C2061c) cVar;
            int i6 = c2061c.f16473c;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                c2061c.f16473c = i6 - Integer.MIN_VALUE;
            } else {
                c2061c = new C2061c(this, cVar);
            }
        }
        Object objH = c2061c.f16471a;
        B4.a aVar = B4.a.f492a;
        int i7 = c2061c.f16473c;
        if (i7 == 0) {
            AbstractC2467b.l(objH);
            c5.e eVar = N.f8259a;
            c5.d dVar = c5.d.f13466b;
            C2062d c2062d = new C2062d(str, str2, str3, null);
            c2061c.f16473c = 1;
            objH = E.H(dVar, c2062d, c2061c);
            if (objH == aVar) {
                return aVar;
            }
        } else {
            if (i7 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            AbstractC2467b.l(objH);
        }
        return ((w4.n) objH).f25472a;
    }
}
