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.annotation.Dimension;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.core.view.s1;
import l.y3;
import l.z1;

/* JADX INFO: loaded from: classes2.dex */
@RestrictTo({RestrictTo.Scope.f556b})
public class NavigationMenuItemView extends ForegroundLinearLayout implements k.c0 {

    /* JADX INFO: renamed from: l0, reason: collision with root package name */
    public static final int[] f22672l0 = {R.attr.state_checked};

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

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

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

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

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public final CheckedTextView f22677e0;

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    public FrameLayout f22678f0;

    /* JADX INFO: renamed from: g0, reason: collision with root package name */
    public k.r f22679g0;

    /* JADX INFO: renamed from: h0, reason: collision with root package name */
    public ColorStateList f22680h0;

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

    /* JADX INFO: renamed from: j0, reason: collision with root package name */
    public Drawable f22682j0;

    /* JADX INFO: renamed from: k0, reason: collision with root package name */
    public final a3.g0 f22683k0;

    public NavigationMenuItemView(@NonNull Context context) {
        this(context, null);
    }

    @Nullable
    private StateListDrawable createDefaultBackground() {
        TypedValue typedValue = new TypedValue();
        if (!getContext().getTheme().resolveAttribute(d.a.colorControlHighlight, typedValue, true)) {
            return null;
        }
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(f22672l0, new ColorDrawable(typedValue.data));
        stateListDrawable.addState(ViewGroup.EMPTY_STATE_SET, new ColorDrawable(0));
        return stateListDrawable;
    }

    private void setActionView(@Nullable View view) {
        if (view != null) {
            if (this.f22678f0 == null) {
                this.f22678f0 = (FrameLayout) ((ViewStub) findViewById(x8.g.design_menu_item_action_area_stub)).inflate();
            }
            if (view.getParent() != null) {
                ((ViewGroup) view.getParent()).removeView(view);
            }
            this.f22678f0.removeAllViews();
            this.f22678f0.addView(view);
        }
    }

    @Override // k.c0
    public final void c(k.r rVar) {
        this.f22679g0 = rVar;
        int i10 = rVar.f28908a;
        if (i10 > 0) {
            setId(i10);
        }
        setVisibility(rVar.isVisible() ? 0 : 8);
        if (getBackground() == null) {
            setBackground(createDefaultBackground());
        }
        setCheckable(rVar.isCheckable());
        setChecked(rVar.isChecked());
        setEnabled(rVar.isEnabled());
        setTitle(rVar.f28912e);
        setIcon(rVar.getIcon());
        setActionView(rVar.getActionView());
        setContentDescription(rVar.f28924q);
        y3.setTooltipText(this, rVar.f28925r);
        k.r rVar2 = this.f22679g0;
        CharSequence charSequence = rVar2.f28912e;
        CheckedTextView checkedTextView = this.f22677e0;
        if (charSequence == null && rVar2.getIcon() == null && this.f22679g0.getActionView() != null) {
            checkedTextView.setVisibility(8);
            FrameLayout frameLayout = this.f22678f0;
            if (frameLayout != null) {
                z1 z1Var = (z1) frameLayout.getLayoutParams();
                ((LinearLayout.LayoutParams) z1Var).width = -1;
                this.f22678f0.setLayoutParams(z1Var);
                return;
            }
            return;
        }
        checkedTextView.setVisibility(0);
        FrameLayout frameLayout2 = this.f22678f0;
        if (frameLayout2 != null) {
            z1 z1Var2 = (z1) frameLayout2.getLayoutParams();
            ((LinearLayout.LayoutParams) z1Var2).width = -2;
            this.f22678f0.setLayoutParams(z1Var2);
        }
    }

    @Override // k.c0
    public k.r getItemData() {
        return this.f22679g0;
    }

    @Override // android.view.ViewGroup, android.view.View
    public final int[] onCreateDrawableState(int i10) {
        int[] iArrOnCreateDrawableState = super.onCreateDrawableState(i10 + 1);
        k.r rVar = this.f22679g0;
        if (rVar != null && rVar.isCheckable() && this.f22679g0.isChecked()) {
            View.mergeDrawableStates(iArrOnCreateDrawableState, f22672l0);
        }
        return iArrOnCreateDrawableState;
    }

    public void setCheckable(boolean z10) {
        refreshDrawableState();
        if (this.f22675c0 != z10) {
            this.f22675c0 = z10;
            this.f22683k0.f(this.f22677e0, 2048);
        }
    }

    public void setChecked(boolean z10) {
        refreshDrawableState();
        CheckedTextView checkedTextView = this.f22677e0;
        checkedTextView.setChecked(z10);
        checkedTextView.setTypeface(checkedTextView.getTypeface(), (z10 && this.f22676d0) ? 1 : 0);
    }

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

    public void setIcon(@Nullable Drawable drawable) {
        if (drawable != null) {
            if (this.f22681i0) {
                Drawable.ConstantState constantState = drawable.getConstantState();
                if (constantState != null) {
                    drawable = constantState.newDrawable();
                }
                drawable = drawable.mutate();
                drawable.setTintList(this.f22680h0);
            }
            int i10 = this.f22673a0;
            drawable.setBounds(0, 0, i10, i10);
        } else if (this.f22674b0) {
            if (this.f22682j0 == null) {
                Drawable drawable2 = i0.r.getDrawable(getResources(), x8.f.navigation_empty_icon, getContext().getTheme());
                this.f22682j0 = drawable2;
                if (drawable2 != null) {
                    int i11 = this.f22673a0;
                    drawable2.setBounds(0, 0, i11, i11);
                }
            }
            drawable = this.f22682j0;
        }
        this.f22677e0.setCompoundDrawablesRelative(drawable, null, null, null);
    }

    public void setIconPadding(int i10) {
        this.f22677e0.setCompoundDrawablePadding(i10);
    }

    public void setIconSize(@Dimension int i10) {
        this.f22673a0 = i10;
    }

    public void setIconTintList(ColorStateList colorStateList) {
        this.f22680h0 = colorStateList;
        this.f22681i0 = colorStateList != null;
        k.r rVar = this.f22679g0;
        if (rVar != null) {
            setIcon(rVar.getIcon());
        }
    }

    public void setMaxLines(int i10) {
        this.f22677e0.setMaxLines(i10);
    }

    public void setNeedsEmptyIcon(boolean z10) {
        this.f22674b0 = z10;
    }

    public void setShortcut(boolean z10, char c6) {
    }

    public void setTextAppearance(int i10) {
        this.f22677e0.setTextAppearance(i10);
    }

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

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

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

    public NavigationMenuItemView(@NonNull Context context, @Nullable AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
        this.f22676d0 = true;
        a3.g0 g0Var = new a3.g0(this, 7);
        this.f22683k0 = g0Var;
        setOrientation(0);
        LayoutInflater.from(context).inflate(x8.i.design_navigation_menu_item, (ViewGroup) this, true);
        setIconSize(context.getResources().getDimensionPixelSize(x8.e.design_navigation_icon_size));
        CheckedTextView checkedTextView = (CheckedTextView) findViewById(x8.g.design_menu_item_text);
        this.f22677e0 = checkedTextView;
        s1.setAccessibilityDelegate(checkedTextView, g0Var);
    }
}
