package u0;

import P.C0158b;
import android.util.SparseArray;
import android.view.View;
import androidx.datastore.preferences.protobuf.C0247k;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import p0.AbstractC0928a;

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

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

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

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f10087e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public int f10088f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public L f10089g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final /* synthetic */ RecyclerView f10090h;

    public M(RecyclerView recyclerView) {
        this.f10090h = recyclerView;
        ArrayList arrayList = new ArrayList();
        this.f10083a = arrayList;
        this.f10084b = null;
        this.f10085c = new ArrayList();
        this.f10086d = Collections.unmodifiableList(arrayList);
        this.f10087e = 2;
        this.f10088f = 2;
    }

    public final void a(V v5, boolean z5) {
        RecyclerView.i(v5);
        RecyclerView recyclerView = this.f10090h;
        X x5 = recyclerView.f4585t0;
        if (x5 != null) {
            W w5 = x5.f10136e;
            View view = v5.f10118a;
            P.Q.k(view, w5 != null ? (C0158b) w5.f10134e.remove(view) : null);
        }
        if (z5 && recyclerView.f4573m0 != null) {
            recyclerView.p.G(v5);
        }
        v5.f10132r = null;
        L lC = c();
        lC.getClass();
        int i = v5.f10123f;
        ArrayList arrayList = lC.a(i).f10077a;
        if (((K) lC.f10081a.get(i)).f10078b <= arrayList.size()) {
            return;
        }
        v5.m();
        arrayList.add(v5);
    }

    public final int b(int i) {
        RecyclerView recyclerView = this.f10090h;
        if (i >= 0 && i < recyclerView.f4573m0.b()) {
            return !recyclerView.f4573m0.f10105g ? i : recyclerView.f4574n.h(i, 0);
        }
        StringBuilder sbM = AbstractC0928a.m(i, "invalid position ", ". State item count is ");
        sbM.append(recyclerView.f4573m0.b());
        sbM.append(recyclerView.x());
        throw new IndexOutOfBoundsException(sbM.toString());
    }

    public final L c() {
        if (this.f10089g == null) {
            L l5 = new L();
            l5.f10081a = new SparseArray();
            l5.f10082b = 0;
            this.f10089g = l5;
        }
        return this.f10089g;
    }

    public final void d() {
        ArrayList arrayList = this.f10085c;
        for (int size = arrayList.size() - 1; size >= 0; size--) {
            e(size);
        }
        arrayList.clear();
        int[] iArr = RecyclerView.f4534C0;
        C0247k c0247k = this.f10090h.l0;
        int[] iArr2 = (int[]) c0247k.f4084e;
        if (iArr2 != null) {
            Arrays.fill(iArr2, -1);
        }
        c0247k.f4083d = 0;
    }

    public final void e(int i) {
        ArrayList arrayList = this.f10085c;
        a((V) arrayList.get(i), true);
        arrayList.remove(i);
    }

    public final void f(View view) {
        V vH = RecyclerView.H(view);
        boolean zJ = vH.j();
        RecyclerView recyclerView = this.f10090h;
        if (zJ) {
            recyclerView.removeDetachedView(view, false);
        }
        if (vH.i()) {
            vH.f10130n.j(vH);
        } else if (vH.p()) {
            vH.f10126j &= -33;
        }
        g(vH);
        if (recyclerView.f4553R == null || vH.g()) {
            return;
        }
        recyclerView.f4553R.d(vH);
    }

    /* JADX WARN: Code restructure failed: missing block: B:46:0x0098, code lost:
    
        r5 = r5 - 1;
     */
    /* JADX WARN: Removed duplicated region for block: B:16:0x0030  */
    /* JADX WARN: Removed duplicated region for block: B:40:0x0079  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final void g(u0.V r12) {
        /*
            Method dump skipped, instruction units count: 287
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: u0.M.g(u0.V):void");
    }

    public final void h(View view) {
        AbstractC1031C abstractC1031C;
        V vH = RecyclerView.H(view);
        boolean z5 = (vH.f10126j & 12) != 0;
        RecyclerView recyclerView = this.f10090h;
        if (!z5 && vH.k() && (abstractC1031C = recyclerView.f4553R) != null) {
            C1047i c1047i = (C1047i) abstractC1031C;
            if (vH.c().isEmpty() && c1047i.f10206g && !vH.f()) {
                if (this.f10084b == null) {
                    this.f10084b = new ArrayList();
                }
                vH.f10130n = this;
                vH.f10131o = true;
                this.f10084b.add(vH);
                return;
            }
        }
        if (vH.f() && !vH.h() && !recyclerView.f4586u.f10310b) {
            throw new IllegalArgumentException("Called scrap view with an invalid view. Invalid views cannot be reused from scrap, they should rebound from recycler pool." + recyclerView.x());
        }
        vH.f10130n = this;
        vH.f10131o = false;
        this.f10083a.add(vH);
    }

    /* JADX WARN: Removed duplicated region for block: B:110:0x01d7  */
    /* JADX WARN: Removed duplicated region for block: B:111:0x01d9  */
    /* JADX WARN: Removed duplicated region for block: B:176:0x031f  */
    /* JADX WARN: Removed duplicated region for block: B:178:0x0322  */
    /* JADX WARN: Removed duplicated region for block: B:217:0x03de  */
    /* JADX WARN: Removed duplicated region for block: B:221:0x03e8  */
    /* JADX WARN: Removed duplicated region for block: B:222:0x03eb  */
    /* JADX WARN: Removed duplicated region for block: B:224:0x03ee  */
    /* JADX WARN: Removed duplicated region for block: B:229:0x0412  */
    /* JADX WARN: Removed duplicated region for block: B:232:0x041b  */
    /* JADX WARN: Removed duplicated region for block: B:234:0x0421  */
    /* JADX WARN: Removed duplicated region for block: B:245:0x044d  */
    /* JADX WARN: Removed duplicated region for block: B:251:0x0464  */
    /* JADX WARN: Removed duplicated region for block: B:297:0x051a  */
    /* JADX WARN: Removed duplicated region for block: B:298:0x0524  */
    /* JADX WARN: Removed duplicated region for block: B:304:0x053a A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:306:0x053e  */
    /* JADX WARN: Removed duplicated region for block: B:37:0x0080  */
    /* JADX WARN: Removed duplicated region for block: B:38:0x0082  */
    /* JADX WARN: Removed duplicated region for block: B:74:0x0125  */
    /* JADX WARN: Removed duplicated region for block: B:80:0x0139  */
    /* JADX WARN: Removed duplicated region for block: B:81:0x0148  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final u0.V i(long r27, int r29) {
        /*
            Method dump skipped, instruction units count: 1395
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: u0.M.i(long, int):u0.V");
    }

    public final void j(V v5) {
        if (v5.f10131o) {
            this.f10084b.remove(v5);
        } else {
            this.f10083a.remove(v5);
        }
        v5.f10130n = null;
        v5.f10131o = false;
        v5.f10126j &= -33;
    }

    public final void k() {
        AbstractC1035G abstractC1035G = this.f10090h.f4588v;
        this.f10088f = this.f10087e + (abstractC1035G != null ? abstractC1035G.f10067j : 0);
        ArrayList arrayList = this.f10085c;
        for (int size = arrayList.size() - 1; size >= 0 && arrayList.size() > this.f10088f; size--) {
            e(size);
        }
    }
}
