package j$.time.format;

import java.util.Iterator;
import java.util.Map;

/* JADX INFO: compiled from: r8-map-id-da1bda724d8b26dc30f90d2ccf434f42461d6c82e7dbdeb074f412e5504de99c */
/* JADX INFO: loaded from: classes2.dex */
public final class q implements e {
    public final j$.time.temporal.o a;
    public final TextStyle b;
    public final a0 c;
    public volatile i d;

    public q(j$.time.temporal.o oVar, TextStyle textStyle, a0 a0Var) {
        this.a = oVar;
        this.b = textStyle;
        this.c = a0Var;
    }

    @Override // j$.time.format.e
    public final boolean k(x xVar, StringBuilder sb) {
        Long lA = xVar.a(this.a);
        DateTimeFormatter dateTimeFormatter = xVar.b;
        if (lA == null) {
            return false;
        }
        j$.time.chrono.j jVar = (j$.time.chrono.j) xVar.a.G(j$.time.temporal.p.b);
        String strC = (jVar == null || jVar == j$.time.chrono.q.c) ? this.c.c(this.a, lA.longValue(), this.b, dateTimeFormatter.b) : this.c.b(jVar, this.a, lA.longValue(), this.b, dateTimeFormatter.b);
        if (strC != null) {
            sb.append(strC);
            return true;
        }
        if (this.d == null) {
            this.d = new i(this.a, 1, 19, e0.NORMAL);
        }
        return this.d.k(xVar, sb);
    }

    @Override // j$.time.format.e
    public final int l(v vVar, CharSequence charSequence, int i) {
        a0 a0Var = this.c;
        j$.time.temporal.o oVar = this.a;
        int length = charSequence.length();
        if (i < 0 || i > length) {
            throw new IndexOutOfBoundsException();
        }
        boolean z = vVar.c;
        DateTimeFormatter dateTimeFormatter = vVar.a;
        TextStyle textStyle = z ? this.b : null;
        j$.time.chrono.j jVar = vVar.c().c;
        if (jVar == null && (jVar = vVar.a.e) == null) {
            jVar = j$.time.chrono.q.c;
        }
        j$.time.chrono.j jVar2 = jVar;
        Iterator itE = (jVar2 == null || jVar2 == j$.time.chrono.q.c) ? a0Var.e(oVar, textStyle, dateTimeFormatter.b) : a0Var.d(jVar2, oVar, textStyle, dateTimeFormatter.b);
        if (itE != null) {
            while (itE.hasNext()) {
                Map.Entry entry = (Map.Entry) itE.next();
                String str = (String) entry.getKey();
                if (vVar.g(str, 0, charSequence, i, str.length())) {
                    return vVar.f(this.a, ((Long) entry.getValue()).longValue(), i, str.length() + i);
                }
            }
            if (oVar == j$.time.temporal.a.ERA && !vVar.c) {
                Iterator it = jVar2.v().iterator();
                while (it.hasNext()) {
                    String string = ((j$.time.chrono.k) it.next()).toString();
                    if (vVar.g(string, 0, charSequence, i, string.length())) {
                        return vVar.f(this.a, r8.getValue(), i, string.length() + i);
                    }
                }
            }
            if (vVar.c) {
                return ~i;
            }
        }
        if (this.d == null) {
            this.d = new i(this.a, 1, 19, e0.NORMAL);
        }
        return this.d.l(vVar, charSequence, i);
    }

    public final String toString() {
        TextStyle textStyle = TextStyle.FULL;
        TextStyle textStyle2 = this.b;
        j$.time.temporal.o oVar = this.a;
        if (textStyle2 == textStyle) {
            return "Text(" + oVar + ")";
        }
        return "Text(" + oVar + "," + textStyle2 + ")";
    }
}
