package androidx.compose.foundation.lazy.layout;

import b0.q;
import dn.l;
import dn.p;
import g0.e0;
import g0.s;
import j2.s1;
import j2.t1;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import l1.i;
import o2.u;
import rm.n0;
import rm.y;
import tp.k;
import tp.m0;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes.dex */
public final class g extends i.c implements s1 {
    private dn.a C;
    private e0 D;
    private q E;
    private boolean F;
    private boolean G;
    private o2.g H;
    private final l I = new b();
    private l J;

    /* loaded from: classes.dex */
    static final class a extends v implements dn.a {
        a() {
            super(0);
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Float invoke() {
            return Float.valueOf(g.this.D.a() - g.this.D.c());
        }
    }

    /* loaded from: classes.dex */
    static final class b extends v implements l {
        b() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Integer invoke(Object obj) {
            s sVar = (s) g.this.C.invoke();
            int a10 = sVar.a();
            int i10 = 0;
            while (true) {
                if (i10 >= a10) {
                    i10 = -1;
                    break;
                }
                if (t.b(sVar.b(i10), obj)) {
                    break;
                }
                i10++;
            }
            return Integer.valueOf(i10);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class c extends v implements dn.a {
        c() {
            super(0);
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Float invoke() {
            return Float.valueOf(g.this.D.b());
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class d extends v implements dn.a {
        d() {
            super(0);
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final Float invoke() {
            return Float.valueOf(g.this.D.d());
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public static final class e extends v implements l {

        /* JADX INFO: Access modifiers changed from: package-private */
        /* loaded from: classes.dex */
        public static final class a extends kotlin.coroutines.jvm.internal.l implements p {

            /* renamed from: p, reason: collision with root package name */
            int f1935p;

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

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

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            a(g gVar, int i10, vm.d dVar) {
                super(2, dVar);
                this.f1936q = gVar;
                this.f1937r = i10;
            }

            @Override // kotlin.coroutines.jvm.internal.a
            public final vm.d create(Object obj, vm.d dVar) {
                return new a(this.f1936q, this.f1937r, dVar);
            }

            @Override // kotlin.coroutines.jvm.internal.a
            public final Object invokeSuspend(Object obj) {
                Object f10;
                f10 = wm.d.f();
                int i10 = this.f1935p;
                if (i10 == 0) {
                    y.b(obj);
                    e0 e0Var = this.f1936q.D;
                    int i11 = this.f1937r;
                    this.f1935p = 1;
                    if (e0Var.f(i11, this) == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    y.b(obj);
                }
                return n0.f34904a;
            }

            @Override // dn.p
            public final Object invoke(m0 m0Var, vm.d dVar) {
                return ((a) create(m0Var, dVar)).invokeSuspend(n0.f34904a);
            }
        }

        e() {
            super(1);
        }

        public final Boolean a(int i10) {
            s sVar = (s) g.this.C.invoke();
            if (i10 >= 0 && i10 < sVar.a()) {
                k.d(g.this.H1(), null, null, new a(g.this, i10, null), 3, null);
                return Boolean.TRUE;
            }
            throw new IllegalArgumentException(("Can't scroll to index " + i10 + ", it is out of bounds [0, " + sVar.a() + ')').toString());
        }

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

    public g(dn.a aVar, e0 e0Var, q qVar, boolean z10, boolean z11) {
        this.C = aVar;
        this.D = e0Var;
        this.E = qVar;
        this.F = z10;
        this.G = z11;
        m2();
    }

    private final o2.b j2() {
        return this.D.e();
    }

    private final boolean k2() {
        return this.E == q.Vertical;
    }

    private final void m2() {
        this.H = new o2.g(new c(), new d(), this.G);
        this.J = this.F ? new e() : null;
    }

    @Override // j2.s1
    public void B0(u uVar) {
        o2.s.s0(uVar, true);
        o2.s.s(uVar, this.I);
        if (k2()) {
            o2.g gVar = this.H;
            if (gVar == null) {
                t.y("scrollAxisRange");
                gVar = null;
            }
            o2.s.u0(uVar, gVar);
        } else {
            o2.g gVar2 = this.H;
            if (gVar2 == null) {
                t.y("scrollAxisRange");
                gVar2 = null;
            }
            o2.s.c0(uVar, gVar2);
        }
        l lVar = this.J;
        if (lVar != null) {
            o2.s.U(uVar, null, lVar, 1, null);
        }
        o2.s.p(uVar, null, new a(), 1, null);
        o2.s.W(uVar, j2());
    }

    @Override // l1.i.c
    public boolean M1() {
        return false;
    }

    public final void l2(dn.a aVar, e0 e0Var, q qVar, boolean z10, boolean z11) {
        this.C = aVar;
        this.D = e0Var;
        if (this.E != qVar) {
            this.E = qVar;
            t1.b(this);
        }
        if (this.F == z10 && this.G == z11) {
            return;
        }
        this.F = z10;
        this.G = z11;
        m2();
        t1.b(this);
    }
}
