package t1;

import C1.c;
import com.revenuecat.purchases.common.Constants;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashSet;
import n1.C2609c;
import u1.C2962c;
import u1.d;
import u1.e;
import u1.k;

/* JADX INFO: renamed from: t1.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C2945a extends k {

    /* JADX INFO: renamed from: A0, reason: collision with root package name */
    public boolean f24272A0;

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

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

    /* JADX INFO: renamed from: D0, reason: collision with root package name */
    public int f24275D0;
    public int E0;

    /* JADX INFO: renamed from: F0, reason: collision with root package name */
    public float f24276F0;

    /* JADX INFO: renamed from: G0, reason: collision with root package name */
    public float f24277G0;

    /* JADX INFO: renamed from: H0, reason: collision with root package name */
    public String f24278H0;

    /* JADX INFO: renamed from: I0, reason: collision with root package name */
    public String f24279I0;

    /* JADX INFO: renamed from: J0, reason: collision with root package name */
    public String f24280J0;
    public String K0;
    public int L0;

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

    /* JADX INFO: renamed from: N0, reason: collision with root package name */
    public boolean[][] f24282N0;

    /* JADX INFO: renamed from: O0, reason: collision with root package name */
    public HashSet f24283O0;

    /* JADX INFO: renamed from: P0, reason: collision with root package name */
    public int[][] f24284P0;

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

    /* JADX INFO: renamed from: R0, reason: collision with root package name */
    public int[][] f24286R0;

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

    /* JADX INFO: renamed from: y0, reason: collision with root package name */
    public e f24288y0;

    /* JADX INFO: renamed from: z0, reason: collision with root package name */
    public d[] f24289z0;

    public static void R(d dVar) {
        dVar.h0[1] = -1.0f;
        dVar.f24437G.j();
        dVar.f24439I.j();
        dVar.f24440J.j();
    }

    public static float[] a0(int i6, String str) {
        if (str == null || str.trim().isEmpty()) {
            return null;
        }
        String[] strArrSplit = str.split(",");
        float[] fArr = new float[i6];
        for (int i7 = 0; i7 < i6; i7++) {
            if (i7 < strArrSplit.length) {
                try {
                    fArr[i7] = Float.parseFloat(strArrSplit[i7]);
                } catch (Exception e6) {
                    System.err.println("Error parsing `" + strArrSplit[i7] + "`: " + e6.getMessage());
                    fArr[i7] = 1.0f;
                }
            } else {
                fArr[i7] = 1.0f;
            }
        }
        return fArr;
    }

    @Override // u1.k
    public final void P(int i6, int i7, int i8, int i9) {
        int[][] iArrZ;
        this.f24288y0 = this.f24447Q;
        if (this.f24273B0 >= 1 && this.f24275D0 >= 1) {
            this.f24281M0 = 0;
            String str = this.K0;
            if (str != null && !str.trim().isEmpty() && (iArrZ = Z(this.K0, false)) != null) {
                V(iArrZ);
            }
            String str2 = this.f24280J0;
            if (str2 != null && !str2.trim().isEmpty()) {
                this.f24286R0 = Z(this.f24280J0, true);
            }
            int iMax = Math.max(this.f24273B0, this.f24275D0);
            d[] dVarArr = this.f24289z0;
            if (dVarArr == null) {
                this.f24289z0 = new d[iMax];
                int i10 = 0;
                while (true) {
                    d[] dVarArr2 = this.f24289z0;
                    if (i10 >= dVarArr2.length) {
                        break;
                    }
                    d dVar = new d();
                    int[] iArr = dVar.f24475m0;
                    iArr[0] = 3;
                    iArr[1] = 3;
                    dVar.f24471k = String.valueOf(dVar.hashCode());
                    dVarArr2[i10] = dVar;
                    i10++;
                }
            } else if (iMax != dVarArr.length) {
                d[] dVarArr3 = new d[iMax];
                for (int i11 = 0; i11 < iMax; i11++) {
                    d[] dVarArr4 = this.f24289z0;
                    if (i11 < dVarArr4.length) {
                        dVarArr3[i11] = dVarArr4[i11];
                    } else {
                        d dVar2 = new d();
                        int[] iArr2 = dVar2.f24475m0;
                        iArr2[0] = 3;
                        iArr2[1] = 3;
                        dVar2.f24471k = String.valueOf(dVar2.hashCode());
                        dVarArr3[i11] = dVar2;
                    }
                }
                while (true) {
                    d[] dVarArr5 = this.f24289z0;
                    if (iMax >= dVarArr5.length) {
                        break;
                    }
                    d dVar3 = dVarArr5[iMax];
                    this.f24288y0.f24493n0.remove(dVar3);
                    dVar3.A();
                    iMax++;
                }
                this.f24289z0 = dVarArr3;
            }
            int[][] iArr3 = this.f24286R0;
            if (iArr3 != null) {
                W(iArr3);
            }
        }
        e eVar = this.f24288y0;
        d[] dVarArr6 = this.f24289z0;
        eVar.getClass();
        for (d dVar4 : dVarArr6) {
            eVar.f24493n0.add(dVar4);
            e eVar2 = dVar4.f24447Q;
            if (eVar2 != null) {
                eVar2.f24493n0.remove(dVar4);
                dVar4.A();
            }
            dVar4.f24447Q = eVar;
        }
    }

    public final void S(int i6, int i7, int i8, int i9, d dVar) {
        dVar.f24436F.a(this.f24289z0[i7].f24436F, 0);
        dVar.f24437G.a(this.f24289z0[i6].f24437G, 0);
        dVar.f24438H.a(this.f24289z0[(i7 + i9) - 1].f24438H, 0);
        dVar.f24439I.a(this.f24289z0[(i6 + i8) - 1].f24439I, 0);
    }

    public final int T(int i6) {
        return this.L0 == 1 ? i6 / this.f24273B0 : i6 % this.f24275D0;
    }

    public final int U(int i6) {
        return this.L0 == 1 ? i6 % this.f24273B0 : i6 / this.f24275D0;
    }

    public final void V(int[][] iArr) {
        for (int[] iArr2 : iArr) {
            if (!Y(U(iArr2[0]), T(iArr2[0]), iArr2[1], iArr2[2])) {
                return;
            }
        }
    }

    public final void W(int[][] iArr) {
        if ((this.f24285Q0 & 2) > 0) {
            return;
        }
        for (int i6 = 0; i6 < iArr.length; i6++) {
            int iU = U(iArr[i6][0]);
            int iT = T(iArr[i6][0]);
            int[] iArr2 = iArr[i6];
            if (!Y(iU, iT, iArr2[1], iArr2[2])) {
                break;
            }
            d dVar = this.f24551n0[i6];
            int[] iArr3 = iArr[i6];
            S(iU, iT, iArr3[1], iArr3[2], dVar);
            this.f24283O0.add(this.f24551n0[i6].f24471k);
        }
    }

    public final void X() {
        boolean[][] zArr = (boolean[][]) Array.newInstance((Class<?>) Boolean.TYPE, this.f24273B0, this.f24275D0);
        this.f24282N0 = zArr;
        for (boolean[] zArr2 : zArr) {
            Arrays.fill(zArr2, true);
        }
        int i6 = this.f24552o0;
        if (i6 > 0) {
            int[][] iArr = (int[][]) Array.newInstance((Class<?>) Integer.TYPE, i6, 4);
            this.f24284P0 = iArr;
            for (int[] iArr2 : iArr) {
                Arrays.fill(iArr2, -1);
            }
        }
    }

    public final boolean Y(int i6, int i7, int i8, int i9) {
        for (int i10 = i6; i10 < i6 + i8; i10++) {
            for (int i11 = i7; i11 < i7 + i9; i11++) {
                boolean[][] zArr = this.f24282N0;
                if (i10 < zArr.length && i11 < zArr[0].length) {
                    boolean[] zArr2 = zArr[i10];
                    if (zArr2[i11]) {
                        zArr2[i11] = false;
                    }
                }
                return false;
            }
        }
        return true;
    }

    public final int[][] Z(String str, boolean z6) {
        int i6;
        int i7;
        try {
            String[] strArrSplit = str.split(",");
            Arrays.sort(strArrSplit, new c(17));
            int[][] iArr = (int[][]) Array.newInstance((Class<?>) Integer.TYPE, strArrSplit.length, 3);
            if (this.f24273B0 != 1 && this.f24275D0 != 1) {
                for (int i8 = 0; i8 < strArrSplit.length; i8++) {
                    String[] strArrSplit2 = strArrSplit[i8].trim().split(Constants.SUBS_ID_BASE_PLAN_ID_SEPARATOR);
                    String[] strArrSplit3 = strArrSplit2[1].split("x");
                    iArr[i8][0] = Integer.parseInt(strArrSplit2[0]);
                    if ((this.f24285Q0 & 1) > 0) {
                        iArr[i8][1] = Integer.parseInt(strArrSplit3[1]);
                        iArr[i8][2] = Integer.parseInt(strArrSplit3[0]);
                    } else {
                        iArr[i8][1] = Integer.parseInt(strArrSplit3[0]);
                        iArr[i8][2] = Integer.parseInt(strArrSplit3[1]);
                    }
                }
                return iArr;
            }
            int i9 = 0;
            int i10 = 0;
            for (int i11 = 0; i11 < strArrSplit.length; i11++) {
                String[] strArrSplit4 = strArrSplit[i11].trim().split(Constants.SUBS_ID_BASE_PLAN_ID_SEPARATOR);
                iArr[i11][0] = Integer.parseInt(strArrSplit4[0]);
                int[] iArr2 = iArr[i11];
                iArr2[1] = 1;
                iArr2[2] = 1;
                if (this.f24275D0 == 1) {
                    iArr2[1] = Integer.parseInt(strArrSplit4[1]);
                    i9 += iArr[i11][1];
                    if (z6) {
                        i9--;
                    }
                }
                if (this.f24273B0 == 1) {
                    iArr[i11][2] = Integer.parseInt(strArrSplit4[1]);
                    i10 += iArr[i11][2];
                    if (z6) {
                        i10--;
                    }
                }
            }
            if (i9 != 0 && !this.f24272A0 && (i7 = this.f24273B0 + i9) <= 50 && this.f24274C0 != i7) {
                this.f24274C0 = i7;
                b0();
                X();
            }
            if (i10 != 0 && !this.f24272A0 && (i6 = this.f24275D0 + i10) <= 50 && this.E0 != i6) {
                this.E0 = i6;
                b0();
                X();
            }
            this.f24272A0 = true;
            return iArr;
        } catch (Exception unused) {
            return null;
        }
    }

    public final void b0() {
        int i6;
        int i7 = this.f24274C0;
        if (i7 != 0 && (i6 = this.E0) != 0) {
            this.f24273B0 = i7;
            this.f24275D0 = i6;
            return;
        }
        int i8 = this.E0;
        if (i8 > 0) {
            this.f24275D0 = i8;
            this.f24273B0 = ((this.f24552o0 + i8) - 1) / i8;
        } else if (i7 > 0) {
            this.f24273B0 = i7;
            this.f24275D0 = ((this.f24552o0 + i7) - 1) / i7;
        } else {
            int iSqrt = (int) (Math.sqrt(this.f24552o0) + 1.5d);
            this.f24273B0 = iSqrt;
            this.f24275D0 = ((this.f24552o0 + iSqrt) - 1) / iSqrt;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:77:0x01c0  */
    @Override // u1.d
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void c(C2609c c2609c, boolean z6) {
        int i6;
        int i7;
        int[][] iArr;
        int i8;
        super.c(c2609c, z6);
        int iMax = Math.max(this.f24273B0, this.f24275D0);
        d dVar = this.f24289z0[0];
        float[] fArrA0 = a0(this.f24273B0, this.f24278H0);
        int i9 = this.f24273B0;
        C2962c c2962c = this.f24439I;
        C2962c c2962c2 = this.f24437G;
        if (i9 == 1) {
            R(dVar);
            dVar.f24437G.a(c2962c2, 0);
            dVar.f24439I.a(c2962c, 0);
        } else {
            int i10 = 0;
            while (true) {
                i6 = this.f24273B0;
                if (i10 >= i6) {
                    break;
                }
                d dVar2 = this.f24289z0[i10];
                R(dVar2);
                if (fArrA0 != null) {
                    dVar2.h0[1] = fArrA0[i10];
                }
                C2962c c2962c3 = dVar2.f24437G;
                if (i10 > 0) {
                    c2962c3.a(this.f24289z0[i10 - 1].f24439I, 0);
                } else {
                    c2962c3.a(c2962c2, 0);
                }
                int i11 = this.f24273B0 - 1;
                C2962c c2962c4 = dVar2.f24439I;
                if (i10 < i11) {
                    c2962c4.a(this.f24289z0[i10 + 1].f24437G, 0);
                } else {
                    c2962c4.a(c2962c, 0);
                }
                if (i10 > 0) {
                    c2962c3.f24428g = (int) this.f24277G0;
                }
                i10++;
            }
            while (i6 < iMax) {
                d dVar3 = this.f24289z0[i6];
                R(dVar3);
                dVar3.f24437G.a(c2962c2, 0);
                dVar3.f24439I.a(c2962c, 0);
                i6++;
            }
        }
        int iMax2 = Math.max(this.f24273B0, this.f24275D0);
        d dVar4 = this.f24289z0[0];
        float[] fArrA02 = a0(this.f24275D0, this.f24279I0);
        int i12 = this.f24275D0;
        C2962c c2962c5 = this.f24438H;
        C2962c c2962c6 = this.f24436F;
        if (i12 == 1) {
            dVar4.h0[0] = -1.0f;
            dVar4.f24436F.j();
            dVar4.f24438H.j();
            dVar4.f24436F.a(c2962c6, 0);
            dVar4.f24438H.a(c2962c5, 0);
        } else {
            int i13 = 0;
            while (true) {
                i7 = this.f24275D0;
                if (i13 >= i7) {
                    break;
                }
                d dVar5 = this.f24289z0[i13];
                dVar5.h0[0] = -1.0f;
                dVar5.f24436F.j();
                dVar5.f24438H.j();
                if (fArrA02 != null) {
                    dVar5.h0[0] = fArrA02[i13];
                }
                C2962c c2962c7 = dVar5.f24436F;
                if (i13 > 0) {
                    c2962c7.a(this.f24289z0[i13 - 1].f24438H, 0);
                } else {
                    c2962c7.a(c2962c6, 0);
                }
                int i14 = this.f24275D0 - 1;
                C2962c c2962c8 = dVar5.f24438H;
                if (i13 < i14) {
                    c2962c8.a(this.f24289z0[i13 + 1].f24436F, 0);
                } else {
                    c2962c8.a(c2962c5, 0);
                }
                if (i13 > 0) {
                    c2962c7.f24428g = (int) this.f24276F0;
                }
                i13++;
            }
            while (i7 < iMax2) {
                d dVar6 = this.f24289z0[i7];
                dVar6.h0[0] = -1.0f;
                dVar6.f24436F.j();
                dVar6.f24438H.j();
                dVar6.f24436F.a(c2962c6, 0);
                dVar6.f24438H.a(c2962c5, 0);
                i7++;
            }
        }
        for (int i15 = 0; i15 < this.f24552o0; i15++) {
            if (!this.f24283O0.contains(this.f24551n0[i15].f24471k)) {
                boolean z7 = false;
                int i16 = 0;
                while (true) {
                    if (z7) {
                        break;
                    }
                    i16 = this.f24281M0;
                    if (i16 >= this.f24273B0 * this.f24275D0) {
                        i16 = -1;
                        break;
                    }
                    int iU = U(i16);
                    int iT = T(this.f24281M0);
                    boolean[] zArr = this.f24282N0[iU];
                    if (zArr[iT]) {
                        zArr[iT] = false;
                        z7 = true;
                    }
                    this.f24281M0++;
                }
                int iU2 = U(i16);
                int iT2 = T(i16);
                if (i16 == -1) {
                    return;
                }
                if ((this.f24285Q0 & 2) <= 0 || (iArr = this.f24286R0) == null || (i8 = this.f24287S0) >= iArr.length) {
                    S(iU2, iT2, 1, 1, this.f24551n0[i15]);
                } else {
                    int[] iArr2 = iArr[i8];
                    if (iArr2[0] == i16) {
                        this.f24282N0[iU2][iT2] = true;
                        if (Y(iU2, iT2, iArr2[1], iArr2[2])) {
                            d dVar7 = this.f24551n0[i15];
                            int[] iArr3 = this.f24286R0[this.f24287S0];
                            S(iU2, iT2, iArr3[1], iArr3[2], dVar7);
                            this.f24287S0++;
                        }
                    }
                }
            }
        }
    }
}
