package defpackage;

import androidx.media3.container.NalUnitUtil;
import defpackage.dw7;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import kotlin.Metadata;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\b\u0000\u0018\u0000*\u0004\b\u0000\u0010\u00012\b\u0012\u0004\u0012\u00028\u00000\u0002¨\u0006\u0003"}, d2 = {"Lkr6;", "Output", "Lp37;", "kotlinx-datetime"}, k = 1, mv = {1, 9, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public final class kr6<Output> implements p37<Output> {
    public final List a;
    public final int b;
    public final boolean c;

    public kr6(List list) {
        boolean z;
        boolean z2;
        int i;
        this.a = list;
        Iterator it = list.iterator();
        int i2 = 0;
        while (true) {
            int iIntValue = 1;
            if (!it.hasNext()) {
                break;
            }
            Integer a = ((er6) it.next()).getA();
            if (a != null) {
                iIntValue = a.intValue();
            }
            i2 += iIntValue;
        }
        this.b = i2;
        List list2 = this.a;
        if ((list2 instanceof Collection) && list2.isEmpty()) {
            z = false;
        } else {
            Iterator it2 = list2.iterator();
            while (it2.hasNext()) {
                if (((er6) it2.next()).getA() == null) {
                    z = true;
                    break;
                }
            }
            z = false;
        }
        this.c = z;
        List list3 = this.a;
        if ((list3 instanceof Collection) && list3.isEmpty()) {
            z2 = true;
        } else {
            Iterator it3 = list3.iterator();
            while (it3.hasNext()) {
                Integer a2 = ((er6) it3.next()).getA();
                if (!((a2 != null ? a2.intValue() : Integer.MAX_VALUE) > 0)) {
                    z2 = false;
                    break;
                }
            }
            z2 = true;
        }
        if (!z2) {
            throw new IllegalArgumentException("Failed requirement.");
        }
        List list4 = this.a;
        if ((list4 instanceof Collection) && list4.isEmpty()) {
            i = 0;
        } else {
            Iterator it4 = list4.iterator();
            i = 0;
            while (it4.hasNext()) {
                if ((((er6) it4.next()).getA() == null) && (i = i + 1) < 0) {
                    y41.bl();
                    throw null;
                }
            }
        }
        if (i <= 1) {
            return;
        }
        List list5 = this.a;
        ArrayList arrayList = new ArrayList();
        for (Object obj : list5) {
            if (((er6) obj).getA() == null) {
                arrayList.add(obj);
            }
        }
        ArrayList arrayList2 = new ArrayList(y41.p(arrayList, 10));
        Iterator it5 = arrayList.iterator();
        while (it5.hasNext()) {
            arrayList2.add(((er6) it5.next()).b);
        }
        throw new IllegalArgumentException(("At most one variable-length numeric field in a row is allowed, but got several: " + arrayList2 + ". Parsing is undefined: for example, with variable-length month number and variable-length day of month, '111' can be parsed as Jan 11th or Nov 1st.").toString());
    }

    @Override // defpackage.p37
    public final Object a(yi1 yi1Var, String str, int i) {
        int i2 = this.b;
        if (i + i2 > str.length()) {
            return new y27(i, new hr6(this));
        }
        dw7.f fVar = new dw7.f();
        while (fVar.a + i < str.length() && kda.a(str.charAt(fVar.a + i))) {
            fVar.a++;
        }
        if (fVar.a < i2) {
            return new y27(i, new ir6(fVar, this));
        }
        List list = this.a;
        int size = list.size();
        int i3 = 0;
        while (i3 < size) {
            Integer a = ((er6) list.get(i3)).getA();
            int iIntValue = (a != null ? a.intValue() : (fVar.a - i2) + 1) + i;
            gr6 gr6VarA = ((er6) list.get(i3)).a(str, i, iIntValue, yi1Var);
            if (gr6VarA != null) {
                return new y27(i, new jr6(str.subSequence(i, iIntValue).toString(), this, i3, gr6VarA));
            }
            i3++;
            i = iIntValue;
        }
        return Integer.valueOf(i);
    }

    public final String b() {
        List<er6> list = this.a;
        ArrayList arrayList = new ArrayList(y41.p(list, 10));
        for (er6 er6Var : list) {
            StringBuilder sb = new StringBuilder();
            Integer a = er6Var.getA();
            sb.append(a == null ? "at least one digit" : a + " digits");
            sb.append(" for ");
            sb.append(er6Var.b);
            arrayList.add(sb.toString());
        }
        boolean z = this.c;
        int i = this.b;
        if (z) {
            return "a number with at least " + i + " digits: " + arrayList;
        }
        return "a number with exactly " + i + " digits: " + arrayList;
    }

    public final String toString() {
        return b();
    }
}
