package com.google.android.material.internal;

import android.R;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.CheckedTextView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import androidx.appcompat.view.menu.n;
import androidx.appcompat.widget.d1;
import androidx.appcompat.widget.m0;
import androidx.core.view.y;

/* JADX INFO: loaded from: classes.dex */
public class NavigationMenuItemView extends f implements n.a {
    private static final int[] J = {R.attr.state_checked};
    private boolean A;
    boolean B;
    private final CheckedTextView C;
    private FrameLayout D;
    private androidx.appcompat.view.menu.i E;
    private ColorStateList F;
    private boolean G;
    private Drawable H;
    private final androidx.core.view.a I;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    private int f4019z;

    class a extends androidx.core.view.a {
        a() {
        }

        @Override // androidx.core.view.a
        public void g(View view, androidx.core.view.accessibility.d dVar) {
            super.g(view, dVar);
            dVar.U(NavigationMenuItemView.this.B);
        }
    }

    public NavigationMenuItemView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    private void B() {
        if (D()) {
            this.C.setVisibility(8);
            FrameLayout frameLayout = this.D;
            if (frameLayout != null) {
                m0.a aVar = (m0.a) frameLayout.getLayoutParams();
                ((LinearLayout.LayoutParams) aVar).width = -1;
                this.D.setLayoutParams(aVar);
                return;
            }
            return;
        }
        this.C.setVisibility(0);
        FrameLayout frameLayout2 = this.D;
        if (frameLayout2 != null) {
            m0.a aVar2 = (m0.a) frameLayout2.getLayoutParams();
            ((LinearLayout.LayoutParams) aVar2).width = -2;
            this.D.setLayoutParams(aVar2);
        }
    }

    private StateListDrawable C() {
        TypedValue typedValue = new TypedValue();
        if (!getContext().getTheme().resolveAttribute(c.a.f3172w, typedValue, true)) {
            return null;
        }
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(J, new ColorDrawable(typedValue.data));
        stateListDrawable.addState(ViewGroup.EMPTY_STATE_SET, new ColorDrawable(0));
        return stateListDrawable;
    }

    private boolean D() {
        return this.E.getTitle() == null && this.E.getIcon() == null && this.E.getActionView() != null;
    }

    private void setActionView(View view) {
        if (view != null) {
            if (this.D == null) {
                this.D = (FrameLayout) ((ViewStub) findViewById(l0.f.f5386d)).inflate();
            }
            this.D.removeAllViews();
            this.D.addView(view);
        }
    }

    @Override // androidx.appcompat.view.menu.n.a
    public boolean d() {
        return false;
    }

    @Override // androidx.appcompat.view.menu.n.a
    public void e(androidx.appcompat.view.menu.i iVar, int i3) {
        this.E = iVar;
        if (iVar.getItemId() > 0) {
            setId(iVar.getItemId());
        }
        setVisibility(iVar.isVisible() ? 0 : 8);
        if (getBackground() == null) {
            y.v0(this, C());
        }
        setCheckable(iVar.isCheckable());
        setChecked(iVar.isChecked());
        setEnabled(iVar.isEnabled());
        setTitle(iVar.getTitle());
        setIcon(iVar.getIcon());
        setActionView(iVar.getActionView());
        setContentDescription(iVar.getContentDescription());
        d1.a(this, iVar.getTooltipText());
        B();
    }

    @Override // androidx.appcompat.view.menu.n.a
    public androidx.appcompat.view.menu.i getItemData() {
        return this.E;
    }

    @Override // android.view.ViewGroup, android.view.View
    protected int[] onCreateDrawableState(int i3) {
        int[] iArrOnCreateDrawableState = super.onCreateDrawableState(i3 + 1);
        androidx.appcompat.view.menu.i iVar = this.E;
        if (iVar != null && iVar.isCheckable() && this.E.isChecked()) {
            ViewGroup.mergeDrawableStates(iArrOnCreateDrawableState, J);
        }
        return iArrOnCreateDrawableState;
    }

    public void setCheckable(boolean z2) {
        refreshDrawableState();
        if (this.B != z2) {
            this.B = z2;
            this.I.l(this.C, 2048);
        }
    }

    public void setChecked(boolean z2) {
        refreshDrawableState();
        this.C.setChecked(z2);
    }

    public void setHorizontalPadding(int i3) {
        setPadding(i3, getPaddingTop(), i3, getPaddingBottom());
    }

    public void setIcon(Drawable drawable) {
        if (drawable != null) {
            if (this.G) {
                Drawable.ConstantState constantState = drawable.getConstantState();
                if (constantState != null) {
                    drawable = constantState.newDrawable();
                }
                drawable = androidx.core.graphics.drawable.a.r(drawable).mutate();
                androidx.core.graphics.drawable.a.o(drawable, this.F);
            }
            int i3 = this.f4019z;
            drawable.setBounds(0, 0, i3, i3);
        } else if (this.A) {
            if (this.H == null) {
                Drawable drawableE = androidx.core.content.res.h.e(getResources(), l0.e.f5382g, getContext().getTheme());
                this.H = drawableE;
                if (drawableE != null) {
                    int i4 = this.f4019z;
                    drawableE.setBounds(0, 0, i4, i4);
                }
            }
            drawable = this.H;
        }
        androidx.core.widget.j.i(this.C, drawable, null, null, null);
    }

    public void setIconPadding(int i3) {
        this.C.setCompoundDrawablePadding(i3);
    }

    public void setIconSize(int i3) {
        this.f4019z = i3;
    }

    void setIconTintList(ColorStateList colorStateList) {
        this.F = colorStateList;
        this.G = colorStateList != null;
        androidx.appcompat.view.menu.i iVar = this.E;
        if (iVar != null) {
            setIcon(iVar.getIcon());
        }
    }

    public void setMaxLines(int i3) {
        this.C.setMaxLines(i3);
    }

    public void setNeedsEmptyIcon(boolean z2) {
        this.A = z2;
    }

    public void setTextAppearance(int i3) {
        androidx.core.widget.j.n(this.C, i3);
    }

    public void setTextColor(ColorStateList colorStateList) {
        this.C.setTextColor(colorStateList);
    }

    public void setTitle(CharSequence charSequence) {
        this.C.setText(charSequence);
    }

    public NavigationMenuItemView(Context context, AttributeSet attributeSet, int i3) {
        super(context, attributeSet, i3);
        a aVar = new a();
        this.I = aVar;
        setOrientation(0);
        LayoutInflater.from(context).inflate(l0.h.f5412a, (ViewGroup) this, true);
        setIconSize(context.getResources().getDimensionPixelSize(l0.d.f5354e));
        CheckedTextView checkedTextView = (CheckedTextView) findViewById(l0.f.f5387e);
        this.C = checkedTextView;
        checkedTextView.setDuplicateParentStateEnabled(true);
        y.r0(checkedTextView, aVar);
    }
}
