package B0;

import L0.AbstractC0146a;
import L0.C0165u;
import L0.C0168x;
import android.graphics.Matrix;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.RectF;
import android.os.Handler;
import android.os.Looper;
import com.rubensousa.dpadrecyclerview.layoutmanager.PivotLayoutManager;
import d3.V0;
import e6.C0890b;
import e6.C0891c;
import f6.C0966a;
import f6.C0967b;
import j6.C1081a;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import k6.C1108a;
import l6.C1139a;
import x3.InterfaceC1715c;

/* JADX INFO: loaded from: classes.dex */
public final class i0 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Object f790a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public boolean f791b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Object f792c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Object f793d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final Object f794e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final Object f795f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final Object f796g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final Object f797h;
    public final Object i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public Object f798j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public Object f799k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public Object f800l;

    public i0(PivotLayoutManager pivotLayoutManager, C0966a c0966a, C0890b c0890b, C0891c c0891c, m6.d dVar, i6.c cVar) {
        this.f792c = pivotLayoutManager;
        this.f793d = c0966a;
        this.f794e = c0890b;
        this.f795f = c0891c;
        this.f796g = dVar;
        this.f797h = cVar;
        V0 v02 = new V0(22, this);
        this.i = v02;
        this.f790a = new ArrayList();
        this.f798j = c0890b.f12500b > 1 ? new C1081a(pivotLayoutManager, cVar, c0966a, v02) : new C1108a(pivotLayoutManager, cVar, c0966a, v02);
        this.f799k = new ArrayList();
    }

    public u0.S a(int i, ArrayList arrayList, L0.f0 f0Var) {
        if (!arrayList.isEmpty()) {
            this.f799k = f0Var;
            for (int i5 = i; i5 < arrayList.size() + i; i5++) {
                h0 h0Var = (h0) arrayList.get(i5 - i);
                ArrayList arrayList2 = (ArrayList) this.f790a;
                if (i5 > 0) {
                    h0 h0Var2 = (h0) arrayList2.get(i5 - 1);
                    h0Var.f783d = h0Var2.f780a.f3922o.f3900b.o() + h0Var2.f783d;
                    h0Var.f784e = false;
                    h0Var.f782c.clear();
                } else {
                    h0Var.f783d = 0;
                    h0Var.f784e = false;
                    h0Var.f782c.clear();
                }
                int iO = h0Var.f780a.f3922o.f3900b.o();
                for (int i8 = i5; i8 < arrayList2.size(); i8++) {
                    ((h0) arrayList2.get(i8)).f783d += iO;
                }
                arrayList2.add(i5, h0Var);
                ((HashMap) this.f794e).put(h0Var.f781b, h0Var);
                if (this.f791b) {
                    g(h0Var);
                    if (((IdentityHashMap) this.f793d).isEmpty()) {
                        ((HashSet) this.f797h).add(h0Var);
                    } else {
                        g0 g0Var = (g0) ((HashMap) this.f795f).get(h0Var);
                        if (g0Var != null) {
                            g0Var.f766a.b(g0Var.f767b);
                        }
                    }
                }
            }
        }
        return c();
    }

    /* JADX WARN: Multi-variable type inference failed */
    public void b(x3.k kVar, float f3, RectF rectF, C1139a c1139a, Path path) {
        Matrix[] matrixArr;
        Matrix[] matrixArr2;
        x3.t[] tVarArr;
        int i;
        char c3;
        float[] fArr;
        float f7;
        char c8;
        int i5;
        i0 i0Var = this;
        path.rewind();
        Path path2 = (Path) i0Var.f795f;
        path2.rewind();
        Path path3 = (Path) i0Var.f796g;
        path3.rewind();
        path3.addRect(rectF, Path.Direction.CW);
        int i8 = 0;
        while (true) {
            matrixArr = (Matrix[]) i0Var.f793d;
            matrixArr2 = (Matrix[]) i0Var.f790a;
            tVarArr = (x3.t[]) i0Var.f792c;
            i = 4;
            c3 = 0;
            fArr = (float[]) i0Var.i;
            if (i8 >= 4) {
                break;
            }
            InterfaceC1715c interfaceC1715c = i8 != 1 ? i8 != 2 ? i8 != 3 ? kVar.f18641f : kVar.f18640e : kVar.f18643h : kVar.f18642g;
            android.support.v4.media.session.a aVar = i8 != 1 ? i8 != 2 ? i8 != 3 ? kVar.f18637b : kVar.f18636a : kVar.f18639d : kVar.f18638c;
            x3.t tVar = tVarArr[i8];
            aVar.getClass();
            aVar.k(tVar, f3, interfaceC1715c.a(rectF));
            int i9 = i8 + 1;
            float f8 = i9 * 90;
            matrixArr2[i8].reset();
            PointF pointF = (PointF) i0Var.f794e;
            if (i8 == 1) {
                i5 = i8;
                pointF.set(rectF.right, rectF.bottom);
            } else if (i8 == 2) {
                i5 = i8;
                pointF.set(rectF.left, rectF.bottom);
            } else if (i8 != 3) {
                i5 = i8;
                pointF.set(rectF.right, rectF.top);
            } else {
                i5 = i8;
                pointF.set(rectF.left, rectF.top);
            }
            matrixArr2[i5].setTranslate(pointF.x, pointF.y);
            matrixArr2[i5].preRotate(f8);
            x3.t tVar2 = tVarArr[i5];
            fArr[0] = tVar2.f18666b;
            fArr[1] = tVar2.f18667c;
            matrixArr2[i5].mapPoints(fArr);
            matrixArr[i5].reset();
            matrixArr[i5].setTranslate(fArr[0], fArr[1]);
            matrixArr[i5].preRotate(f8);
            i8 = i9;
        }
        int i10 = 0;
        while (i10 < i) {
            x3.t tVar3 = tVarArr[i10];
            tVar3.getClass();
            fArr[c3] = 0.0f;
            fArr[1] = tVar3.f18665a;
            matrixArr2[i10].mapPoints(fArr);
            if (i10 == 0) {
                path.moveTo(fArr[c3], fArr[1]);
            } else {
                path.lineTo(fArr[c3], fArr[1]);
            }
            tVarArr[i10].b(matrixArr2[i10], path);
            if (c1139a != null) {
                x3.t tVar4 = tVarArr[i10];
                Matrix matrix = matrixArr2[i10];
                x3.g gVar = (x3.g) c1139a.f14409q;
                BitSet bitSet = gVar.f18617t;
                tVar4.getClass();
                f7 = 0.0f;
                bitSet.set(i10, (boolean) c3);
                tVar4.a(tVar4.f18669e);
                gVar.f18615r[i10] = new x3.m(new ArrayList(tVar4.f18671g), new Matrix(matrix));
            } else {
                f7 = 0.0f;
            }
            int i11 = i10 + 1;
            int i12 = i11 % 4;
            x3.t tVar5 = tVarArr[i10];
            fArr[0] = tVar5.f18666b;
            fArr[1] = tVar5.f18667c;
            matrixArr2[i10].mapPoints(fArr);
            x3.t tVar6 = tVarArr[i12];
            tVar6.getClass();
            float[] fArr2 = (float[]) i0Var.f798j;
            fArr2[0] = f7;
            fArr2[1] = tVar6.f18665a;
            matrixArr2[i12].mapPoints(fArr2);
            Matrix[] matrixArr3 = matrixArr2;
            x3.t[] tVarArr2 = tVarArr;
            float fMax = Math.max(((float) Math.hypot(fArr[0] - fArr2[0], fArr[1] - fArr2[1])) - 0.001f, f7);
            x3.t tVar7 = tVarArr2[i10];
            fArr[0] = tVar7.f18666b;
            fArr[1] = tVar7.f18667c;
            matrixArr3[i10].mapPoints(fArr);
            if (i10 == 1 || i10 == 3) {
                Math.abs(rectF.centerX() - fArr[0]);
            } else {
                Math.abs(rectF.centerY() - fArr[1]);
            }
            x3.t tVar8 = (x3.t) i0Var.f797h;
            tVar8.d(0.0f, 270.0f, 0.0f);
            (i10 != 1 ? i10 != 2 ? i10 != 3 ? kVar.f18644j : kVar.i : kVar.f18646l : kVar.f18645k).getClass();
            tVar8.c(fMax, 0.0f);
            Path path4 = (Path) i0Var.f799k;
            path4.reset();
            tVar8.b(matrixArr[i10], path4);
            if (i0Var.f791b && (i0Var.f(path4, i10) || i0Var.f(path4, i12))) {
                path4.op(path4, path3, Path.Op.DIFFERENCE);
                fArr[0] = 0.0f;
                fArr[1] = tVar8.f18665a;
                matrixArr[i10].mapPoints(fArr);
                path2.moveTo(fArr[0], fArr[1]);
                tVar8.b(matrixArr[i10], path2);
            } else {
                tVar8.b(matrixArr[i10], path);
            }
            if (c1139a != null) {
                Matrix matrix2 = matrixArr[i10];
                x3.g gVar2 = (x3.g) c1139a.f14409q;
                c8 = 0;
                gVar2.f18617t.set(i10 + 4, false);
                tVar8.a(tVar8.f18669e);
                gVar2.f18616s[i10] = new x3.m(new ArrayList(tVar8.f18671g), new Matrix(matrix2));
            } else {
                c8 = 0;
            }
            c3 = c8;
            i10 = i11;
            tVarArr = tVarArr2;
            matrixArr2 = matrixArr3;
            i = 4;
            i0Var = this;
        }
        path.close();
        path2.close();
        if (path2.isEmpty()) {
            return;
        }
        path.op(path2, Path.Op.UNION);
    }

    public u0.S c() {
        ArrayList arrayList = (ArrayList) this.f790a;
        if (arrayList.isEmpty()) {
            return u0.S.f17199a;
        }
        int iO = 0;
        for (int i = 0; i < arrayList.size(); i++) {
            h0 h0Var = (h0) arrayList.get(i);
            h0Var.f783d = iO;
            iO += h0Var.f780a.f3922o.f3900b.o();
        }
        return new o0(arrayList, (L0.f0) this.f799k);
    }

    public void d() {
        Iterator it = ((HashSet) this.f797h).iterator();
        while (it.hasNext()) {
            h0 h0Var = (h0) it.next();
            if (h0Var.f782c.isEmpty()) {
                g0 g0Var = (g0) ((HashMap) this.f795f).get(h0Var);
                if (g0Var != null) {
                    g0Var.f766a.b(g0Var.f767b);
                }
                it.remove();
            }
        }
    }

    public void e(h0 h0Var) {
        if (h0Var.f784e && h0Var.f782c.isEmpty()) {
            g0 g0Var = (g0) ((HashMap) this.f795f).remove(h0Var);
            g0Var.getClass();
            a0 a0Var = g0Var.f767b;
            AbstractC0146a abstractC0146a = g0Var.f766a;
            abstractC0146a.n(a0Var);
            f0 f0Var = g0Var.f768c;
            abstractC0146a.q(f0Var);
            abstractC0146a.p(f0Var);
            ((HashSet) this.f797h).remove(h0Var);
        }
    }

    public boolean f(Path path, int i) {
        Path path2 = (Path) this.f800l;
        path2.reset();
        ((x3.t[]) this.f792c)[i].b(((Matrix[]) this.f790a)[i], path2);
        RectF rectF = new RectF();
        path.computeBounds(rectF, true);
        path2.computeBounds(rectF, true);
        path.op(path2, Path.Op.INTERSECT);
        path.computeBounds(rectF, true);
        return !rectF.isEmpty() || (rectF.width() > 1.0f && rectF.height() > 1.0f);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r1v0, types: [B0.a0, L0.D] */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    public void g(h0 h0Var) {
        C0168x c0168x = h0Var.f780a;
        ?? r12 = new L0.D() { // from class: B0.a0
            @Override // L0.D
            public final void a(AbstractC0146a abstractC0146a, u0.S s8) {
                x0.s sVar = ((P) this.f709a.f796g).f651x;
                sVar.d(2);
                sVar.e(22);
            }
        };
        f0 f0Var = new f0(this, h0Var);
        ((HashMap) this.f795f).put(h0Var, new g0(c0168x, r12, f0Var));
        int i = x0.v.f18553a;
        Looper looperMyLooper = Looper.myLooper();
        if (looperMyLooper == null) {
            looperMyLooper = Looper.getMainLooper();
        }
        Handler handler = new Handler(looperMyLooper, null);
        c0168x.getClass();
        E0.e eVar = c0168x.f3758c;
        eVar.getClass();
        L0.H h8 = new L0.H();
        h8.f3643a = handler;
        h8.f3644b = f0Var;
        eVar.f1973c.add(h8);
        Looper looperMyLooper2 = Looper.myLooper();
        if (looperMyLooper2 == null) {
            looperMyLooper2 = Looper.getMainLooper();
        }
        new Handler(looperMyLooper2, null);
        E0.e eVar2 = c0168x.f3759d;
        eVar2.getClass();
        E0.d dVar = new E0.d();
        dVar.f1970a = f0Var;
        eVar2.f1973c.add(dVar);
        c0168x.j(r12, (z0.y) this.f800l, (C0.l) this.f792c);
    }

    public void h(L0.A a3) {
        IdentityHashMap identityHashMap = (IdentityHashMap) this.f793d;
        h0 h0Var = (h0) identityHashMap.remove(a3);
        h0Var.getClass();
        h0Var.f780a.m(a3);
        h0Var.f782c.remove(((C0165u) a3).f3908q);
        if (!identityHashMap.isEmpty()) {
            d();
        }
        e(h0Var);
    }

    public void i(int i, int i5) {
        for (int i8 = i5 - 1; i8 >= i; i8--) {
            ArrayList arrayList = (ArrayList) this.f790a;
            h0 h0Var = (h0) arrayList.remove(i8);
            ((HashMap) this.f794e).remove(h0Var.f781b);
            int i9 = -h0Var.f780a.f3922o.f3900b.o();
            for (int i10 = i8; i10 < arrayList.size(); i10++) {
                ((h0) arrayList.get(i10)).f783d += i9;
            }
            h0Var.f784e = true;
            if (this.f791b) {
                e(h0Var);
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x0031  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public int j(int i, N1.i0 i0Var, N1.p0 p0Var) {
        if (p0Var.b() == 0 || i == 0 || !((C0890b) this.f794e).f12516s) {
            return 0;
        }
        C0967b c0967b = (C0967b) ((C0966a) this.f793d).f12862h;
        int i5 = c0967b.f12864b;
        int i8 = c0967b.f12863a;
        if (i > 0) {
            if (!C0967b.d(i5)) {
                if (Integer.signum(i) != Integer.signum(i5)) {
                    i = 0;
                } else if (i > i5) {
                    i = i5;
                }
            }
        } else if (Integer.signum(i) == Integer.signum(i8)) {
            if (!C0967b.d(i8) && i < i8) {
                i = i8;
            }
        }
        ((i6.i) this.f798j).k(i, i0Var, p0Var, true);
        return i;
    }

    public i0() {
        this.f792c = new x3.t[4];
        this.f790a = new Matrix[4];
        this.f793d = new Matrix[4];
        this.f794e = new PointF();
        this.f795f = new Path();
        this.f796g = new Path();
        this.f797h = new x3.t();
        this.i = new float[2];
        this.f798j = new float[2];
        this.f799k = new Path();
        this.f800l = new Path();
        this.f791b = true;
        for (int i = 0; i < 4; i++) {
            ((x3.t[]) this.f792c)[i] = new x3.t();
            ((Matrix[]) this.f790a)[i] = new Matrix();
            ((Matrix[]) this.f793d)[i] = new Matrix();
        }
    }

    public i0(P p3, C0.f fVar, x0.s sVar, C0.l lVar) {
        this.f792c = lVar;
        this.f796g = p3;
        this.f799k = new L0.f0();
        this.f793d = new IdentityHashMap();
        this.f794e = new HashMap();
        this.f790a = new ArrayList();
        this.i = fVar;
        this.f798j = sVar;
        this.f795f = new HashMap();
        this.f797h = new HashSet();
    }
}
