package f0;

import androidx.compose.foundation.lazy.layout.LazyLayoutItemAnimator;
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 rm.n0;
import s1.s0;
import tp.m0;
import y0.q1;

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

    /* 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 */
        public static final a f17485p = new a();

        a() {
            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 b extends kotlin.jvm.internal.v implements dn.l {

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

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

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

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        b(List list, t tVar, boolean z10, q1 q1Var) {
            super(1);
            this.f17486p = list;
            this.f17487q = tVar;
            this.f17488r = z10;
            this.f17489s = q1Var;
        }

        public final void a(p0.a aVar) {
            List list = this.f17486p;
            t tVar = this.f17487q;
            boolean z10 = this.f17488r;
            int size = list.size();
            for (int i10 = 0; i10 < size; i10++) {
                t tVar2 = (t) list.get(i10);
                if (tVar2 != tVar) {
                    tVar2.r(aVar, z10);
                }
            }
            t tVar3 = this.f17487q;
            if (tVar3 != null) {
                tVar3.r(aVar, this.f17488r);
            }
            l0.a(this.f17489s);
        }

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

    private static final List a(List list, List list2, List list3, int i10, int i11, int i12, int i13, int i14, boolean z10, b.m mVar, b.e eVar, boolean z11, c3.d dVar) {
        jn.g U;
        int i15 = z10 ? i11 : i10;
        boolean z12 = i12 < Math.min(i15, i13);
        if (z12) {
            if (!(i14 == 0)) {
                throw new IllegalStateException("non-zero itemsScrollOffset".toString());
            }
        }
        ArrayList arrayList = new ArrayList(list.size() + list2.size() + list3.size());
        if (z12) {
            if (!(list2.isEmpty() && list3.isEmpty())) {
                throw new IllegalArgumentException("no extra items".toString());
            }
            int size = list.size();
            int[] iArr = new int[size];
            for (int i16 = 0; i16 < size; i16++) {
                iArr[i16] = ((t) list.get(b(i16, z11, size))).a();
            }
            int[] iArr2 = new int[size];
            for (int i17 = 0; i17 < size; i17++) {
                iArr2[i17] = 0;
            }
            if (z10) {
                if (mVar == null) {
                    throw new IllegalArgumentException("null verticalArrangement when isVertical == true".toString());
                }
                mVar.c(dVar, i15, iArr, iArr2);
            } else {
                if (eVar == null) {
                    throw new IllegalArgumentException("null horizontalArrangement when isVertical == false".toString());
                }
                eVar.b(dVar, i15, iArr, c3.t.Ltr, iArr2);
            }
            U = sm.p.U(iArr2);
            if (z11) {
                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 i18 = iArr2[g10];
                    t tVar = (t) list.get(b(g10, z11, size));
                    if (z11) {
                        i18 = (i15 - i18) - tVar.a();
                    }
                    tVar.s(i18, i10, i11);
                    arrayList.add(tVar);
                    if (g10 == m10) {
                        break;
                    }
                    g10 += r10;
                }
            }
        } else {
            int size2 = list2.size();
            int i19 = i14;
            for (int i20 = 0; i20 < size2; i20++) {
                t tVar2 = (t) list2.get(i20);
                i19 -= tVar2.e();
                tVar2.s(i19, i10, i11);
                arrayList.add(tVar2);
            }
            int size3 = list.size();
            int i21 = i14;
            for (int i22 = 0; i22 < size3; i22++) {
                t tVar3 = (t) list.get(i22);
                tVar3.s(i21, i10, i11);
                arrayList.add(tVar3);
                i21 += tVar3.e();
            }
            int size4 = list3.size();
            for (int i23 = 0; i23 < size4; i23++) {
                t tVar4 = (t) list3.get(i23);
                tVar4.s(i21, i10, i11);
                arrayList.add(tVar4);
                i21 += tVar4.e();
            }
        }
        return arrayList;
    }

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

    private static final List c(List list, u uVar, int i10, int i11, List list2, float f10, boolean z10, q qVar) {
        Object o02;
        Object o03;
        ArrayList arrayList;
        List k10;
        Object o04;
        Object o05;
        l lVar;
        Object o06;
        t tVar;
        Object obj;
        Object o07;
        int e10;
        Object obj2;
        int index;
        int min;
        t tVar2;
        Object obj3;
        o02 = sm.c0.o0(list);
        int i12 = i10 - 1;
        int min2 = Math.min(((t) o02).getIndex() + i11, i12);
        o03 = sm.c0.o0(list);
        int index2 = ((t) o03).getIndex() + 1;
        if (index2 <= min2) {
            ArrayList arrayList2 = null;
            while (true) {
                if (arrayList2 == null) {
                    arrayList2 = new ArrayList();
                }
                arrayList = arrayList2;
                arrayList.add(u.e(uVar, index2, 0L, 2, null));
                if (index2 == min2) {
                    break;
                }
                index2++;
                arrayList2 = arrayList;
            }
        } else {
            arrayList = null;
        }
        if (z10 && qVar != null && (!qVar.k().isEmpty())) {
            List k11 = qVar.k();
            for (int size = k11.size() - 1; -1 < size; size--) {
                if (((l) k11.get(size)).getIndex() > min2 && (size == 0 || ((l) k11.get(size - 1)).getIndex() <= min2)) {
                    lVar = (l) k11.get(size);
                    break;
                }
            }
            lVar = null;
            o06 = sm.c0.o0(qVar.k());
            l lVar2 = (l) o06;
            if (lVar != null && (index = lVar.getIndex()) <= (min = Math.min(lVar2.getIndex(), i12))) {
                while (true) {
                    if (arrayList != null) {
                        int size2 = arrayList.size();
                        int i13 = 0;
                        while (true) {
                            if (i13 >= size2) {
                                obj3 = null;
                                break;
                            }
                            obj3 = arrayList.get(i13);
                            if (((t) obj3).getIndex() == index) {
                                break;
                            }
                            i13++;
                        }
                        tVar2 = (t) obj3;
                    } else {
                        tVar2 = null;
                    }
                    if (tVar2 == null) {
                        if (arrayList == null) {
                            arrayList = new ArrayList();
                        }
                        arrayList.add(u.e(uVar, index, 0L, 2, null));
                    }
                    if (index == min) {
                        break;
                    }
                    index++;
                }
            }
            float c10 = ((qVar.c() - lVar2.b()) - lVar2.a()) - f10;
            if (c10 > BitmapDescriptorFactory.HUE_RED) {
                int index3 = lVar2.getIndex() + 1;
                int i14 = 0;
                while (index3 < i10 && i14 < c10) {
                    if (index3 <= min2) {
                        int size3 = list.size();
                        int i15 = 0;
                        while (true) {
                            if (i15 >= size3) {
                                obj2 = null;
                                break;
                            }
                            obj2 = list.get(i15);
                            if (((t) obj2).getIndex() == index3) {
                                break;
                            }
                            i15++;
                        }
                        tVar = (t) obj2;
                    } else if (arrayList != null) {
                        int size4 = arrayList.size();
                        int i16 = 0;
                        while (true) {
                            if (i16 >= size4) {
                                obj = null;
                                break;
                            }
                            obj = arrayList.get(i16);
                            if (((t) obj).getIndex() == index3) {
                                break;
                            }
                            i16++;
                        }
                        tVar = (t) obj;
                    } else {
                        tVar = null;
                    }
                    if (tVar != null) {
                        index3++;
                        e10 = tVar.e();
                    } else {
                        if (arrayList == null) {
                            arrayList = new ArrayList();
                        }
                        arrayList.add(u.e(uVar, index3, 0L, 2, null));
                        index3++;
                        o07 = sm.c0.o0(arrayList);
                        e10 = ((t) o07).e();
                    }
                    i14 += e10;
                }
            }
        }
        if (arrayList != null) {
            o04 = sm.c0.o0(arrayList);
            if (((t) o04).getIndex() > min2) {
                o05 = sm.c0.o0(arrayList);
                min2 = ((t) o05).getIndex();
            }
        }
        int size5 = list2.size();
        for (int i17 = 0; i17 < size5; i17++) {
            int intValue = ((Number) list2.get(i17)).intValue();
            if (intValue > min2) {
                if (arrayList == null) {
                    arrayList = new ArrayList();
                }
                arrayList.add(u.e(uVar, intValue, 0L, 2, null));
            }
        }
        if (arrayList != null) {
            return arrayList;
        }
        k10 = sm.u.k();
        return k10;
    }

    private static final List d(int i10, u uVar, int i11, List list) {
        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(u.e(uVar, i12, 0L, 2, null));
                if (i12 == max) {
                    break;
                }
                i12--;
            }
        }
        int size = list.size() - 1;
        if (size >= 0) {
            while (true) {
                int i13 = size - 1;
                int intValue = ((Number) list.get(size)).intValue();
                if (intValue < max) {
                    if (arrayList == null) {
                        arrayList = new ArrayList();
                    }
                    arrayList.add(u.e(uVar, intValue, 0L, 2, null));
                }
                if (i13 < 0) {
                    break;
                }
                size = i13;
            }
        }
        if (arrayList != null) {
            return arrayList;
        }
        k10 = sm.u.k();
        return k10;
    }

    /* JADX WARN: Removed duplicated region for block: B:122:0x03a0  */
    /* JADX WARN: Removed duplicated region for block: B:125:0x03b5  */
    /* JADX WARN: Removed duplicated region for block: B:130:0x03dd  */
    /* JADX WARN: Removed duplicated region for block: B:132:0x0429  */
    /* JADX WARN: Removed duplicated region for block: B:135:0x042c  */
    /* JADX WARN: Removed duplicated region for block: B:136:0x03df  */
    /* JADX WARN: Removed duplicated region for block: B:153:0x03c0  */
    /* JADX WARN: Removed duplicated region for block: B:154:0x03ae  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final s e(int i10, u uVar, int i11, int i12, int i13, int i14, int i15, int i16, float f10, long j10, boolean z10, List list, b.m mVar, b.e eVar, boolean z11, c3.d dVar, LazyLayoutItemAnimator lazyLayoutItemAnimator, int i17, List list2, boolean z12, boolean z13, q qVar, m0 m0Var, q1 q1Var, s0 s0Var, dn.q qVar2) {
        int i18;
        int d10;
        int i19;
        int i20;
        int i21;
        int i22;
        int i23;
        int a10;
        int a11;
        int i24;
        u uVar2;
        t tVar;
        int i25;
        int i26;
        int m10;
        int i27;
        int i28;
        boolean z14;
        boolean z15;
        List list3;
        int i29;
        int i30;
        List k10;
        int i31 = 0;
        if (!(i12 >= 0)) {
            throw new IllegalArgumentException("invalid beforeContentPadding".toString());
        }
        if (!(i13 >= 0)) {
            throw new IllegalArgumentException("invalid afterContentPadding".toString());
        }
        if (i10 <= 0) {
            int n10 = c3.b.n(j10);
            int m11 = c3.b.m(j10);
            lazyLayoutItemAnimator.l(0, n10, m11, new ArrayList(), uVar.g(), uVar, z10, z13, 1, z12, 0, 0, m0Var, s0Var);
            if (!z13) {
                long h10 = lazyLayoutItemAnimator.h();
                if (!c3.r.e(h10, c3.r.f7432b.a())) {
                    n10 = c3.c.i(j10, c3.r.g(h10));
                    m11 = c3.c.h(j10, c3.r.f(h10));
                }
            }
            f0 f0Var = (f0) qVar2.invoke(Integer.valueOf(n10), Integer.valueOf(m11), a.f17485p);
            k10 = sm.u.k();
            return new s(null, 0, false, BitmapDescriptorFactory.HUE_RED, f0Var, BitmapDescriptorFactory.HUE_RED, false, m0Var, dVar, uVar.f(), k10, -i12, i11 + i13, 0, z11, z10 ? b0.q.Vertical : b0.q.Horizontal, i13, i14, null);
        }
        int i32 = i15;
        if (i32 >= i10) {
            i32 = i10 - 1;
            i18 = 0;
        } else {
            i18 = i16;
        }
        int round = Math.round(f10);
        int i33 = i18 - round;
        if (i32 == 0 && i33 < 0) {
            round += i33;
            i33 = 0;
        }
        sm.k kVar = new sm.k();
        int i34 = -i12;
        int i35 = (i14 < 0 ? i14 : 0) + i34;
        int i36 = i33 + i35;
        int i37 = 0;
        while (i36 < 0 && i32 > 0) {
            i32--;
            t e10 = u.e(uVar, i32, 0L, 2, null);
            kVar.add(i31, e10);
            i37 = Math.max(i37, e10.n());
            i36 += e10.e();
            i31 = 0;
        }
        if (i36 < i35) {
            round += i36;
            i36 = i35;
        }
        int i38 = i36 - i35;
        int i39 = i11 + i13;
        int i40 = i32;
        d10 = jn.o.d(i39, 0);
        int i41 = i40;
        int i42 = i37;
        int i43 = -i38;
        int i44 = 0;
        boolean z16 = false;
        while (i44 < kVar.size()) {
            if (i43 >= d10) {
                kVar.remove(i44);
                z16 = true;
            } else {
                i41++;
                i43 += ((t) kVar.get(i44)).e();
                i44++;
            }
        }
        int i45 = i38;
        int i46 = i43;
        boolean z17 = z16;
        int i47 = i41;
        int i48 = i42;
        while (i47 < i10 && (i46 < d10 || i46 <= 0 || kVar.isEmpty())) {
            int i49 = d10;
            t e11 = u.e(uVar, i47, 0L, 2, null);
            i46 += e11.e();
            if (i46 <= i35) {
                i29 = i35;
                if (i47 != i10 - 1) {
                    i30 = i47 + 1;
                    i45 -= e11.e();
                    z17 = true;
                    i47++;
                    d10 = i49;
                    i40 = i30;
                    i35 = i29;
                }
            } else {
                i29 = i35;
            }
            i48 = Math.max(i48, e11.n());
            kVar.add(e11);
            i30 = i40;
            i47++;
            d10 = i49;
            i40 = i30;
            i35 = i29;
        }
        if (i46 < i11) {
            int i50 = i11 - i46;
            i45 -= i50;
            int i51 = i46 + i50;
            i20 = i48;
            i23 = i40;
            while (i45 < i12 && i23 > 0) {
                int i52 = i23 - 1;
                t e12 = u.e(uVar, i52, 0L, 2, null);
                kVar.add(0, e12);
                i20 = Math.max(i20, e12.n());
                i45 += e12.e();
                i23 = i52;
                i39 = i39;
            }
            i19 = i39;
            i21 = i50 + round;
            if (i45 < 0) {
                i21 += i45;
                i22 = i51 + i45;
                i45 = 0;
            } else {
                i22 = i51;
            }
        } else {
            i19 = i39;
            i20 = i48;
            i21 = round;
            i22 = i46;
            i23 = i40;
        }
        a10 = fn.c.a(Math.round(f10));
        int i53 = i20;
        a11 = fn.c.a(i21);
        float f11 = (a10 != a11 || Math.abs(Math.round(f10)) < Math.abs(i21)) ? f10 : i21;
        float f12 = f10 - f11;
        float f13 = (!z13 || i21 <= round || f12 > BitmapDescriptorFactory.HUE_RED) ? 0.0f : (i21 - round) + f12;
        if (!(i45 >= 0)) {
            throw new IllegalArgumentException("negative currentFirstItemScrollOffset".toString());
        }
        int i54 = -i45;
        t tVar2 = (t) kVar.first();
        if (i12 > 0 || i14 < 0) {
            int size = kVar.size();
            t tVar3 = tVar2;
            int i55 = i45;
            int i56 = 0;
            while (i56 < size) {
                int i57 = size;
                int e13 = ((t) kVar.get(i56)).e();
                if (i55 == 0 || e13 > i55) {
                    break;
                }
                i24 = i54;
                m10 = sm.u.m(kVar);
                if (i56 == m10) {
                    break;
                }
                i55 -= e13;
                i56++;
                tVar3 = (t) kVar.get(i56);
                i54 = i24;
                size = i57;
            }
            i24 = i54;
            uVar2 = uVar;
            tVar = tVar3;
            i25 = i17;
            i26 = i55;
        } else {
            i25 = i17;
            i24 = i54;
            i26 = i45;
            uVar2 = uVar;
            tVar = tVar2;
        }
        List d11 = d(i23, uVar2, i25, list2);
        int i58 = i47;
        int i59 = 0;
        int i60 = i53;
        for (int size2 = d11.size(); i59 < size2; size2 = size2) {
            i60 = Math.max(i60, ((t) d11.get(i59)).n());
            i59++;
        }
        float f14 = f11;
        t tVar4 = tVar;
        List c10 = c(kVar, uVar, i10, i17, list2, f14, z13, qVar);
        int size3 = c10.size();
        for (int i61 = 0; i61 < size3; i61++) {
            i60 = Math.max(i60, ((t) c10.get(i61)).n());
        }
        boolean z18 = kotlin.jvm.internal.t.b(tVar4, kVar.first()) && d11.isEmpty() && c10.isEmpty();
        int i62 = c3.c.i(j10, z10 ? i60 : i22);
        if (z10) {
            i60 = i22;
        }
        int h11 = c3.c.h(j10, i60);
        int i63 = i19;
        int i64 = i22;
        List a12 = a(kVar, d11, c10, i62, h11, i22, i11, i24, z10, mVar, eVar, z11, dVar);
        lazyLayoutItemAnimator.l((int) f14, i62, h11, a12, uVar.g(), uVar, z10, z13, 1, z12, i26, i64, m0Var, s0Var);
        if (!z13) {
            long h12 = lazyLayoutItemAnimator.h();
            if (!c3.r.e(h12, c3.r.f7432b.a())) {
                int i65 = z10 ? h11 : i62;
                int i66 = c3.c.i(j10, Math.max(i62, c3.r.g(h12)));
                i27 = c3.c.h(j10, Math.max(h11, c3.r.f(h12)));
                int i67 = z10 ? i27 : i66;
                if (i67 != i65) {
                    int size4 = a12.size();
                    for (int i68 = 0; i68 < size4; i68++) {
                        ((t) a12.get(i68)).t(i67);
                    }
                }
                i28 = i66;
                t a13 = !(list.isEmpty() ^ true) ? i.a(a12, uVar, list, i12, i28, i27) : null;
                if (i58 < i10) {
                    z14 = z13;
                    if (i64 <= i11) {
                        z15 = false;
                        f0 f0Var2 = (f0) qVar2.invoke(Integer.valueOf(i28), Integer.valueOf(i27), new b(a12, a13, z14, q1Var));
                        if (z18) {
                            list3 = a12;
                        } else {
                            ArrayList arrayList = new ArrayList(a12.size());
                            int size5 = a12.size();
                            for (int i69 = 0; i69 < size5; i69++) {
                                Object obj = a12.get(i69);
                                t tVar5 = (t) obj;
                                if ((tVar5.getIndex() >= ((t) kVar.first()).getIndex() && tVar5.getIndex() <= ((t) kVar.last()).getIndex()) || tVar5 == a13) {
                                    arrayList.add(obj);
                                }
                            }
                            list3 = arrayList;
                        }
                        return new s(tVar4, i26, z15, f14, f0Var2, f13, z17, m0Var, dVar, uVar.f(), list3, i34, i63, i10, z11, z10 ? b0.q.Vertical : b0.q.Horizontal, i13, i14, null);
                    }
                } else {
                    z14 = z13;
                }
                z15 = true;
                f0 f0Var22 = (f0) qVar2.invoke(Integer.valueOf(i28), Integer.valueOf(i27), new b(a12, a13, z14, q1Var));
                if (z18) {
                }
                if (z10) {
                }
                return new s(tVar4, i26, z15, f14, f0Var22, f13, z17, m0Var, dVar, uVar.f(), list3, i34, i63, i10, z11, z10 ? b0.q.Vertical : b0.q.Horizontal, i13, i14, null);
            }
        }
        i27 = h11;
        i28 = i62;
        if (!(list.isEmpty() ^ true)) {
        }
        if (i58 < i10) {
        }
        z15 = true;
        f0 f0Var222 = (f0) qVar2.invoke(Integer.valueOf(i28), Integer.valueOf(i27), new b(a12, a13, z14, q1Var));
        if (z18) {
        }
        if (z10) {
        }
        return new s(tVar4, i26, z15, f14, f0Var222, f13, z17, m0Var, dVar, uVar.f(), list3, i34, i63, i10, z11, z10 ? b0.q.Vertical : b0.q.Horizontal, i13, i14, null);
    }
}
