package j$.time.format;

import androidx.media3.exoplayer.audio.SilenceSkippingAudioProcessor;
import java.math.BigInteger;

/* JADX INFO: renamed from: j$.time.format.j, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes2.dex */
class C2300j implements InterfaceC2296f {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    static final long[] f19232f = {0, 10, 100, 1000, 10000, SilenceSkippingAudioProcessor.DEFAULT_MINIMUM_SILENCE_DURATION_US, 1000000, 10000000, 100000000, androidx.media3.common.C.NANOS_PER_SECOND, 10000000000L};

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    final j$.time.temporal.s f19233a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    final int f19235c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private final H f19236d;

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

    long b(z zVar, long j4) {
        return j4;
    }

    C2300j(j$.time.temporal.s sVar, int i6, int i7, H h5) {
        this.f19233a = sVar;
        this.f19234b = i6;
        this.f19235c = i7;
        this.f19236d = h5;
        this.f19237e = 0;
    }

    protected C2300j(j$.time.temporal.s sVar, int i6, int i7, H h5, int i8) {
        this.f19233a = sVar;
        this.f19234b = i6;
        this.f19235c = i7;
        this.f19236d = h5;
        this.f19237e = i8;
    }

    C2300j e() {
        if (this.f19237e == -1) {
            return this;
        }
        return new C2300j(this.f19233a, this.f19234b, this.f19235c, this.f19236d, -1);
    }

    C2300j f(int i6) {
        int i7 = this.f19237e + i6;
        return new C2300j(this.f19233a, this.f19234b, this.f19235c, this.f19236d, i7);
    }

    @Override // j$.time.format.InterfaceC2296f
    public boolean p(z zVar, StringBuilder sb) {
        j$.time.temporal.s sVar = this.f19233a;
        Long lE = zVar.e(sVar);
        if (lE == null) {
            return false;
        }
        long jB = b(zVar, lE.longValue());
        D dB = zVar.b();
        String string = jB == Long.MIN_VALUE ? "9223372036854775808" : Long.toString(Math.abs(jB));
        int length = string.length();
        int i6 = this.f19235c;
        if (length > i6) {
            throw new j$.time.c("Field " + sVar + " cannot be printed as the value " + jB + " exceeds the maximum print width of " + i6);
        }
        dB.getClass();
        int i7 = this.f19234b;
        H h5 = this.f19236d;
        if (jB >= 0) {
            int i8 = AbstractC2293c.f19225a[h5.ordinal()];
            if (i8 != 1) {
                if (i8 == 2) {
                    sb.append('+');
                }
            } else if (i7 < 19 && jB >= f19232f[i7]) {
                sb.append('+');
            }
        } else {
            int i9 = AbstractC2293c.f19225a[h5.ordinal()];
            if (i9 == 1 || i9 == 2 || i9 == 3) {
                sb.append('-');
            } else if (i9 == 4) {
                throw new j$.time.c("Field " + sVar + " cannot be printed as the value " + jB + " cannot be negative according to the SignStyle");
            }
        }
        for (int i10 = 0; i10 < i7 - string.length(); i10++) {
            sb.append('0');
        }
        sb.append(string);
        return true;
    }

    boolean c(w wVar) {
        int i6 = this.f19237e;
        if (i6 != -1) {
            return i6 > 0 && this.f19234b == this.f19235c && this.f19236d == H.NOT_NEGATIVE;
        }
        return true;
    }

    @Override // j$.time.format.InterfaceC2296f
    public int r(w wVar, CharSequence charSequence, int i6) {
        int i7;
        boolean z6;
        boolean z7;
        BigInteger bigIntegerAdd;
        long j4;
        int i8;
        long j6;
        int i9;
        long j7;
        boolean z8;
        int length = charSequence.length();
        if (i6 == length) {
            return ~i6;
        }
        char cCharAt = charSequence.charAt(i6);
        wVar.g().getClass();
        boolean z9 = true;
        int i10 = this.f19235c;
        H h5 = this.f19236d;
        int i11 = this.f19234b;
        int i12 = 0;
        if (cCharAt == '+') {
            boolean zL = wVar.l();
            boolean z10 = i11 == i10;
            int iOrdinal = h5.ordinal();
            if (iOrdinal == 0 ? zL : !(iOrdinal == 1 || iOrdinal == 4 || (!zL && !z10))) {
                return ~i6;
            }
            i7 = i6 + 1;
            z7 = true;
            z6 = false;
        } else {
            wVar.g().getClass();
            if (cCharAt == '-') {
                boolean zL2 = wVar.l();
                boolean z11 = i11 == i10;
                int iOrdinal2 = h5.ordinal();
                if (iOrdinal2 != 0 && iOrdinal2 != 1 && iOrdinal2 != 4 && (zL2 || z11)) {
                    return ~i6;
                }
                i7 = i6 + 1;
                z6 = true;
                z7 = false;
            } else {
                if (h5 == H.ALWAYS && wVar.l()) {
                    return ~i6;
                }
                i7 = i6;
                z6 = false;
                z7 = false;
            }
        }
        int i13 = (wVar.l() || c(wVar)) ? i11 : 1;
        int i14 = i7 + i13;
        if (i14 > length) {
            return ~i7;
        }
        if (!wVar.l() && !c(wVar)) {
            i10 = 9;
        }
        int i15 = this.f19237e;
        int iMax = Math.max(i15, 0) + i10;
        while (true) {
            bigIntegerAdd = null;
            if (i12 >= 2) {
                j4 = 0;
                i8 = i7;
                j6 = 0;
                break;
            }
            int iMin = Math.min(iMax + i7, length);
            i9 = i7;
            j7 = 0;
            while (true) {
                if (i9 >= iMin) {
                    z8 = z9;
                    j4 = 0;
                    break;
                }
                int i16 = i9 + 1;
                z8 = z9;
                j4 = 0;
                int iA = wVar.g().a(charSequence.charAt(i9));
                if (iA >= 0) {
                    if (i16 - i7 > 18) {
                        if (bigIntegerAdd == null) {
                            bigIntegerAdd = BigInteger.valueOf(j7);
                        }
                        bigIntegerAdd = bigIntegerAdd.multiply(BigInteger.TEN).add(BigInteger.valueOf(iA));
                    } else {
                        j7 = (j7 * 10) + ((long) iA);
                    }
                    i9 = i16;
                    z9 = z8;
                } else if (i9 < i14) {
                    return ~i7;
                }
            }
            if (i15 <= 0 || i12 != 0) {
                break;
            }
            iMax = Math.max(i13, (i9 - i7) - i15);
            i12++;
            z9 = z8;
        }
        i8 = i9;
        j6 = j7;
        BigInteger bigIntegerDivide = bigIntegerAdd;
        if (z6) {
            if (bigIntegerDivide != null) {
                if (bigIntegerDivide.equals(BigInteger.ZERO) && wVar.l()) {
                    return ~(i7 - 1);
                }
                bigIntegerDivide = bigIntegerDivide.negate();
            } else {
                if (j6 == j4 && wVar.l()) {
                    return ~(i7 - 1);
                }
                j6 = -j6;
            }
        } else if (h5 == H.EXCEEDS_PAD && wVar.l()) {
            int i17 = i8 - i7;
            if (z7) {
                if (i17 <= i11) {
                    return ~(i7 - 1);
                }
            } else if (i17 > i11) {
                return ~i7;
            }
        }
        if (bigIntegerDivide != null) {
            if (bigIntegerDivide.bitLength() > 63) {
                bigIntegerDivide = bigIntegerDivide.divide(BigInteger.TEN);
                i8--;
            }
            return d(wVar, bigIntegerDivide.longValue(), i7, i8);
        }
        return d(wVar, j6, i7, i8);
    }

    int d(w wVar, long j4, int i6, int i7) {
        return wVar.o(this.f19233a, j4, i6, i7);
    }

    public String toString() {
        int i6 = this.f19235c;
        j$.time.temporal.s sVar = this.f19233a;
        H h5 = this.f19236d;
        int i7 = this.f19234b;
        if (i7 == 1 && i6 == 19 && h5 == H.NORMAL) {
            return "Value(" + sVar + ")";
        }
        if (i7 == i6 && h5 == H.NOT_NEGATIVE) {
            return "Value(" + sVar + "," + i7 + ")";
        }
        return "Value(" + sVar + "," + i7 + "," + i6 + "," + h5 + ")";
    }
}
