package y3;

import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.v1;
import androidx.viewpager2.widget.ViewPager2;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Locale;

/* JADX INFO: loaded from: classes.dex */
public final class d extends v1 {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ViewPager2 f36771b;

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

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

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

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

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

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

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

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

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

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

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

    public d(ViewPager2 viewPager2) {
        this.f36771b = viewPager2;
        RecyclerView recyclerView = viewPager2.f4400j;
        this.f36772c = recyclerView;
        this.f36773d = (LinearLayoutManager) recyclerView.getLayoutManager();
        this.f36776g = new c();
        b();
    }

    public final void a(int i10) {
        if ((this.f36774e == 3 && this.f36775f == 0) || this.f36775f == i10) {
            return;
        }
        this.f36775f = i10;
        k kVar = this.f36770a;
        if (kVar != null) {
            kVar.a(i10);
        }
    }

    public final void b() {
        this.f36774e = 0;
        this.f36775f = 0;
        c cVar = this.f36776g;
        cVar.f36768b = -1;
        cVar.f36767a = 0.0f;
        cVar.f36769c = 0;
        this.f36777h = -1;
        this.f36778i = -1;
        this.f36779j = false;
        this.f36780k = false;
        this.f36782m = false;
        this.f36781l = false;
    }

    /* JADX WARN: Removed duplicated region for block: B:65:0x012a  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void c() {
        int top;
        int childCount;
        int top2;
        int i10;
        int bottom;
        int i11;
        LinearLayoutManager linearLayoutManager = this.f36773d;
        int iFindFirstVisibleItemPosition = linearLayoutManager.findFirstVisibleItemPosition();
        c cVar = this.f36776g;
        cVar.f36768b = iFindFirstVisibleItemPosition;
        if (iFindFirstVisibleItemPosition == -1) {
            cVar.f36768b = -1;
            cVar.f36767a = 0.0f;
            cVar.f36769c = 0;
            return;
        }
        View viewFindViewByPosition = linearLayoutManager.findViewByPosition(iFindFirstVisibleItemPosition);
        if (viewFindViewByPosition == null) {
            cVar.f36768b = -1;
            cVar.f36767a = 0.0f;
            cVar.f36769c = 0;
            return;
        }
        int leftDecorationWidth = linearLayoutManager.getLeftDecorationWidth(viewFindViewByPosition);
        int rightDecorationWidth = linearLayoutManager.getRightDecorationWidth(viewFindViewByPosition);
        int topDecorationHeight = linearLayoutManager.getTopDecorationHeight(viewFindViewByPosition);
        int bottomDecorationHeight = linearLayoutManager.getBottomDecorationHeight(viewFindViewByPosition);
        ViewGroup.LayoutParams layoutParams = viewFindViewByPosition.getLayoutParams();
        if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
            leftDecorationWidth += marginLayoutParams.leftMargin;
            rightDecorationWidth += marginLayoutParams.rightMargin;
            topDecorationHeight += marginLayoutParams.topMargin;
            bottomDecorationHeight += marginLayoutParams.bottomMargin;
        }
        int height = viewFindViewByPosition.getHeight() + topDecorationHeight + bottomDecorationHeight;
        int width = viewFindViewByPosition.getWidth() + leftDecorationWidth + rightDecorationWidth;
        int orientation = linearLayoutManager.getOrientation();
        RecyclerView recyclerView = this.f36772c;
        if (orientation == 0) {
            top = (viewFindViewByPosition.getLeft() - leftDecorationWidth) - recyclerView.getPaddingLeft();
            if (this.f36771b.f4397g.getLayoutDirection() == 1) {
                top = -top;
            }
            height = width;
        } else {
            top = (viewFindViewByPosition.getTop() - topDecorationHeight) - recyclerView.getPaddingTop();
        }
        int i12 = -top;
        cVar.f36769c = i12;
        if (i12 >= 0) {
            cVar.f36767a = height != 0 ? i12 / height : 0.0f;
            return;
        }
        a aVar = new a();
        int childCount2 = linearLayoutManager.getChildCount();
        if (childCount2 != 0) {
            boolean z10 = linearLayoutManager.getOrientation() == 0;
            int[][] iArr = (int[][]) Array.newInstance((Class<?>) Integer.TYPE, childCount2, 2);
            for (int i13 = 0; i13 < childCount2; i13++) {
                View childAt = linearLayoutManager.getChildAt(i13);
                if (childAt == null) {
                    throw new IllegalStateException("null view contained in the view hierarchy");
                }
                ViewGroup.LayoutParams layoutParams2 = childAt.getLayoutParams();
                ViewGroup.MarginLayoutParams marginLayoutParams2 = layoutParams2 instanceof ViewGroup.MarginLayoutParams ? (ViewGroup.MarginLayoutParams) layoutParams2 : a.f36766a;
                int[] iArr2 = iArr[i13];
                if (z10) {
                    top2 = childAt.getLeft();
                    i10 = marginLayoutParams2.leftMargin;
                } else {
                    top2 = childAt.getTop();
                    i10 = marginLayoutParams2.topMargin;
                }
                iArr2[0] = top2 - i10;
                int[] iArr3 = iArr[i13];
                if (z10) {
                    bottom = childAt.getRight();
                    i11 = marginLayoutParams2.rightMargin;
                } else {
                    bottom = childAt.getBottom();
                    i11 = marginLayoutParams2.bottomMargin;
                }
                iArr3[1] = bottom + i11;
            }
            Arrays.sort(iArr, new u.i(aVar, 2));
            int i14 = 1;
            while (true) {
                if (i14 >= childCount2) {
                    int[] iArr4 = iArr[0];
                    int i15 = iArr4[1];
                    int i16 = iArr4[0];
                    int i17 = i15 - i16;
                    if (i16 > 0 || iArr[childCount2 - 1][1] < i17) {
                        break;
                    }
                } else if (iArr[i14 - 1][1] != iArr[i14][0]) {
                    break;
                } else {
                    i14++;
                }
            }
            childCount = linearLayoutManager.getChildCount();
            for (int i18 = 0; i18 < childCount; i18++) {
                if (a.a(linearLayoutManager.getChildAt(i18))) {
                    throw new IllegalStateException("Page(s) contain a ViewGroup with a LayoutTransition (or animateLayoutChanges=\"true\"), which interferes with the scrolling animation. Make sure to call getLayoutTransition().setAnimateParentHierarchy(false) on all ViewGroups with a LayoutTransition before an animation is started.");
                }
            }
        } else if (linearLayoutManager.getChildCount() <= 1) {
            childCount = linearLayoutManager.getChildCount();
            while (i18 < childCount) {
            }
        }
        throw new IllegalStateException(String.format(Locale.US, "Page can only be offset by a positive amount, not by %d", Integer.valueOf(cVar.f36769c)));
    }

    @Override // androidx.recyclerview.widget.v1
    public final void onScrollStateChanged(RecyclerView recyclerView, int i10) {
        k kVar;
        k kVar2;
        int i11 = this.f36774e;
        boolean z10 = true;
        if (!(i11 == 1 && this.f36775f == 1) && i10 == 1) {
            this.f36782m = false;
            this.f36774e = 1;
            int i12 = this.f36778i;
            if (i12 != -1) {
                this.f36777h = i12;
                this.f36778i = -1;
            } else if (this.f36777h == -1) {
                this.f36777h = this.f36773d.findFirstVisibleItemPosition();
            }
            a(1);
            return;
        }
        if ((i11 == 1 || i11 == 4) && i10 == 2) {
            if (this.f36780k) {
                a(2);
                this.f36779j = true;
                return;
            }
            return;
        }
        if (i11 != 1 && i11 != 4) {
            z10 = false;
        }
        c cVar = this.f36776g;
        if (z10 && i10 == 0) {
            c();
            if (!this.f36780k) {
                int i13 = cVar.f36768b;
                if (i13 != -1 && (kVar2 = this.f36770a) != null) {
                    kVar2.b(i13, 0.0f, 0);
                }
            } else if (cVar.f36769c == 0) {
                int i14 = this.f36777h;
                int i15 = cVar.f36768b;
                if (i14 != i15 && (kVar = this.f36770a) != null) {
                    kVar.c(i15);
                }
            }
            a(0);
            b();
        }
        if (this.f36774e == 2 && i10 == 0 && this.f36781l) {
            c();
            if (cVar.f36769c == 0) {
                int i16 = this.f36778i;
                int i17 = cVar.f36768b;
                if (i16 != i17) {
                    if (i17 == -1) {
                        i17 = 0;
                    }
                    k kVar3 = this.f36770a;
                    if (kVar3 != null) {
                        kVar3.c(i17);
                    }
                }
                a(0);
                b();
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x0028  */
    @Override // androidx.recyclerview.widget.v1
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void onScrolled(RecyclerView recyclerView, int i10, int i11) {
        int i12;
        k kVar;
        this.f36780k = true;
        c();
        boolean z10 = this.f36779j;
        c cVar = this.f36776g;
        if (z10) {
            this.f36779j = false;
            if (i11 > 0) {
                i12 = cVar.f36769c != 0 ? cVar.f36768b + 1 : cVar.f36768b;
                this.f36778i = i12;
                if (this.f36777h != i12 && (kVar = this.f36770a) != null) {
                    kVar.c(i12);
                }
            } else {
                if (i11 == 0) {
                    if ((i10 < 0) == (this.f36771b.f4397g.getLayoutDirection() == 1)) {
                    }
                }
                this.f36778i = i12;
                if (this.f36777h != i12) {
                    kVar.c(i12);
                }
            }
        } else if (this.f36774e == 0) {
            int i13 = cVar.f36768b;
            if (i13 == -1) {
                i13 = 0;
            }
            k kVar2 = this.f36770a;
            if (kVar2 != null) {
                kVar2.c(i13);
            }
        }
        int i14 = cVar.f36768b;
        if (i14 == -1) {
            i14 = 0;
        }
        float f10 = cVar.f36767a;
        int i15 = cVar.f36769c;
        k kVar3 = this.f36770a;
        if (kVar3 != null) {
            kVar3.b(i14, f10, i15);
        }
        int i16 = cVar.f36768b;
        int i17 = this.f36778i;
        if ((i16 == i17 || i17 == -1) && cVar.f36769c == 0 && this.f36775f != 1) {
            a(0);
            b();
        }
    }
}
