package h0;

import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import e0.b;
import g0.l0;
import h2.f0;
import h2.p0;
import java.util.ArrayList;
import java.util.List;
import l1.c;
import rm.n0;
import tp.m0;
import y0.q1;

/* loaded from: classes.dex */
public abstract class s {

    /* loaded from: classes.dex */
    static final class a extends kotlin.jvm.internal.v implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ List f20592p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ q1 f20593q;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        a(List list, q1 q1Var) {
            super(1);
            this.f20592p = list;
            this.f20593q = q1Var;
        }

        public final void a(p0.a aVar) {
            List list = this.f20592p;
            int size = list.size();
            for (int i10 = 0; i10 < size; i10++) {
                ((e) list.get(i10)).h(aVar);
            }
            l0.a(this.f20593q);
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((p0.a) obj);
            return n0.f34904a;
        }
    }

    /* loaded from: classes.dex */
    static final class b extends kotlin.jvm.internal.v implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        public static final b f20594p = new b();

        b() {
            super(1);
        }

        public final void a(p0.a aVar) {
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((p0.a) obj);
            return n0.f34904a;
        }
    }

    /* loaded from: classes.dex */
    static final class c extends kotlin.jvm.internal.v implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ g0.w f20595p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ long f20596q;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ r f20597r;

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ long f20598s;

        /* renamed from: t, reason: collision with root package name */
        final /* synthetic */ b0.q f20599t;

        /* renamed from: u, reason: collision with root package name */
        final /* synthetic */ c.b f20600u;

        /* renamed from: v, reason: collision with root package name */
        final /* synthetic */ c.InterfaceC0608c f20601v;

        /* renamed from: w, reason: collision with root package name */
        final /* synthetic */ boolean f20602w;

        /* renamed from: x, reason: collision with root package name */
        final /* synthetic */ int f20603x;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        c(g0.w wVar, long j10, r rVar, long j11, b0.q qVar, c.b bVar, c.InterfaceC0608c interfaceC0608c, boolean z10, int i10) {
            super(1);
            this.f20595p = wVar;
            this.f20596q = j10;
            this.f20597r = rVar;
            this.f20598s = j11;
            this.f20599t = qVar;
            this.f20600u = bVar;
            this.f20601v = interfaceC0608c;
            this.f20602w = z10;
            this.f20603x = i10;
        }

        public final e a(int i10) {
            g0.w wVar = this.f20595p;
            return s.g(wVar, i10, this.f20596q, this.f20597r, this.f20598s, this.f20599t, this.f20600u, this.f20601v, wVar.getLayoutDirection(), this.f20602w, this.f20603x);
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            return a(((Number) obj).intValue());
        }
    }

    /* loaded from: classes.dex */
    static final class d extends kotlin.jvm.internal.v implements dn.l {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ g0.w f20604p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ long f20605q;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ r f20606r;

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ long f20607s;

        /* renamed from: t, reason: collision with root package name */
        final /* synthetic */ b0.q f20608t;

        /* renamed from: u, reason: collision with root package name */
        final /* synthetic */ c.b f20609u;

        /* renamed from: v, reason: collision with root package name */
        final /* synthetic */ c.InterfaceC0608c f20610v;

        /* renamed from: w, reason: collision with root package name */
        final /* synthetic */ boolean f20611w;

        /* renamed from: x, reason: collision with root package name */
        final /* synthetic */ int f20612x;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        d(g0.w wVar, long j10, r rVar, long j11, b0.q qVar, c.b bVar, c.InterfaceC0608c interfaceC0608c, boolean z10, int i10) {
            super(1);
            this.f20604p = wVar;
            this.f20605q = j10;
            this.f20606r = rVar;
            this.f20607s = j11;
            this.f20608t = qVar;
            this.f20609u = bVar;
            this.f20610v = interfaceC0608c;
            this.f20611w = z10;
            this.f20612x = i10;
        }

        public final e a(int i10) {
            g0.w wVar = this.f20604p;
            return s.g(wVar, i10, this.f20605q, this.f20606r, this.f20607s, this.f20608t, this.f20609u, this.f20610v, wVar.getLayoutDirection(), this.f20611w, this.f20612x);
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            return a(((Number) obj).intValue());
        }
    }

    private static final e b(int i10, List list, int i11, int i12, int i13, c0.j jVar, int i14) {
        int m10;
        Object obj;
        if (list.isEmpty()) {
            obj = null;
        } else {
            Object obj2 = list.get(0);
            e eVar = (e) obj2;
            float f10 = -Math.abs(c0.k.a(i10, i11, i12, i13, eVar.b(), eVar.getIndex(), jVar, i14));
            m10 = sm.u.m(list);
            int i15 = 1;
            if (1 <= m10) {
                while (true) {
                    Object obj3 = list.get(i15);
                    e eVar2 = (e) obj3;
                    float f11 = -Math.abs(c0.k.a(i10, i11, i12, i13, eVar2.b(), eVar2.getIndex(), jVar, i14));
                    if (Float.compare(f10, f11) < 0) {
                        obj2 = obj3;
                        f10 = f11;
                    }
                    if (i15 == m10) {
                        break;
                    }
                    i15++;
                }
            }
            obj = obj2;
        }
        return (e) obj;
    }

    private static final List c(g0.w wVar, List list, List list2, List list3, int i10, int i11, int i12, int i13, int i14, b0.q qVar, boolean z10, c3.d dVar, int i15, int i16) {
        int i17;
        int i18;
        jn.g U;
        int i19 = i14;
        int i20 = i16 + i15;
        if (qVar == b0.q.Vertical) {
            i17 = i13;
            i18 = i11;
        } else {
            i17 = i13;
            i18 = i10;
        }
        boolean z11 = i12 < Math.min(i18, i17);
        if (z11) {
            if (!(i19 == 0)) {
                throw new IllegalStateException(("non-zero pagesScrollOffset=" + i19).toString());
            }
        }
        ArrayList arrayList = new ArrayList(list.size() + list2.size() + list3.size());
        if (z11) {
            if (!(list2.isEmpty() && list3.isEmpty())) {
                throw new IllegalArgumentException("No extra pages".toString());
            }
            int size = list.size();
            int[] iArr = new int[size];
            for (int i21 = 0; i21 < size; i21++) {
                iArr[i21] = i16;
            }
            int[] iArr2 = new int[size];
            for (int i22 = 0; i22 < size; i22++) {
                iArr2[i22] = 0;
            }
            b.f c10 = b.a.f16616a.c(wVar.w(i15));
            if (qVar == b0.q.Vertical) {
                c10.c(dVar, i18, iArr, iArr2);
            } else {
                c10.b(dVar, i18, iArr, c3.t.Ltr, iArr2);
            }
            U = sm.p.U(iArr2);
            if (z10) {
                U = jn.o.o(U);
            }
            int g10 = U.g();
            int m10 = U.m();
            int r10 = U.r();
            if ((r10 > 0 && g10 <= m10) || (r10 < 0 && m10 <= g10)) {
                while (true) {
                    int i23 = iArr2[g10];
                    e eVar = (e) list.get(d(g10, z10, size));
                    if (z10) {
                        i23 = (i18 - i23) - eVar.g();
                    }
                    eVar.i(i23, i10, i11);
                    arrayList.add(eVar);
                    if (g10 == m10) {
                        break;
                    }
                    g10 += r10;
                }
            }
        } else {
            int size2 = list2.size();
            int i24 = i19;
            for (int i25 = 0; i25 < size2; i25++) {
                e eVar2 = (e) list2.get(i25);
                i24 -= i20;
                eVar2.i(i24, i10, i11);
                arrayList.add(eVar2);
            }
            int size3 = list.size();
            for (int i26 = 0; i26 < size3; i26++) {
                e eVar3 = (e) list.get(i26);
                eVar3.i(i19, i10, i11);
                arrayList.add(eVar3);
                i19 += i20;
            }
            int size4 = list3.size();
            for (int i27 = 0; i27 < size4; i27++) {
                e eVar4 = (e) list3.get(i27);
                eVar4.i(i19, i10, i11);
                arrayList.add(eVar4);
                i19 += i20;
            }
        }
        return arrayList;
    }

    private static final int d(int i10, boolean z10, int i11) {
        return !z10 ? i10 : (i11 - i10) - 1;
    }

    private static final List e(int i10, int i11, int i12, List list, dn.l lVar) {
        List k10;
        int min = Math.min(i12 + i10, i11 - 1);
        int i13 = i10 + 1;
        ArrayList arrayList = null;
        if (i13 <= min) {
            while (true) {
                if (arrayList == null) {
                    arrayList = new ArrayList();
                }
                arrayList.add(lVar.invoke(Integer.valueOf(i13)));
                if (i13 == min) {
                    break;
                }
                i13++;
            }
        }
        int size = list.size();
        for (int i14 = 0; i14 < size; i14++) {
            int intValue = ((Number) list.get(i14)).intValue();
            if (min + 1 <= intValue && intValue < i11) {
                if (arrayList == null) {
                    arrayList = new ArrayList();
                }
                arrayList.add(lVar.invoke(Integer.valueOf(intValue)));
            }
        }
        if (arrayList != null) {
            return arrayList;
        }
        k10 = sm.u.k();
        return k10;
    }

    private static final List f(int i10, int i11, List list, dn.l lVar) {
        List k10;
        int max = Math.max(0, i10 - i11);
        int i12 = i10 - 1;
        ArrayList arrayList = null;
        if (max <= i12) {
            while (true) {
                if (arrayList == null) {
                    arrayList = new ArrayList();
                }
                arrayList.add(lVar.invoke(Integer.valueOf(i12)));
                if (i12 == max) {
                    break;
                }
                i12--;
            }
        }
        int size = list.size();
        for (int i13 = 0; i13 < size; i13++) {
            int intValue = ((Number) list.get(i13)).intValue();
            if (intValue < max) {
                if (arrayList == null) {
                    arrayList = new ArrayList();
                }
                arrayList.add(lVar.invoke(Integer.valueOf(intValue)));
            }
        }
        if (arrayList != null) {
            return arrayList;
        }
        k10 = sm.u.k();
        return k10;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final e g(g0.w wVar, int i10, long j10, r rVar, long j11, b0.q qVar, c.b bVar, c.InterfaceC0608c interfaceC0608c, c3.t tVar, boolean z10, int i11) {
        return new e(i10, i11, wVar.x0(i10, j10), j11, rVar.b(i10), qVar, bVar, interfaceC0608c, tVar, z10, null);
    }

    /* JADX WARN: Multi-variable type inference failed */
    public static final u h(g0.w wVar, int i10, r rVar, int i11, int i12, int i13, int i14, int i15, int i16, long j10, b0.q qVar, c.InterfaceC0608c interfaceC0608c, c.b bVar, boolean z10, long j11, int i17, int i18, List list, c0.j jVar, q1 q1Var, m0 m0Var, dn.q qVar2) {
        int d10;
        int d11;
        int i19;
        int i20;
        int i21;
        int i22;
        int i23;
        e eVar;
        int i24;
        int m10;
        long j12;
        int i25;
        List list2;
        List arrayList;
        List arrayList2;
        List k10;
        int i26 = 0;
        if (!(i12 >= 0)) {
            throw new IllegalArgumentException("negative beforeContentPadding".toString());
        }
        if (!(i13 >= 0)) {
            throw new IllegalArgumentException("negative afterContentPadding".toString());
        }
        d10 = jn.o.d(i17 + i14, 0);
        if (i10 <= 0) {
            k10 = sm.u.k();
            return new u(k10, i17, i14, i13, qVar, -i12, i11 + i13, false, i18, null, null, BitmapDescriptorFactory.HUE_RED, 0, false, jVar, (f0) qVar2.invoke(Integer.valueOf(c3.b.n(j10)), Integer.valueOf(c3.b.m(j10)), b.f20594p), false, null, null, m0Var, 393216, null);
        }
        b0.q qVar3 = b0.q.Vertical;
        long b10 = c3.c.b(0, qVar == qVar3 ? c3.b.l(j10) : i17, 0, qVar != qVar3 ? c3.b.k(j10) : i17, 5, null);
        int i27 = i15;
        int i28 = i16;
        while (i27 > 0 && i28 > 0) {
            i27--;
            i28 -= d10;
        }
        int i29 = i28 * (-1);
        if (i27 >= i10) {
            i27 = i10 - 1;
            i29 = 0;
        }
        sm.k kVar = new sm.k();
        int i30 = -i12;
        int i31 = (i14 < 0 ? i14 : 0) + i30;
        int i32 = i29 + i31;
        int i33 = 0;
        while (i32 < 0 && i27 > 0) {
            int i34 = i27 - 1;
            sm.k kVar2 = kVar;
            int i35 = i26;
            int i36 = d10;
            e g10 = g(wVar, i34, b10, rVar, j11, qVar, bVar, interfaceC0608c, wVar.getLayoutDirection(), z10, i17);
            kVar2.add(i35, g10);
            i33 = Math.max(i33, g10.c());
            i32 += i36;
            i27 = i34;
            i31 = i31;
            kVar = kVar2;
            i26 = i35;
            d10 = i36;
            i30 = i30;
        }
        int i37 = i32;
        int i38 = i30;
        int i39 = i31;
        sm.k kVar3 = kVar;
        int i40 = i26;
        int i41 = d10;
        int i42 = (i37 < i39 ? i39 : i37) - i39;
        int i43 = i11 + i13;
        d11 = jn.o.d(i43, i40);
        int i44 = -i42;
        int i45 = i40;
        int i46 = i45;
        int i47 = i27;
        while (i45 < kVar3.size()) {
            if (i44 >= d11) {
                kVar3.remove(i45);
                i46 = 1;
            } else {
                i47++;
                i44 += i41;
                i45++;
            }
        }
        int i48 = i27;
        int i49 = i42;
        int i50 = i46;
        int i51 = i47;
        int i52 = i44;
        while (i51 < i10 && (i52 < d11 || i52 <= 0 || kVar3.isEmpty())) {
            int i53 = i43;
            int i54 = i51;
            int i55 = i48;
            int i56 = d11;
            int i57 = i52;
            int i58 = i41;
            e g11 = g(wVar, i51, b10, rVar, j11, qVar, bVar, interfaceC0608c, wVar.getLayoutDirection(), z10, i17);
            int i59 = i10 - 1;
            i52 = (i54 == i59 ? i17 : i58) + i57;
            if (i52 > i39 || i54 == i59) {
                i33 = Math.max(i33, g11.c());
                kVar3.add(g11);
                i48 = i55;
            } else {
                i49 -= i58;
                i48 = i54 + 1;
                i50 = 1;
            }
            i51 = i54 + 1;
            i43 = i53;
            i41 = i58;
            d11 = i56;
        }
        int i60 = i48;
        int i61 = i43;
        int i62 = i51;
        int i63 = i52;
        int i64 = i41;
        if (i63 < i11) {
            int i65 = i11 - i63;
            int i66 = i49 - i65;
            int i67 = i65 + i63;
            int i68 = i12;
            i23 = i60;
            int i69 = i64;
            int i70 = i66;
            while (i70 < i68 && i23 > 0) {
                i23--;
                int i71 = i69;
                e g12 = g(wVar, i23, b10, rVar, j11, qVar, bVar, interfaceC0608c, wVar.getLayoutDirection(), z10, i17);
                kVar3.add(0, g12);
                i33 = Math.max(i33, g12.c());
                i70 += i71;
                i68 = i12;
                i69 = i71;
            }
            i19 = i69;
            i20 = 0;
            if (i70 < 0) {
                i21 = i67 + i70;
                i22 = 0;
            } else {
                i22 = i70;
                i21 = i67;
            }
        } else {
            i19 = i64;
            i20 = 0;
            i21 = i63;
            i22 = i49;
            i23 = i60;
        }
        if ((i22 >= 0 ? 1 : i20) == 0) {
            throw new IllegalArgumentException("invalid currentFirstPageScrollOffset".toString());
        }
        int i72 = -i22;
        e eVar2 = (e) kVar3.first();
        if (i12 > 0 || i14 < 0) {
            int size = kVar3.size();
            int i73 = i22;
            int i74 = i20;
            while (i74 < size && i73 != 0 && i19 <= i73) {
                m10 = sm.u.m(kVar3);
                if (i74 == m10) {
                    break;
                }
                i73 -= i19;
                i74++;
                eVar2 = (e) kVar3.get(i74);
            }
            eVar = eVar2;
            i24 = i73;
        } else {
            i24 = i22;
            eVar = eVar2;
        }
        int i75 = i33;
        e eVar3 = eVar;
        int i76 = i20;
        List f10 = f(i23, i18, list, new d(wVar, b10, rVar, j11, qVar, bVar, interfaceC0608c, z10, i17));
        int size2 = f10.size();
        int i77 = i75;
        for (int i78 = i76; i78 < size2; i78++) {
            i77 = Math.max(i77, ((e) f10.get(i78)).c());
        }
        int i79 = i19;
        List e10 = e(((e) kVar3.last()).getIndex(), i10, i18, list, new c(wVar, b10, rVar, j11, qVar, bVar, interfaceC0608c, z10, i17));
        int size3 = e10.size();
        int i80 = i77;
        for (int i81 = i76; i81 < size3; i81++) {
            i80 = Math.max(i80, ((e) e10.get(i81)).c());
        }
        int i82 = (kotlin.jvm.internal.t.b(eVar3, kVar3.first()) && f10.isEmpty() && e10.isEmpty()) ? 1 : i76;
        b0.q qVar4 = b0.q.Vertical;
        if (qVar == qVar4) {
            j12 = j10;
            i25 = i80;
        } else {
            j12 = j10;
            i25 = i21;
        }
        int i83 = c3.c.i(j12, i25);
        if (qVar == qVar4) {
            i80 = i21;
        }
        int h10 = c3.c.h(j12, i80);
        List c10 = c(wVar, kVar3, f10, e10, i83, h10, i21, i11, i72, qVar, z10, wVar, i14, i17);
        if (i82 != 0) {
            list2 = c10;
        } else {
            ArrayList arrayList3 = new ArrayList(c10.size());
            int size4 = c10.size();
            for (int i84 = i76; i84 < size4; i84++) {
                Object obj = c10.get(i84);
                e eVar4 = (e) obj;
                if (((eVar4.getIndex() < ((e) kVar3.first()).getIndex() || eVar4.getIndex() > ((e) kVar3.last()).getIndex()) ? i76 : 1) != 0) {
                    arrayList3.add(obj);
                }
            }
            list2 = arrayList3;
        }
        if (f10.isEmpty()) {
            arrayList = sm.u.k();
        } else {
            arrayList = new ArrayList(c10.size());
            int size5 = c10.size();
            for (int i85 = i76; i85 < size5; i85++) {
                Object obj2 = c10.get(i85);
                if ((((e) obj2).getIndex() < ((e) kVar3.first()).getIndex() ? 1 : i76) != 0) {
                    arrayList.add(obj2);
                }
            }
        }
        List list3 = arrayList;
        if (e10.isEmpty()) {
            arrayList2 = sm.u.k();
        } else {
            arrayList2 = new ArrayList(c10.size());
            int size6 = c10.size();
            for (int i86 = i76; i86 < size6; i86++) {
                Object obj3 = c10.get(i86);
                if ((((e) obj3).getIndex() > ((e) kVar3.last()).getIndex() ? 1 : i76) != 0) {
                    arrayList2.add(obj3);
                }
            }
        }
        List list4 = arrayList2;
        int i87 = i21;
        e b11 = b(qVar == b0.q.Vertical ? h10 : i83, list2, i12, i13, i79, jVar, i10);
        return new u(list2, i17, i14, i13, qVar, i38, i61, z10, i18, eVar3, b11, i79 == 0 ? BitmapDescriptorFactory.HUE_RED : jn.o.j((jVar.a(i11, i17, i12, i13, b11 != null ? b11.getIndex() : i76, i10) - (b11 != null ? b11.b() : i76)) / i79, -0.5f, 0.5f), i24, (i62 < i10 || i87 > i11) ? 1 : i76, jVar, (f0) qVar2.invoke(Integer.valueOf(i83), Integer.valueOf(h10), new a(c10, q1Var)), i50, list3, list4, m0Var);
    }
}
