package Z0;

import J2.L;
import T0.C0596g;
import T0.N;
import V.C0629x;
import a1.AbstractC0958a;

/* JADX INFO: renamed from: Z0.h, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0867h {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final L f9104a;

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

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

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

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

    public C0867h(C0596g c0596g, long j4) {
        String str = c0596g.f6510b;
        L l = new L(3);
        l.f3284d = str;
        l.f3282b = -1;
        l.f3283c = -1;
        this.f9104a = l;
        this.f9105b = N.f(j4);
        this.f9106c = N.e(j4);
        this.f9107d = -1;
        this.f9108e = -1;
        int iF = N.f(j4);
        int iE = N.e(j4);
        String str2 = c0596g.f6510b;
        if (iF < 0 || iF > str2.length()) {
            StringBuilder sbR = com.google.android.recaptcha.internal.a.r(iF, "start (", ") offset is outside of text region ");
            sbR.append(str2.length());
            throw new IndexOutOfBoundsException(sbR.toString());
        }
        if (iE < 0 || iE > str2.length()) {
            StringBuilder sbR2 = com.google.android.recaptcha.internal.a.r(iE, "end (", ") offset is outside of text region ");
            sbR2.append(str2.length());
            throw new IndexOutOfBoundsException(sbR2.toString());
        }
        if (iF > iE) {
            throw new IllegalArgumentException(com.google.android.recaptcha.internal.a.i(iF, iE, "Do not set reversed range: ", " > "));
        }
    }

    public final void a(int i6, int i7) {
        long jG = android.support.v4.media.session.b.g(i6, i7);
        this.f9104a.H(i6, i7, "");
        long jG2 = W.d.G(android.support.v4.media.session.b.g(this.f9105b, this.f9106c), jG);
        h(N.f(jG2));
        g(N.e(jG2));
        int i8 = this.f9107d;
        if (i8 != -1) {
            long jG3 = W.d.G(android.support.v4.media.session.b.g(i8, this.f9108e), jG);
            if (N.c(jG3)) {
                this.f9107d = -1;
                this.f9108e = -1;
            } else {
                this.f9107d = N.f(jG3);
                this.f9108e = N.e(jG3);
            }
        }
    }

    public final char b(int i6) {
        L l = this.f9104a;
        C0629x c0629x = (C0629x) l.f3285e;
        if (c0629x == null) {
            return ((String) l.f3284d).charAt(i6);
        }
        if (i6 < l.f3282b) {
            return ((String) l.f3284d).charAt(i6);
        }
        int iE = c0629x.f7177b - c0629x.e();
        int i7 = l.f3282b;
        if (i6 >= iE + i7) {
            return ((String) l.f3284d).charAt(i6 - ((iE - l.f3283c) + i7));
        }
        int i8 = i6 - i7;
        int i9 = c0629x.f7178c;
        return i8 < i9 ? ((char[]) c0629x.f7180e)[i8] : ((char[]) c0629x.f7180e)[(i8 - i9) + c0629x.f7179d];
    }

    public final N c() {
        int i6 = this.f9107d;
        if (i6 != -1) {
            return new N(android.support.v4.media.session.b.g(i6, this.f9108e));
        }
        return null;
    }

    public final void d(int i6, int i7, String str) {
        L l = this.f9104a;
        if (i6 < 0 || i6 > l.p()) {
            StringBuilder sbR = com.google.android.recaptcha.internal.a.r(i6, "start (", ") offset is outside of text region ");
            sbR.append(l.p());
            throw new IndexOutOfBoundsException(sbR.toString());
        }
        if (i7 < 0 || i7 > l.p()) {
            StringBuilder sbR2 = com.google.android.recaptcha.internal.a.r(i7, "end (", ") offset is outside of text region ");
            sbR2.append(l.p());
            throw new IndexOutOfBoundsException(sbR2.toString());
        }
        if (i6 > i7) {
            throw new IllegalArgumentException(com.google.android.recaptcha.internal.a.i(i6, i7, "Do not set reversed range: ", " > "));
        }
        l.H(i6, i7, str);
        h(str.length() + i6);
        g(str.length() + i6);
        this.f9107d = -1;
        this.f9108e = -1;
    }

    public final void e(int i6, int i7) {
        L l = this.f9104a;
        if (i6 < 0 || i6 > l.p()) {
            StringBuilder sbR = com.google.android.recaptcha.internal.a.r(i6, "start (", ") offset is outside of text region ");
            sbR.append(l.p());
            throw new IndexOutOfBoundsException(sbR.toString());
        }
        if (i7 < 0 || i7 > l.p()) {
            StringBuilder sbR2 = com.google.android.recaptcha.internal.a.r(i7, "end (", ") offset is outside of text region ");
            sbR2.append(l.p());
            throw new IndexOutOfBoundsException(sbR2.toString());
        }
        if (i6 >= i7) {
            throw new IllegalArgumentException(com.google.android.recaptcha.internal.a.i(i6, i7, "Do not set reversed or empty range: ", " > "));
        }
        this.f9107d = i6;
        this.f9108e = i7;
    }

    public final void f(int i6, int i7) {
        L l = this.f9104a;
        if (i6 < 0 || i6 > l.p()) {
            StringBuilder sbR = com.google.android.recaptcha.internal.a.r(i6, "start (", ") offset is outside of text region ");
            sbR.append(l.p());
            throw new IndexOutOfBoundsException(sbR.toString());
        }
        if (i7 < 0 || i7 > l.p()) {
            StringBuilder sbR2 = com.google.android.recaptcha.internal.a.r(i7, "end (", ") offset is outside of text region ");
            sbR2.append(l.p());
            throw new IndexOutOfBoundsException(sbR2.toString());
        }
        if (i6 > i7) {
            throw new IllegalArgumentException(com.google.android.recaptcha.internal.a.i(i6, i7, "Do not set reversed range: ", " > "));
        }
        h(i6);
        g(i7);
    }

    public final void g(int i6) {
        if (!(i6 >= 0)) {
            AbstractC0958a.a("Cannot set selectionEnd to a negative value: " + i6);
        }
        this.f9106c = i6;
    }

    public final void h(int i6) {
        if (!(i6 >= 0)) {
            AbstractC0958a.a("Cannot set selectionStart to a negative value: " + i6);
        }
        this.f9105b = i6;
    }

    public final String toString() {
        return this.f9104a.toString();
    }
}
