package b0;

import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import java.util.concurrent.CancellationException;
import l1.i;
import rm.n0;
import tp.a2;
import tp.l0;
import tp.m0;
import tp.o0;
import tp.u1;
import tp.y1;
import z.g0;

/* loaded from: classes.dex */
public final class f extends i.c implements i0.c, j2.a0, j2.h {
    private q C;
    private final z D;
    private boolean E;
    private d F;
    private final boolean G;
    private h2.s I;
    private r1.i J;
    private boolean K;
    private boolean M;
    private final b0.c H = new b0.c();
    private long L = c3.r.f7432b.a();

    /* loaded from: classes.dex */
    public static final class a {

        /* renamed from: a, reason: collision with root package name */
        private final dn.a f6327a;

        /* renamed from: b, reason: collision with root package name */
        private final tp.o f6328b;

        public a(dn.a aVar, tp.o oVar) {
            this.f6327a = aVar;
            this.f6328b = oVar;
        }

        public final tp.o a() {
            return this.f6328b;
        }

        public final dn.a b() {
            return this.f6327a;
        }

        public String toString() {
            int a10;
            android.support.v4.media.session.b.a(this.f6328b.getContext().d(l0.f36564q));
            StringBuilder sb2 = new StringBuilder();
            sb2.append("Request@");
            int hashCode = hashCode();
            a10 = kotlin.text.b.a(16);
            String num = Integer.toString(hashCode, a10);
            kotlin.jvm.internal.t.f(num, "toString(this, checkRadix(radix))");
            sb2.append(num);
            sb2.append("(");
            sb2.append("currentBounds()=");
            sb2.append(this.f6327a.invoke());
            sb2.append(", continuation=");
            sb2.append(this.f6328b);
            sb2.append(')');
            return sb2.toString();
        }
    }

    /* loaded from: classes.dex */
    public /* synthetic */ class b {

        /* renamed from: a, reason: collision with root package name */
        public static final /* synthetic */ int[] f6329a;

        static {
            int[] iArr = new int[q.values().length];
            try {
                iArr[q.Vertical.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[q.Horizontal.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            f6329a = iArr;
        }
    }

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

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

        /* renamed from: q, reason: collision with root package name */
        private /* synthetic */ Object f6331q;

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

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

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

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

            /* renamed from: q, reason: collision with root package name */
            private /* synthetic */ Object f6336q;

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

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

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

            /* renamed from: u, reason: collision with root package name */
            final /* synthetic */ u1 f6340u;

            /* JADX INFO: Access modifiers changed from: package-private */
            /* renamed from: b0.f$c$a$a, reason: collision with other inner class name */
            /* loaded from: classes.dex */
            public static final class C0167a extends kotlin.jvm.internal.v implements dn.l {

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

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

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

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

                /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
                C0167a(f fVar, e0 e0Var, u1 u1Var, p pVar) {
                    super(1);
                    this.f6341p = fVar;
                    this.f6342q = e0Var;
                    this.f6343r = u1Var;
                    this.f6344s = pVar;
                }

                public final void a(float f10) {
                    float f11 = this.f6341p.E ? 1.0f : -1.0f;
                    z zVar = this.f6341p.D;
                    float A = f11 * zVar.A(zVar.u(this.f6344s.b(zVar.u(zVar.B(f11 * f10)), c2.e.f7396a.b())));
                    if (Math.abs(A) < Math.abs(f10)) {
                        a2.e(this.f6343r, "Scroll animation cancelled because scroll was not consumed (" + A + " < " + f10 + ')', null, 2, null);
                    }
                }

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

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

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

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

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

                /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
                b(f fVar, e0 e0Var, d dVar) {
                    super(0);
                    this.f6345p = fVar;
                    this.f6346q = e0Var;
                    this.f6347r = dVar;
                }

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

                /* renamed from: invoke, reason: collision with other method in class */
                public final void m39invoke() {
                    b0.c cVar = this.f6345p.H;
                    f fVar = this.f6345p;
                    while (true) {
                        if (!cVar.f6290a.t()) {
                            break;
                        }
                        r1.i iVar = (r1.i) ((a) cVar.f6290a.u()).b().invoke();
                        if (!(iVar == null ? true : f.z2(fVar, iVar, 0L, 1, null))) {
                            break;
                        } else {
                            ((a) cVar.f6290a.z(cVar.f6290a.q() - 1)).a().resumeWith(rm.x.a(n0.f34904a));
                        }
                    }
                    if (this.f6345p.K) {
                        r1.i w22 = this.f6345p.w2();
                        if (w22 != null && f.z2(this.f6345p, w22, 0L, 1, null)) {
                            this.f6345p.K = false;
                        }
                    }
                    this.f6346q.j(this.f6345p.r2(this.f6347r));
                }
            }

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            a(e0 e0Var, f fVar, d dVar, u1 u1Var, vm.d dVar2) {
                super(2, dVar2);
                this.f6337r = e0Var;
                this.f6338s = fVar;
                this.f6339t = dVar;
                this.f6340u = u1Var;
            }

            @Override // dn.p
            /* renamed from: b, reason: merged with bridge method [inline-methods] */
            public final Object invoke(p pVar, vm.d dVar) {
                return ((a) create(pVar, dVar)).invokeSuspend(n0.f34904a);
            }

            @Override // kotlin.coroutines.jvm.internal.a
            public final vm.d create(Object obj, vm.d dVar) {
                a aVar = new a(this.f6337r, this.f6338s, this.f6339t, this.f6340u, dVar);
                aVar.f6336q = obj;
                return aVar;
            }

            @Override // kotlin.coroutines.jvm.internal.a
            public final Object invokeSuspend(Object obj) {
                Object f10;
                f10 = wm.d.f();
                int i10 = this.f6335p;
                if (i10 == 0) {
                    rm.y.b(obj);
                    p pVar = (p) this.f6336q;
                    this.f6337r.j(this.f6338s.r2(this.f6339t));
                    e0 e0Var = this.f6337r;
                    C0167a c0167a = new C0167a(this.f6338s, e0Var, this.f6340u, pVar);
                    b bVar = new b(this.f6338s, this.f6337r, this.f6339t);
                    this.f6335p = 1;
                    if (e0Var.h(c0167a, bVar, this) == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    rm.y.b(obj);
                }
                return n0.f34904a;
            }
        }

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        c(e0 e0Var, d dVar, vm.d dVar2) {
            super(2, dVar2);
            this.f6333s = e0Var;
            this.f6334t = dVar;
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final vm.d create(Object obj, vm.d dVar) {
            c cVar = new c(this.f6333s, this.f6334t, dVar);
            cVar.f6331q = obj;
            return cVar;
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f6330p;
            CancellationException cancellationException = null;
            try {
                try {
                    if (i10 == 0) {
                        rm.y.b(obj);
                        u1 k10 = y1.k(((m0) this.f6331q).getCoroutineContext());
                        f.this.M = true;
                        z zVar = f.this.D;
                        g0 g0Var = g0.Default;
                        a aVar = new a(this.f6333s, f.this, this.f6334t, k10, null);
                        this.f6330p = 1;
                        if (zVar.v(g0Var, aVar, this) == f10) {
                            return f10;
                        }
                    } else {
                        if (i10 != 1) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        rm.y.b(obj);
                    }
                    f.this.H.d();
                    f.this.M = false;
                    f.this.H.b(null);
                    f.this.K = false;
                    return n0.f34904a;
                } catch (CancellationException e10) {
                    cancellationException = e10;
                    throw cancellationException;
                }
            } catch (Throwable th2) {
                f.this.M = false;
                f.this.H.b(cancellationException);
                f.this.K = false;
                throw th2;
            }
        }

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

    public f(q qVar, z zVar, boolean z10, d dVar) {
        this.C = qVar;
        this.D = zVar;
        this.E = z10;
        this.F = dVar;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void A2() {
        d D2 = D2();
        if (!(!this.M)) {
            throw new IllegalStateException("launchAnimation called when previous animation was running".toString());
        }
        tp.k.d(H1(), null, o0.UNDISPATCHED, new c(new e0(D2.b()), D2, null), 1, null);
    }

    private final long C2(r1.i iVar, long j10) {
        long d10 = c3.s.d(j10);
        int i10 = b.f6329a[this.C.ordinal()];
        if (i10 == 1) {
            return r1.h.a(BitmapDescriptorFactory.HUE_RED, D2().a(iVar.l(), iVar.e() - iVar.l(), r1.m.g(d10)));
        }
        if (i10 == 2) {
            return r1.h.a(D2().a(iVar.i(), iVar.j() - iVar.i(), r1.m.i(d10)), BitmapDescriptorFactory.HUE_RED);
        }
        throw new rm.t();
    }

    private final d D2() {
        d dVar = this.F;
        return dVar == null ? (d) j2.i.a(this, e.a()) : dVar;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final float r2(d dVar) {
        if (c3.r.e(this.L, c3.r.f7432b.a())) {
            return BitmapDescriptorFactory.HUE_RED;
        }
        r1.i v22 = v2();
        if (v22 == null) {
            v22 = this.K ? w2() : null;
            if (v22 == null) {
                return BitmapDescriptorFactory.HUE_RED;
            }
        }
        long d10 = c3.s.d(this.L);
        int i10 = b.f6329a[this.C.ordinal()];
        if (i10 == 1) {
            return dVar.a(v22.l(), v22.e() - v22.l(), r1.m.g(d10));
        }
        if (i10 == 2) {
            return dVar.a(v22.i(), v22.j() - v22.i(), r1.m.i(d10));
        }
        throw new rm.t();
    }

    private final int s2(long j10, long j11) {
        int i10 = b.f6329a[this.C.ordinal()];
        if (i10 == 1) {
            return kotlin.jvm.internal.t.i(c3.r.f(j10), c3.r.f(j11));
        }
        if (i10 == 2) {
            return kotlin.jvm.internal.t.i(c3.r.g(j10), c3.r.g(j11));
        }
        throw new rm.t();
    }

    private final int t2(long j10, long j11) {
        int i10 = b.f6329a[this.C.ordinal()];
        if (i10 == 1) {
            return Float.compare(r1.m.g(j10), r1.m.g(j11));
        }
        if (i10 == 2) {
            return Float.compare(r1.m.i(j10), r1.m.i(j11));
        }
        throw new rm.t();
    }

    private final r1.i u2(r1.i iVar, long j10) {
        return iVar.t(r1.g.u(C2(iVar, j10)));
    }

    private final r1.i v2() {
        a1.b bVar = this.H.f6290a;
        int q10 = bVar.q();
        r1.i iVar = null;
        if (q10 > 0) {
            int i10 = q10 - 1;
            Object[] p10 = bVar.p();
            do {
                r1.i iVar2 = (r1.i) ((a) p10[i10]).b().invoke();
                if (iVar2 != null) {
                    if (t2(iVar2.k(), c3.s.d(this.L)) > 0) {
                        return iVar == null ? iVar2 : iVar;
                    }
                    iVar = iVar2;
                }
                i10--;
            } while (i10 >= 0);
        }
        return iVar;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final r1.i w2() {
        if (!O1()) {
            return null;
        }
        h2.s k10 = j2.k.k(this);
        h2.s sVar = this.I;
        if (sVar != null) {
            if (!sVar.N()) {
                sVar = null;
            }
            if (sVar != null) {
                return k10.f0(sVar, false);
            }
        }
        return null;
    }

    private final boolean y2(r1.i iVar, long j10) {
        long C2 = C2(iVar, j10);
        return Math.abs(r1.g.m(C2)) <= 0.5f && Math.abs(r1.g.n(C2)) <= 0.5f;
    }

    static /* synthetic */ boolean z2(f fVar, r1.i iVar, long j10, int i10, Object obj) {
        if ((i10 & 1) != 0) {
            j10 = fVar.L;
        }
        return fVar.y2(iVar, j10);
    }

    public final void B2(h2.s sVar) {
        this.I = sVar;
    }

    public final void E2(q qVar, boolean z10, d dVar) {
        this.C = qVar;
        this.E = z10;
        this.F = dVar;
    }

    @Override // i0.c
    public Object I0(dn.a aVar, vm.d dVar) {
        vm.d d10;
        Object f10;
        Object f11;
        r1.i iVar = (r1.i) aVar.invoke();
        boolean z10 = false;
        if (iVar != null && !z2(this, iVar, 0L, 1, null)) {
            z10 = true;
        }
        if (!z10) {
            return n0.f34904a;
        }
        d10 = wm.c.d(dVar);
        tp.p pVar = new tp.p(d10, 1);
        pVar.u();
        if (this.H.c(new a(aVar, pVar)) && !this.M) {
            A2();
        }
        Object r10 = pVar.r();
        f10 = wm.d.f();
        if (r10 == f10) {
            kotlin.coroutines.jvm.internal.h.c(dVar);
        }
        f11 = wm.d.f();
        return r10 == f11 ? r10 : n0.f34904a;
    }

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

    @Override // j2.a0
    public void R(long j10) {
        r1.i w22;
        long j11 = this.L;
        this.L = j10;
        if (s2(j10, j11) < 0 && (w22 = w2()) != null) {
            r1.i iVar = this.J;
            if (iVar == null) {
                iVar = w22;
            }
            if (!this.M && !this.K && y2(iVar, j11) && !y2(w22, j10)) {
                this.K = true;
                A2();
            }
            this.J = w22;
        }
    }

    @Override // i0.c
    public r1.i p1(r1.i iVar) {
        if (!c3.r.e(this.L, c3.r.f7432b.a())) {
            return u2(iVar, this.L);
        }
        throw new IllegalStateException("Expected BringIntoViewRequester to not be used before parents are placed.".toString());
    }

    public final long x2() {
        return this.L;
    }
}
