package Y2;

import S4.w;
import com.debridstream.tv.data.home.HomeMetaItem;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Pattern;
import okhttp3.Response;
import x4.AbstractC3250p;
import x4.AbstractC3251q;

/* JADX INFO: loaded from: classes.dex */
public abstract class q {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final Set f8782a = AbstractC3250p.Y(new String[]{"g", "pg", "pg-13"});

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Set f8783b = AbstractC3250p.Y(new String[]{"tv-y", "tv-y7", "tv-g", "tv-pg"});

    public static final boolean a(String str) {
        return (S4.p.Q0(str) || str.equals("null")) ? false : true;
    }

    public static final boolean b(Response response, int i6, int i7) {
        String strB = Response.b("X-Pagination-Page", response);
        Integer numB0 = strB != null ? w.B0(strB) : null;
        String strB2 = Response.b("X-Pagination-Page-Count", response);
        Integer numB02 = strB2 != null ? w.B0(strB2) : null;
        return (numB0 == null || numB02 == null || numB02.intValue() <= 0) ? i7 != 0 && i7 >= i6 : numB0.intValue() < numB02.intValue();
    }

    /* JADX WARN: Removed duplicated region for block: B:35:0x0082  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x00d6  */
    /* JADX WARN: Removed duplicated region for block: B:58:0x00da  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final t c(t tVar, boolean z6, Integer num, Integer num2) {
        Integer numB0;
        List list = tVar.f8789a;
        List listA0 = W.a.a0(list);
        if (listA0 != list) {
            tVar = new t(tVar.f8790b, listA0, tVar.f8791c);
        }
        if (num == null || num.intValue() <= 0) {
            num = null;
        }
        if (num2 == null || num2.intValue() <= 0) {
            num2 = null;
        }
        if (z6 || num != null || num2 != null) {
            ArrayList arrayList = new ArrayList();
            List list2 = tVar.f8789a;
            for (Object obj : list2) {
                HomeMetaItem homeMetaItem = (HomeMetaItem) obj;
                boolean z7 = true;
                if (z6) {
                    String lowerCase = S4.p.o1(homeMetaItem.getCertificate()).toString().toLowerCase(Locale.ROOT);
                    kotlin.jvm.internal.o.g(lowerCase, "toLowerCase(...)");
                    if (lowerCase.length() == 0 ? false : (w.t0(homeMetaItem.getType(), "movie", true) ? f8782a : f8783b).contains(lowerCase)) {
                        if (num == null || W.a.s0(homeMetaItem, num.intValue())) {
                            if (num2 != null) {
                                int iIntValue = num2.intValue();
                                kotlin.jvm.internal.o.h(homeMetaItem, "<this>");
                                String strM1 = S4.p.m1(4, S4.p.o1(homeMetaItem.getYear()).toString());
                                if (strM1.length() == 4) {
                                    for (int i6 = 0; i6 < strM1.length(); i6++) {
                                        if (!Character.isDigit(strM1.charAt(i6))) {
                                            strM1 = null;
                                            break;
                                        }
                                    }
                                    if (!(strM1 == null && (numB0 = w.B0(strM1)) != null && numB0.intValue() >= iIntValue)) {
                                        z7 = false;
                                    }
                                } else {
                                    strM1 = null;
                                    if (strM1 == null) {
                                        if (!(strM1 == null && (numB0 = w.B0(strM1)) != null && numB0.intValue() >= iIntValue)) {
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (z7) {
                    arrayList.add(obj);
                }
            }
            if (arrayList.size() != list2.size()) {
                return new t(tVar.f8790b, arrayList, tVar.f8791c);
            }
        }
        return tVar;
    }

    public static final String d(int i6, String query) {
        kotlin.jvm.internal.o.h(query, "query");
        String input = S4.p.o1(query).toString();
        Pattern patternCompile = Pattern.compile("[?&]page=\\d+");
        kotlin.jvm.internal.o.g(patternCompile, "compile(...)");
        kotlin.jvm.internal.o.h(input, "input");
        if (patternCompile.matcher(input).find()) {
            return new S4.m("([?&])page=\\d+").e(input, new p(i6, 0));
        }
        if (input.length() == 0) {
            return Z0.o.l("page=", i6);
        }
        if (S4.p.J0(input, '&')) {
            return input + "page=" + i6;
        }
        return input + "&page=" + i6;
    }

    public static final String e(String queryRaw, boolean z6) {
        kotlin.jvm.internal.o.h(queryRaw, "queryRaw");
        List listC1 = S4.p.c1(queryRaw, new char[]{'&'}, 6);
        ArrayList arrayList = new ArrayList();
        for (Object obj : listC1) {
            if (!S4.p.Q0((String) obj)) {
                arrayList.add(obj);
            }
        }
        ArrayList arrayList2 = new ArrayList();
        for (Object obj2 : arrayList) {
            String str = (String) obj2;
            String string = S4.p.o1(S4.p.j1('=', str, str)).toString();
            if (!w.t0(string, "certification_country", true) && !w.t0(string, "certification", true) && !w.A0(string, "certification.", true)) {
                arrayList2.add(obj2);
            }
        }
        String str2 = z6 ? "certification_country=US&certification.lte=PG-13" : "certification_country=US&certification.lte=TV-PG";
        return arrayList2.isEmpty() ? str2 : Z0.o.B(AbstractC3251q.m0(arrayList2, "&", null, null, null, 62), "&", str2);
    }
}
