package com.google.android.material.bottomnavigation;

import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import com.google.android.material.navigation.NavigationBarItemView;
import com.google.android.material.navigation.NavigationBarMenuView;
import java.util.ArrayList;
import x8.e;

/* JADX INFO: loaded from: classes2.dex */
@RestrictTo({RestrictTo.Scope.f556b})
public class BottomNavigationMenuView extends NavigationBarMenuView {
    public final int A0;
    public final int B0;
    public boolean C0;
    public final ArrayList D0;

    /* JADX INFO: renamed from: y0, reason: collision with root package name */
    public final int f22258y0;
    public final int z0;

    public BottomNavigationMenuView(@NonNull Context context) {
        super(context);
        this.D0 = new ArrayList();
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-2, -2);
        layoutParams.gravity = 17;
        setLayoutParams(layoutParams);
        Resources resources = getResources();
        this.f22258y0 = resources.getDimensionPixelSize(e.design_bottom_navigation_item_max_width);
        this.z0 = resources.getDimensionPixelSize(e.design_bottom_navigation_item_min_width);
        this.A0 = resources.getDimensionPixelSize(e.design_bottom_navigation_active_item_max_width);
        this.B0 = resources.getDimensionPixelSize(e.design_bottom_navigation_active_item_min_width);
    }

    @Override // com.google.android.material.navigation.NavigationBarMenuView
    public final NavigationBarItemView c(Context context) {
        return new BottomNavigationItemView(context);
    }

    @Override // android.view.ViewGroup, android.view.View
    public final void onLayout(boolean z10, int i10, int i11, int i12, int i13) {
        int childCount = getChildCount();
        int i14 = i12 - i10;
        int i15 = i13 - i11;
        int measuredWidth = 0;
        for (int i16 = 0; i16 < childCount; i16++) {
            View childAt = getChildAt(i16);
            if (childAt.getVisibility() != 8) {
                if (getLayoutDirection() == 1) {
                    int i17 = i14 - measuredWidth;
                    childAt.layout(i17 - childAt.getMeasuredWidth(), 0, i17, i15);
                } else {
                    childAt.layout(measuredWidth, 0, childAt.getMeasuredWidth() + measuredWidth, i15);
                }
                measuredWidth += childAt.getMeasuredWidth();
            }
        }
    }

    @Override // android.view.View
    public final void onMeasure(int i10, int i11) {
        int i12;
        int iMax;
        int i13;
        int i14;
        int size = View.MeasureSpec.getSize(i10);
        int currentVisibleContentItemCount = getCurrentVisibleContentItemCount();
        int childCount = getChildCount();
        ArrayList arrayList = this.D0;
        arrayList.clear();
        int iMakeMeasureSpec = View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(i11), Integer.MIN_VALUE);
        int i15 = 0;
        if (getItemIconGravity() == 0) {
            boolean zE = NavigationBarMenuView.e(getLabelVisibilityMode(), currentVisibleContentItemCount);
            int i16 = this.A0;
            if (zE && this.C0) {
                View childAt = getChildAt(getSelectedItemPosition());
                int visibility = childAt.getVisibility();
                int iMax2 = this.B0;
                if (visibility != 8) {
                    childAt.measure(View.MeasureSpec.makeMeasureSpec(i16, Integer.MIN_VALUE), iMakeMeasureSpec);
                    iMax2 = Math.max(iMax2, childAt.getMeasuredWidth());
                }
                int i17 = currentVisibleContentItemCount - (childAt.getVisibility() != 8 ? 1 : 0);
                int iMin = Math.min(size - (this.z0 * i17), Math.min(iMax2, i16));
                int i18 = size - iMin;
                int iMin2 = Math.min(i18 / (i17 != 0 ? i17 : 1), this.f22258y0);
                int i19 = i18 - (i17 * iMin2);
                int i20 = 0;
                while (i20 < childCount) {
                    if (getChildAt(i20).getVisibility() != 8) {
                        i14 = i20 == getSelectedItemPosition() ? iMin : iMin2;
                        if (i19 > 0) {
                            i14++;
                            i19--;
                        }
                    } else {
                        i14 = 0;
                    }
                    arrayList.add(Integer.valueOf(i14));
                    i20++;
                }
            } else {
                int iMin3 = Math.min(size / (currentVisibleContentItemCount != 0 ? currentVisibleContentItemCount : 1), i16);
                int i21 = size - (currentVisibleContentItemCount * iMin3);
                for (int i22 = 0; i22 < childCount; i22++) {
                    if (getChildAt(i22).getVisibility() == 8) {
                        i13 = 0;
                    } else if (i21 > 0) {
                        i13 = iMin3 + 1;
                        i21--;
                    } else {
                        i13 = iMin3;
                    }
                    arrayList.add(Integer.valueOf(i13));
                }
            }
            i12 = 0;
            iMax = 0;
            while (i15 < childCount) {
                View childAt2 = getChildAt(i15);
                if (childAt2.getVisibility() != 8) {
                    childAt2.measure(View.MeasureSpec.makeMeasureSpec(((Integer) arrayList.get(i15)).intValue(), 1073741824), iMakeMeasureSpec);
                    childAt2.getLayoutParams().width = childAt2.getMeasuredWidth();
                    int measuredWidth = childAt2.getMeasuredWidth() + i12;
                    iMax = Math.max(iMax, childAt2.getMeasuredHeight());
                    i12 = measuredWidth;
                }
                i15++;
            }
        } else {
            if (currentVisibleContentItemCount == 0) {
                currentVisibleContentItemCount = 1;
            }
            float f10 = size;
            float fMin = Math.min((currentVisibleContentItemCount + 3) / 10.0f, 0.9f) * f10;
            float f11 = currentVisibleContentItemCount;
            int iRound = Math.round(fMin / f11);
            int iRound2 = Math.round(f10 / f11);
            int i23 = 0;
            int iMax3 = 0;
            while (i15 < childCount) {
                View childAt3 = getChildAt(i15);
                if (childAt3.getVisibility() != 8) {
                    childAt3.measure(View.MeasureSpec.makeMeasureSpec(iRound2, Integer.MIN_VALUE), iMakeMeasureSpec);
                    if (childAt3.getMeasuredWidth() < iRound) {
                        childAt3.measure(View.MeasureSpec.makeMeasureSpec(iRound, 1073741824), iMakeMeasureSpec);
                    }
                    int measuredWidth2 = childAt3.getMeasuredWidth() + i23;
                    iMax3 = Math.max(iMax3, childAt3.getMeasuredHeight());
                    i23 = measuredWidth2;
                }
                i15++;
            }
            i12 = i23;
            iMax = iMax3;
        }
        setMeasuredDimension(i12, Math.max(iMax, getSuggestedMinimumHeight()));
    }

    public void setItemHorizontalTranslationEnabled(boolean z10) {
        this.C0 = z10;
    }
}
