package k2;

import java.util.ArrayList;
import java.util.List;
import kotlin.jvm.internal.v;
import o2.b;
import o2.i;
import o2.j;
import o2.m;
import o2.p;
import r1.g;
import r1.h;
import sm.c0;
import sm.u;
import t3.h;

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

    /* renamed from: k2.a$a, reason: collision with other inner class name */
    /* loaded from: classes.dex */
    static final class C0528a extends v implements dn.a {

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

        C0528a() {
            super(0);
        }

        @Override // dn.a
        public final Boolean invoke() {
            return Boolean.FALSE;
        }
    }

    private static final boolean a(List list) {
        List k10;
        Object c02;
        int m10;
        long v10;
        Object c03;
        int m11;
        if (list.size() < 2) {
            return true;
        }
        if (list.size() == 0 || list.size() == 1) {
            k10 = u.k();
        } else {
            k10 = new ArrayList();
            Object obj = list.get(0);
            m11 = u.m(list);
            int i10 = 0;
            while (i10 < m11) {
                i10++;
                Object obj2 = list.get(i10);
                m mVar = (m) obj2;
                m mVar2 = (m) obj;
                k10.add(g.d(h.a(Math.abs(g.m(mVar2.i().g()) - g.m(mVar.i().g())), Math.abs(g.n(mVar2.i().g()) - g.n(mVar.i().g())))));
                obj = obj2;
            }
        }
        if (k10.size() == 1) {
            c03 = c0.c0(k10);
            v10 = ((g) c03).v();
        } else {
            if (k10.isEmpty()) {
                throw new UnsupportedOperationException("Empty collection can't be reduced.");
            }
            c02 = c0.c0(k10);
            m10 = u.m(k10);
            if (1 <= m10) {
                int i11 = 1;
                while (true) {
                    c02 = g.d(g.r(((g) c02).v(), ((g) k10.get(i11)).v()));
                    if (i11 == m10) {
                        break;
                    }
                    i11++;
                }
            }
            v10 = ((g) c02).v();
        }
        return g.n(v10) < g.m(v10);
    }

    public static final boolean b(m mVar) {
        i n10 = mVar.n();
        p pVar = p.f30605a;
        return (j.a(n10, pVar.a()) == null && j.a(mVar.n(), pVar.z()) == null) ? false : true;
    }

    private static final boolean c(b bVar) {
        return bVar.b() < 0 || bVar.a() < 0;
    }

    public static final void d(m mVar, t3.h hVar) {
        i n10 = mVar.n();
        p pVar = p.f30605a;
        b bVar = (b) j.a(n10, pVar.a());
        if (bVar != null) {
            hVar.i0(f(bVar));
            return;
        }
        ArrayList arrayList = new ArrayList();
        if (j.a(mVar.n(), pVar.z()) != null) {
            List t10 = mVar.t();
            int size = t10.size();
            for (int i10 = 0; i10 < size; i10++) {
                m mVar2 = (m) t10.get(i10);
                if (mVar2.n().i(p.f30605a.A())) {
                    arrayList.add(mVar2);
                }
            }
        }
        if (!arrayList.isEmpty()) {
            boolean a10 = a(arrayList);
            hVar.i0(h.e.a(a10 ? 1 : arrayList.size(), a10 ? arrayList.size() : 1, false, 0));
        }
    }

    public static final void e(m mVar, t3.h hVar) {
        i n10 = mVar.n();
        p pVar = p.f30605a;
        android.support.v4.media.session.b.a(j.a(n10, pVar.b()));
        m r10 = mVar.r();
        if (r10 == null || j.a(r10.n(), pVar.z()) == null) {
            return;
        }
        b bVar = (b) j.a(r10.n(), pVar.a());
        if ((bVar == null || !c(bVar)) && mVar.n().i(pVar.A())) {
            ArrayList arrayList = new ArrayList();
            List t10 = r10.t();
            int size = t10.size();
            int i10 = 0;
            for (int i11 = 0; i11 < size; i11++) {
                m mVar2 = (m) t10.get(i11);
                if (mVar2.n().i(p.f30605a.A())) {
                    arrayList.add(mVar2);
                    if (mVar2.q().p0() < mVar.q().p0()) {
                        i10++;
                    }
                }
            }
            if (!arrayList.isEmpty()) {
                boolean a10 = a(arrayList);
                h.f a11 = h.f.a(a10 ? 0 : i10, 1, a10 ? i10 : 0, 1, false, ((Boolean) mVar.n().z(p.f30605a.A(), C0528a.f25354p)).booleanValue());
                if (a11 != null) {
                    hVar.j0(a11);
                }
            }
        }
    }

    private static final h.e f(b bVar) {
        return h.e.a(bVar.b(), bVar.a(), false, 0);
    }
}
