package f9;

import android.R;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.text.TextPaint;
import android.text.TextUtils;
import android.util.AttributeSet;
import androidx.annotation.AttrRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import com.google.android.material.chip.Chip;
import com.google.android.material.internal.m0;
import com.google.android.material.internal.n0;
import com.google.android.material.internal.q0;
import com.google.android.material.internal.w0;
import com.google.android.material.shape.k;
import com.google.android.material.shape.q;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import x8.m;

/* JADX INFO: loaded from: classes2.dex */
public final class e extends k implements Drawable.Callback, m0 {
    public static final int[] T0 = {R.attr.state_enabled};
    public static final ShapeDrawable U0 = new ShapeDrawable(new OvalShape());
    public final PointF A0;
    public final Path B0;
    public final n0 C0;
    public int D0;
    public int E0;
    public int F0;
    public int G0;
    public int H0;
    public int I0;
    public boolean J0;
    public int K0;
    public int L0;
    public int[] M0;
    public boolean N0;
    public WeakReference O0;
    public TextUtils.TruncateAt P0;
    public boolean Q0;
    public int R0;
    public boolean S0;

    @Nullable
    private Drawable checkedIcon;

    @Nullable
    private ColorStateList checkedIconTint;

    @Nullable
    private ColorStateList chipBackgroundColor;

    @Nullable
    private Drawable chipIcon;

    @Nullable
    private ColorStateList chipIconTint;

    @Nullable
    private ColorStateList chipStrokeColor;

    @Nullable
    private ColorStateList chipSurfaceColor;

    @Nullable
    private Drawable closeIcon;

    @Nullable
    private CharSequence closeIconContentDescription;

    @Nullable
    private Drawable closeIconRipple;

    @Nullable
    private ColorStateList closeIconTint;

    @Nullable
    private ColorFilter colorFilter;

    @Nullable
    private ColorStateList compatRippleColor;

    @Nullable
    private final Paint debugPaint;

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public float f25957e0;

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

    /* JADX INFO: renamed from: g0, reason: collision with root package name */
    public float f25959g0;

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

    @Nullable
    private y8.g hideMotionSpec;

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

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

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

    /* JADX INFO: renamed from: l0, reason: collision with root package name */
    public float f25964l0;

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

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

    /* JADX INFO: renamed from: o0, reason: collision with root package name */
    public float f25967o0;

    /* JADX INFO: renamed from: p0, reason: collision with root package name */
    public float f25968p0;

    /* JADX INFO: renamed from: q0, reason: collision with root package name */
    public float f25969q0;

    /* JADX INFO: renamed from: r0, reason: collision with root package name */
    public float f25970r0;

    @Nullable
    private ColorStateList rippleColor;

    /* JADX INFO: renamed from: s0, reason: collision with root package name */
    public float f25971s0;

    @Nullable
    private y8.g showMotionSpec;

    /* JADX INFO: renamed from: t0, reason: collision with root package name */
    public float f25972t0;

    @Nullable
    private CharSequence text;

    @Nullable
    private ColorStateList tint;

    @Nullable
    private PorterDuffColorFilter tintFilter;

    @Nullable
    private PorterDuff.Mode tintMode;

    /* JADX INFO: renamed from: u0, reason: collision with root package name */
    public float f25973u0;

    /* JADX INFO: renamed from: v0, reason: collision with root package name */
    public float f25974v0;

    /* JADX INFO: renamed from: w0, reason: collision with root package name */
    public final Context f25975w0;

    /* JADX INFO: renamed from: x0, reason: collision with root package name */
    public final Paint f25976x0;

    /* JADX INFO: renamed from: y0, reason: collision with root package name */
    public final Paint.FontMetrics f25977y0;
    public final RectF z0;

    public e(Context context, AttributeSet attributeSet, int i10, int i11) {
        super(context, attributeSet, i10, i11);
        this.f25958f0 = -1.0f;
        this.f25976x0 = new Paint(1);
        this.f25977y0 = new Paint.FontMetrics();
        this.z0 = new RectF();
        this.A0 = new PointF();
        this.B0 = new Path();
        this.L0 = 255;
        this.tintMode = PorterDuff.Mode.SRC_IN;
        this.O0 = new WeakReference(null);
        s(context);
        this.f25975w0 = context;
        n0 n0Var = new n0(this);
        this.C0 = n0Var;
        this.text = "";
        n0Var.f22792a.density = context.getResources().getDisplayMetrics().density;
        this.debugPaint = null;
        int[] iArr = T0;
        setState(iArr);
        b0(iArr);
        this.Q0 = true;
        U0.setTint(-1);
    }

    private void applyChildDrawable(@Nullable Drawable drawable) {
        if (drawable == null) {
            return;
        }
        drawable.setCallback(this);
        drawable.setLayoutDirection(getLayoutDirection());
        drawable.setLevel(getLevel());
        drawable.setVisible(isVisible(), false);
        if (drawable == this.closeIcon) {
            if (drawable.isStateful()) {
                drawable.setState(this.M0);
            }
            drawable.setTintList(this.closeIconTint);
            return;
        }
        Drawable drawable2 = this.chipIcon;
        if (drawable == drawable2 && this.f25962j0) {
            drawable2.setTintList(this.chipIconTint);
        }
        if (drawable.isStateful()) {
            drawable.setState(getState());
        }
    }

    @NonNull
    public static e createFromAttributes(@NonNull Context context, @Nullable AttributeSet attributeSet, @AttrRes int i10, @StyleRes int i11) {
        e eVar = new e(context, attributeSet, i10, i11);
        eVar.loadFromAttributes(attributeSet, i10, i11);
        return eVar;
    }

    @Nullable
    private ColorFilter getTintColorFilter() {
        ColorFilter colorFilter = this.colorFilter;
        return colorFilter != null ? colorFilter : this.tintFilter;
    }

    private static boolean hasState(@Nullable int[] iArr, @AttrRes int i10) {
        if (iArr == null) {
            return false;
        }
        for (int i11 : iArr) {
            if (i11 == i10) {
                return true;
            }
        }
        return false;
    }

    private void loadFromAttributes(@Nullable AttributeSet attributeSet, @AttrRes int i10, @StyleRes int i11) {
        TypedArray typedArrayC = q0.c(this.f25975w0, attributeSet, m.Chip, i10, i11, new int[0]);
        this.S0 = typedArrayC.hasValue(m.Chip_shapeAppearance);
        int i12 = m.Chip_chipSurfaceColor;
        Context context = this.f25975w0;
        setChipSurfaceColor(q9.d.getColorStateList(context, typedArrayC, i12));
        setChipBackgroundColor(q9.d.getColorStateList(context, typedArrayC, m.Chip_chipBackgroundColor));
        float dimension = typedArrayC.getDimension(m.Chip_chipMinHeight, 0.0f);
        if (this.f25957e0 != dimension) {
            this.f25957e0 = dimension;
            invalidateSelf();
            P();
        }
        int i13 = m.Chip_chipCornerRadius;
        if (typedArrayC.hasValue(i13)) {
            U(typedArrayC.getDimension(i13, 0.0f));
        }
        setChipStrokeColor(q9.d.getColorStateList(context, typedArrayC, m.Chip_chipStrokeColor));
        X(typedArrayC.getDimension(m.Chip_chipStrokeWidth, 0.0f));
        setRippleColor(q9.d.getColorStateList(context, typedArrayC, m.Chip_rippleColor));
        setText(typedArrayC.getText(m.Chip_android_text));
        q9.g textAppearance = q9.d.getTextAppearance(context, typedArrayC, m.Chip_android_textAppearance);
        textAppearance.f32262h = typedArrayC.getDimension(m.Chip_android_textSize, textAppearance.f32262h);
        setTextAppearance(textAppearance);
        int i14 = typedArrayC.getInt(m.Chip_android_ellipsize, 0);
        if (i14 == 1) {
            setEllipsize(TextUtils.TruncateAt.START);
        } else if (i14 == 2) {
            setEllipsize(TextUtils.TruncateAt.MIDDLE);
        } else if (i14 == 3) {
            setEllipsize(TextUtils.TruncateAt.END);
        }
        W(typedArrayC.getBoolean(m.Chip_chipIconVisible, false));
        if (attributeSet != null && attributeSet.getAttributeValue("http://schemas.android.com/apk/res-auto", "chipIconEnabled") != null && attributeSet.getAttributeValue("http://schemas.android.com/apk/res-auto", "chipIconVisible") == null) {
            W(typedArrayC.getBoolean(m.Chip_chipIconEnabled, false));
        }
        setChipIcon(q9.d.getDrawable(context, typedArrayC, m.Chip_chipIcon));
        int i15 = m.Chip_chipIconTint;
        if (typedArrayC.hasValue(i15)) {
            setChipIconTint(q9.d.getColorStateList(context, typedArrayC, i15));
        }
        V(typedArrayC.getDimension(m.Chip_chipIconSize, -1.0f));
        c0(typedArrayC.getBoolean(m.Chip_closeIconVisible, false));
        if (attributeSet != null && attributeSet.getAttributeValue("http://schemas.android.com/apk/res-auto", "closeIconEnabled") != null && attributeSet.getAttributeValue("http://schemas.android.com/apk/res-auto", "closeIconVisible") == null) {
            c0(typedArrayC.getBoolean(m.Chip_closeIconEnabled, false));
        }
        setCloseIcon(q9.d.getDrawable(context, typedArrayC, m.Chip_closeIcon));
        setCloseIconTint(q9.d.getColorStateList(context, typedArrayC, m.Chip_closeIconTint));
        Z(typedArrayC.getDimension(m.Chip_closeIconSize, 0.0f));
        S(typedArrayC.getBoolean(m.Chip_android_checkable, false));
        T(typedArrayC.getBoolean(m.Chip_checkedIconVisible, false));
        if (attributeSet != null && attributeSet.getAttributeValue("http://schemas.android.com/apk/res-auto", "checkedIconEnabled") != null && attributeSet.getAttributeValue("http://schemas.android.com/apk/res-auto", "checkedIconVisible") == null) {
            T(typedArrayC.getBoolean(m.Chip_checkedIconEnabled, false));
        }
        setCheckedIcon(q9.d.getDrawable(context, typedArrayC, m.Chip_checkedIcon));
        int i16 = m.Chip_checkedIconTint;
        if (typedArrayC.hasValue(i16)) {
            setCheckedIconTint(q9.d.getColorStateList(context, typedArrayC, i16));
        }
        setShowMotionSpec(y8.g.createFromAttribute(context, typedArrayC, m.Chip_showMotionSpec));
        setHideMotionSpec(y8.g.createFromAttribute(context, typedArrayC, m.Chip_hideMotionSpec));
        float dimension2 = typedArrayC.getDimension(m.Chip_chipStartPadding, 0.0f);
        if (this.f25967o0 != dimension2) {
            this.f25967o0 = dimension2;
            invalidateSelf();
            P();
        }
        e0(typedArrayC.getDimension(m.Chip_iconStartPadding, 0.0f));
        d0(typedArrayC.getDimension(m.Chip_iconEndPadding, 0.0f));
        float dimension3 = typedArrayC.getDimension(m.Chip_textStartPadding, 0.0f);
        if (this.f25970r0 != dimension3) {
            this.f25970r0 = dimension3;
            invalidateSelf();
            P();
        }
        float dimension4 = typedArrayC.getDimension(m.Chip_textEndPadding, 0.0f);
        if (this.f25971s0 != dimension4) {
            this.f25971s0 = dimension4;
            invalidateSelf();
            P();
        }
        a0(typedArrayC.getDimension(m.Chip_closeIconStartPadding, 0.0f));
        Y(typedArrayC.getDimension(m.Chip_closeIconEndPadding, 0.0f));
        float dimension5 = typedArrayC.getDimension(m.Chip_chipEndPadding, 0.0f);
        if (this.f25974v0 != dimension5) {
            this.f25974v0 = dimension5;
            invalidateSelf();
            P();
        }
        this.R0 = typedArrayC.getDimensionPixelSize(m.Chip_android_maxWidth, Integer.MAX_VALUE);
        typedArrayC.recycle();
    }

    private void setChipSurfaceColor(@Nullable ColorStateList colorStateList) {
        if (this.chipSurfaceColor != colorStateList) {
            this.chipSurfaceColor = colorStateList;
            onStateChange(getState());
        }
    }

    private void unapplyChildDrawable(@Nullable Drawable drawable) {
        if (drawable != null) {
            drawable.setCallback(null);
        }
    }

    public final void I(Rect rect, RectF rectF) {
        rectF.setEmpty();
        if (g0() || f0()) {
            float f10 = this.f25967o0 + this.f25968p0;
            Drawable drawable = this.J0 ? this.checkedIcon : this.chipIcon;
            float intrinsicWidth = this.f25961i0;
            if (intrinsicWidth <= 0.0f && drawable != null) {
                intrinsicWidth = drawable.getIntrinsicWidth();
            }
            if (getLayoutDirection() == 0) {
                float f11 = rect.left + f10;
                rectF.left = f11;
                rectF.right = f11 + intrinsicWidth;
            } else {
                float f12 = rect.right - f10;
                rectF.right = f12;
                rectF.left = f12 - intrinsicWidth;
            }
            Drawable drawable2 = this.J0 ? this.checkedIcon : this.chipIcon;
            float fCeil = this.f25961i0;
            if (fCeil <= 0.0f && drawable2 != null) {
                fCeil = (float) Math.ceil(w0.d(this.f25975w0, 24));
                if (drawable2.getIntrinsicHeight() <= fCeil) {
                    fCeil = drawable2.getIntrinsicHeight();
                }
            }
            float fExactCenterY = rect.exactCenterY() - (fCeil / 2.0f);
            rectF.top = fExactCenterY;
            rectF.bottom = fExactCenterY + fCeil;
        }
    }

    public final float J() {
        if (!g0() && !f0()) {
            return 0.0f;
        }
        float f10 = this.f25968p0;
        Drawable drawable = this.J0 ? this.checkedIcon : this.chipIcon;
        float intrinsicWidth = this.f25961i0;
        if (intrinsicWidth <= 0.0f && drawable != null) {
            intrinsicWidth = drawable.getIntrinsicWidth();
        }
        return intrinsicWidth + f10 + this.f25969q0;
    }

    public final void K(Rect rect, RectF rectF) {
        rectF.setEmpty();
        if (h0()) {
            float f10 = this.f25974v0 + this.f25973u0;
            if (getLayoutDirection() == 0) {
                float f11 = rect.right - f10;
                rectF.right = f11;
                rectF.left = f11 - this.f25964l0;
            } else {
                float f12 = rect.left + f10;
                rectF.left = f12;
                rectF.right = f12 + this.f25964l0;
            }
            float fExactCenterY = rect.exactCenterY();
            float f13 = this.f25964l0;
            float f14 = fExactCenterY - (f13 / 2.0f);
            rectF.top = f14;
            rectF.bottom = f14 + f13;
        }
    }

    public final void L(Rect rect, RectF rectF) {
        rectF.setEmpty();
        if (h0()) {
            float f10 = this.f25974v0 + this.f25973u0 + this.f25964l0 + this.f25972t0 + this.f25971s0;
            if (getLayoutDirection() == 0) {
                float f11 = rect.right;
                rectF.right = f11;
                rectF.left = f11 - f10;
            } else {
                float f12 = rect.left;
                rectF.left = f12;
                rectF.right = f12 + f10;
            }
            rectF.top = rect.top;
            rectF.bottom = rect.bottom;
        }
    }

    public final float M() {
        if (h0()) {
            return this.f25972t0 + this.f25964l0 + this.f25973u0;
        }
        return 0.0f;
    }

    public final float N() {
        return this.S0 ? p() : this.f25958f0;
    }

    public final boolean O() {
        return isStateful(this.closeIcon);
    }

    public final void P() {
        d dVar = (d) this.O0.get();
        if (dVar != null) {
            Chip chip = (Chip) dVar;
            chip.f(chip.f22431k);
            chip.requestLayout();
            chip.invalidateOutline();
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:54:0x009e  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean Q(int[] iArr, int[] iArr2) {
        int colorForState;
        boolean z10;
        boolean zOnStateChange = super.onStateChange(iArr);
        ColorStateList colorStateList = this.chipSurfaceColor;
        int iF = f(colorStateList != null ? colorStateList.getColorForState(iArr, this.D0) : 0);
        boolean state = true;
        if (this.D0 != iF) {
            this.D0 = iF;
            zOnStateChange = true;
        }
        ColorStateList colorStateList2 = this.chipBackgroundColor;
        int iF2 = f(colorStateList2 != null ? colorStateList2.getColorForState(iArr, this.E0) : 0);
        if (this.E0 != iF2) {
            this.E0 = iF2;
            zOnStateChange = true;
        }
        int iC = j0.c.c(iF2, iF);
        if ((this.F0 != iC) | (getFillColor() == null)) {
            this.F0 = iC;
            setFillColor(ColorStateList.valueOf(iC));
            zOnStateChange = true;
        }
        ColorStateList colorStateList3 = this.chipStrokeColor;
        int colorForState2 = colorStateList3 != null ? colorStateList3.getColorForState(iArr, this.G0) : 0;
        if (this.G0 != colorForState2) {
            this.G0 = colorForState2;
            zOnStateChange = true;
        }
        if (this.compatRippleColor != null) {
            boolean z11 = false;
            boolean z12 = false;
            for (int i10 : iArr) {
                if (i10 == 16842910) {
                    z11 = true;
                } else if (i10 == 16842908 || i10 == 16842919 || i10 == 16843623) {
                    z12 = true;
                }
            }
            colorForState = (z11 && z12) ? this.compatRippleColor.getColorForState(iArr, this.H0) : 0;
        }
        if (this.H0 != colorForState) {
            this.H0 = colorForState;
            if (this.N0) {
                zOnStateChange = true;
            }
        }
        n0 n0Var = this.C0;
        int colorForState3 = (n0Var.getTextAppearance() == null || n0Var.getTextAppearance().getTextColor() == null) ? 0 : n0Var.getTextAppearance().getTextColor().getColorForState(iArr, this.I0);
        if (this.I0 != colorForState3) {
            this.I0 = colorForState3;
            zOnStateChange = true;
        }
        boolean z13 = hasState(getState(), R.attr.state_checked) && this.f25965m0;
        if (this.J0 == z13 || this.checkedIcon == null) {
            z10 = false;
        } else {
            float fJ = J();
            this.J0 = z13;
            if (fJ != J()) {
                zOnStateChange = true;
                z10 = true;
            } else {
                z10 = false;
                zOnStateChange = true;
            }
        }
        ColorStateList colorStateList4 = this.tint;
        int colorForState4 = colorStateList4 != null ? colorStateList4.getColorForState(iArr, this.K0) : 0;
        if (this.K0 != colorForState4) {
            this.K0 = colorForState4;
            this.tintFilter = j9.c.updateTintFilter(this, this.tint, this.tintMode);
        } else {
            state = zOnStateChange;
        }
        if (isStateful(this.chipIcon)) {
            state |= this.chipIcon.setState(iArr);
        }
        if (isStateful(this.checkedIcon)) {
            state |= this.checkedIcon.setState(iArr);
        }
        if (isStateful(this.closeIcon)) {
            int[] iArr3 = new int[iArr.length + iArr2.length];
            System.arraycopy(iArr, 0, iArr3, 0, iArr.length);
            System.arraycopy(iArr2, 0, iArr3, iArr.length, iArr2.length);
            state |= this.closeIcon.setState(iArr3);
        }
        if (isStateful(this.closeIconRipple)) {
            state |= this.closeIconRipple.setState(iArr2);
        }
        if (state) {
            invalidateSelf();
        }
        if (z10) {
            P();
        }
        return state;
    }

    public final boolean R(boolean z10) {
        if (this.closeIcon != null) {
            return b0(z10 ? new int[]{R.attr.state_pressed, R.attr.state_enabled} : T0);
        }
        return false;
    }

    public final void S(boolean z10) {
        if (this.f25965m0 != z10) {
            this.f25965m0 = z10;
            float fJ = J();
            if (!z10 && this.J0) {
                this.J0 = false;
            }
            float fJ2 = J();
            invalidateSelf();
            if (fJ != fJ2) {
                P();
            }
        }
    }

    public final void T(boolean z10) {
        if (this.f25966n0 != z10) {
            boolean zF0 = f0();
            this.f25966n0 = z10;
            boolean zF02 = f0();
            if (zF0 != zF02) {
                if (zF02) {
                    applyChildDrawable(this.checkedIcon);
                } else {
                    unapplyChildDrawable(this.checkedIcon);
                }
                invalidateSelf();
                P();
            }
        }
    }

    public final void U(float f10) {
        if (this.f25958f0 != f10) {
            this.f25958f0 = f10;
            q qVarH = this.f23095b.f23068a.h();
            qVarH.c(f10);
            setShapeAppearanceModel(qVarH.a());
        }
    }

    public final void V(float f10) {
        if (this.f25961i0 != f10) {
            float fJ = J();
            this.f25961i0 = f10;
            float fJ2 = J();
            invalidateSelf();
            if (fJ != fJ2) {
                P();
            }
        }
    }

    public final void W(boolean z10) {
        if (this.f25960h0 != z10) {
            boolean zG0 = g0();
            this.f25960h0 = z10;
            boolean zG02 = g0();
            if (zG0 != zG02) {
                if (zG02) {
                    applyChildDrawable(this.chipIcon);
                } else {
                    unapplyChildDrawable(this.chipIcon);
                }
                invalidateSelf();
                P();
            }
        }
    }

    public final void X(float f10) {
        if (this.f25959g0 != f10) {
            this.f25959g0 = f10;
            this.f25976x0.setStrokeWidth(f10);
            if (this.S0) {
                D(f10);
            }
            invalidateSelf();
        }
    }

    public final void Y(float f10) {
        if (this.f25973u0 != f10) {
            this.f25973u0 = f10;
            invalidateSelf();
            if (h0()) {
                P();
            }
        }
    }

    public final void Z(float f10) {
        if (this.f25964l0 != f10) {
            this.f25964l0 = f10;
            invalidateSelf();
            if (h0()) {
                P();
            }
        }
    }

    @Override // com.google.android.material.shape.k, com.google.android.material.internal.m0
    public final void a() {
        P();
        invalidateSelf();
    }

    public final void a0(float f10) {
        if (this.f25972t0 != f10) {
            this.f25972t0 = f10;
            invalidateSelf();
            if (h0()) {
                P();
            }
        }
    }

    public final boolean b0(int[] iArr) {
        if (Arrays.equals(this.M0, iArr)) {
            return false;
        }
        this.M0 = iArr;
        if (h0()) {
            return Q(getState(), iArr);
        }
        return false;
    }

    public final void c0(boolean z10) {
        if (this.f25963k0 != z10) {
            boolean zH0 = h0();
            this.f25963k0 = z10;
            boolean zH02 = h0();
            if (zH0 != zH02) {
                if (zH02) {
                    applyChildDrawable(this.closeIcon);
                } else {
                    unapplyChildDrawable(this.closeIcon);
                }
                invalidateSelf();
                P();
            }
        }
    }

    public final void d0(float f10) {
        if (this.f25969q0 != f10) {
            float fJ = J();
            this.f25969q0 = f10;
            float fJ2 = J();
            invalidateSelf();
            if (fJ != fJ2) {
                P();
            }
        }
    }

    @Override // com.google.android.material.shape.k, android.graphics.drawable.Drawable
    public final void draw(Canvas canvas) {
        int i10;
        int i11;
        Rect bounds = getBounds();
        if (bounds.isEmpty() || (i10 = this.L0) == 0) {
            return;
        }
        int iSaveLayerAlpha = i10 < 255 ? canvas.saveLayerAlpha(bounds.left, bounds.top, bounds.right, bounds.bottom, i10) : 0;
        boolean z10 = this.S0;
        Paint paint = this.f25976x0;
        RectF rectF = this.z0;
        if (!z10) {
            paint.setColor(this.D0);
            paint.setStyle(Paint.Style.FILL);
            rectF.set(bounds);
            canvas.drawRoundRect(rectF, N(), N(), paint);
        }
        if (!this.S0) {
            paint.setColor(this.E0);
            paint.setStyle(Paint.Style.FILL);
            paint.setColorFilter(getTintColorFilter());
            rectF.set(bounds);
            canvas.drawRoundRect(rectF, N(), N(), paint);
        }
        if (this.S0) {
            super.draw(canvas);
        }
        if (this.f25959g0 > 0.0f && !this.S0) {
            paint.setColor(this.G0);
            paint.setStyle(Paint.Style.STROKE);
            if (!this.S0) {
                paint.setColorFilter(getTintColorFilter());
            }
            float f10 = bounds.left;
            float f11 = this.f25959g0 / 2.0f;
            rectF.set(f10 + f11, bounds.top + f11, bounds.right - f11, bounds.bottom - f11);
            float f12 = this.f25958f0 - (this.f25959g0 / 2.0f);
            canvas.drawRoundRect(rectF, f12, f12, paint);
        }
        paint.setColor(this.H0);
        paint.setStyle(Paint.Style.FILL);
        rectF.set(bounds);
        if (this.S0) {
            RectF rectF2 = new RectF(bounds);
            Path path = this.B0;
            e(rectF2, path);
            h(canvas, paint, path, l());
        } else {
            canvas.drawRoundRect(rectF, N(), N(), paint);
        }
        if (g0()) {
            I(bounds, rectF);
            float f13 = rectF.left;
            float f14 = rectF.top;
            canvas.translate(f13, f14);
            this.chipIcon.setBounds(0, 0, (int) rectF.width(), (int) rectF.height());
            this.chipIcon.draw(canvas);
            canvas.translate(-f13, -f14);
        }
        if (f0()) {
            I(bounds, rectF);
            float f15 = rectF.left;
            float f16 = rectF.top;
            canvas.translate(f15, f16);
            this.checkedIcon.setBounds(0, 0, (int) rectF.width(), (int) rectF.height());
            this.checkedIcon.draw(canvas);
            canvas.translate(-f15, -f16);
        }
        if (this.Q0 && this.text != null) {
            PointF pointF = this.A0;
            pointF.set(0.0f, 0.0f);
            Paint.Align align = Paint.Align.LEFT;
            CharSequence charSequence = this.text;
            n0 n0Var = this.C0;
            if (charSequence != null) {
                float fJ = J() + this.f25967o0 + this.f25970r0;
                if (getLayoutDirection() == 0) {
                    pointF.x = bounds.left + fJ;
                } else {
                    pointF.x = bounds.right - fJ;
                    align = Paint.Align.RIGHT;
                }
                float fCenterY = bounds.centerY();
                TextPaint textPaint = n0Var.f22792a;
                Paint.FontMetrics fontMetrics = this.f25977y0;
                textPaint.getFontMetrics(fontMetrics);
                pointF.y = fCenterY - ((fontMetrics.descent + fontMetrics.ascent) / 2.0f);
            }
            rectF.setEmpty();
            if (this.text != null) {
                float fJ2 = J() + this.f25967o0 + this.f25970r0;
                float fM = M() + this.f25974v0 + this.f25971s0;
                if (getLayoutDirection() == 0) {
                    rectF.left = bounds.left + fJ2;
                    rectF.right = bounds.right - fM;
                } else {
                    rectF.left = bounds.left + fM;
                    rectF.right = bounds.right - fJ2;
                }
                rectF.top = bounds.top;
                rectF.bottom = bounds.bottom;
            }
            q9.g textAppearance = n0Var.getTextAppearance();
            TextPaint textPaint2 = n0Var.f22792a;
            if (textAppearance != null) {
                textPaint2.drawableState = getState();
                n0Var.c(this.f25975w0);
            }
            textPaint2.setTextAlign(align);
            boolean z11 = Math.round(n0Var.b(getText().toString())) > Math.round(rectF.width());
            if (z11) {
                int iSave = canvas.save();
                canvas.clipRect(rectF);
                i11 = iSave;
            } else {
                i11 = 0;
            }
            CharSequence charSequenceEllipsize = this.text;
            if (z11 && this.P0 != null) {
                charSequenceEllipsize = TextUtils.ellipsize(charSequenceEllipsize, textPaint2, rectF.width(), this.P0);
            }
            canvas.drawText(charSequenceEllipsize, 0, charSequenceEllipsize.length(), pointF.x, pointF.y, textPaint2);
            if (z11) {
                canvas.restoreToCount(i11);
            }
        }
        if (h0()) {
            K(bounds, rectF);
            float f17 = rectF.left;
            float f18 = rectF.top;
            canvas.translate(f17, f18);
            this.closeIcon.setBounds(0, 0, (int) rectF.width(), (int) rectF.height());
            this.closeIconRipple.setBounds(this.closeIcon.getBounds());
            this.closeIconRipple.jumpToCurrentState();
            this.closeIconRipple.draw(canvas);
            canvas.translate(-f17, -f18);
        }
        Paint paint2 = this.debugPaint;
        if (paint2 != null) {
            paint2.setColor(j0.c.e(-16777216, 127));
            canvas.drawRect(bounds, this.debugPaint);
            if (g0() || f0()) {
                I(bounds, rectF);
                canvas.drawRect(rectF, this.debugPaint);
            }
            if (this.text != null) {
                canvas.drawLine(bounds.left, bounds.exactCenterY(), bounds.right, bounds.exactCenterY(), this.debugPaint);
            }
            if (h0()) {
                K(bounds, rectF);
                canvas.drawRect(rectF, this.debugPaint);
            }
            this.debugPaint.setColor(j0.c.e(-65536, 127));
            rectF.set(bounds);
            if (h0()) {
                float f19 = this.f25974v0 + this.f25973u0 + this.f25964l0 + this.f25972t0 + this.f25971s0;
                if (getLayoutDirection() == 0) {
                    rectF.right = bounds.right - f19;
                } else {
                    rectF.left = bounds.left + f19;
                }
            }
            canvas.drawRect(rectF, this.debugPaint);
            this.debugPaint.setColor(j0.c.e(-16711936, 127));
            L(bounds, rectF);
            canvas.drawRect(rectF, this.debugPaint);
        }
        if (this.L0 < 255) {
            canvas.restoreToCount(iSaveLayerAlpha);
        }
    }

    public final void e0(float f10) {
        if (this.f25968p0 != f10) {
            float fJ = J();
            this.f25968p0 = f10;
            float fJ2 = J();
            invalidateSelf();
            if (fJ != fJ2) {
                P();
            }
        }
    }

    public final boolean f0() {
        return this.f25966n0 && this.checkedIcon != null && this.J0;
    }

    public final boolean g0() {
        return this.f25960h0 && this.chipIcon != null;
    }

    @Override // com.google.android.material.shape.k, android.graphics.drawable.Drawable
    public final int getAlpha() {
        return this.L0;
    }

    @Nullable
    public Drawable getCheckedIcon() {
        return this.checkedIcon;
    }

    @Nullable
    public ColorStateList getCheckedIconTint() {
        return this.checkedIconTint;
    }

    @Nullable
    public ColorStateList getChipBackgroundColor() {
        return this.chipBackgroundColor;
    }

    @Nullable
    public Drawable getChipIcon() {
        Drawable drawable = this.chipIcon;
        if (drawable != null) {
            return k0.a.b(drawable);
        }
        return null;
    }

    @Nullable
    public ColorStateList getChipIconTint() {
        return this.chipIconTint;
    }

    @Nullable
    public ColorStateList getChipStrokeColor() {
        return this.chipStrokeColor;
    }

    @Nullable
    public Drawable getCloseIcon() {
        Drawable drawable = this.closeIcon;
        if (drawable != null) {
            return k0.a.b(drawable);
        }
        return null;
    }

    @Nullable
    public CharSequence getCloseIconContentDescription() {
        return this.closeIconContentDescription;
    }

    @Nullable
    public ColorStateList getCloseIconTint() {
        return this.closeIconTint;
    }

    @Override // android.graphics.drawable.Drawable
    @Nullable
    public ColorFilter getColorFilter() {
        return this.colorFilter;
    }

    @Nullable
    public y8.g getHideMotionSpec() {
        return this.hideMotionSpec;
    }

    @Override // android.graphics.drawable.Drawable
    public final int getIntrinsicHeight() {
        return (int) this.f25957e0;
    }

    @Override // android.graphics.drawable.Drawable
    public final int getIntrinsicWidth() {
        return Math.min(Math.round(M() + this.C0.b(getText().toString()) + J() + this.f25967o0 + this.f25970r0 + this.f25971s0 + this.f25974v0), this.R0);
    }

    @Override // com.google.android.material.shape.k, android.graphics.drawable.Drawable
    public final int getOpacity() {
        return -3;
    }

    @Override // com.google.android.material.shape.k, android.graphics.drawable.Drawable
    public final void getOutline(Outline outline) {
        if (this.S0) {
            super.getOutline(outline);
            return;
        }
        Rect bounds = getBounds();
        if (bounds.isEmpty()) {
            outline.setRoundRect(0, 0, getIntrinsicWidth(), (int) this.f25957e0, this.f25958f0);
        } else {
            outline.setRoundRect(bounds, this.f25958f0);
        }
        outline.setAlpha(this.L0 / 255.0f);
    }

    @Nullable
    public ColorStateList getRippleColor() {
        return this.rippleColor;
    }

    @Nullable
    public y8.g getShowMotionSpec() {
        return this.showMotionSpec;
    }

    @Nullable
    public CharSequence getText() {
        return this.text;
    }

    @Nullable
    public q9.g getTextAppearance() {
        return this.C0.getTextAppearance();
    }

    public final boolean h0() {
        return this.f25963k0 && this.closeIcon != null;
    }

    public final void i0() {
        this.compatRippleColor = this.N0 ? r9.a.sanitizeRippleDrawableColor(this.rippleColor) : null;
    }

    @Override // android.graphics.drawable.Drawable.Callback
    public final void invalidateDrawable(Drawable drawable) {
        Drawable.Callback callback = getCallback();
        if (callback != null) {
            callback.invalidateDrawable(this);
        }
    }

    @Override // com.google.android.material.shape.k, android.graphics.drawable.Drawable
    public final boolean isStateful() {
        return isStateful(this.chipSurfaceColor) || isStateful(this.chipBackgroundColor) || isStateful(this.chipStrokeColor) || (this.N0 && isStateful(this.compatRippleColor)) || isStateful(this.C0.getTextAppearance()) || ((this.f25966n0 && this.checkedIcon != null && this.f25965m0) || isStateful(this.chipIcon) || isStateful(this.checkedIcon) || isStateful(this.tint));
    }

    @Override // android.graphics.drawable.Drawable
    public final boolean onLayoutDirectionChanged(int i10) {
        boolean zOnLayoutDirectionChanged = super.onLayoutDirectionChanged(i10);
        if (g0()) {
            zOnLayoutDirectionChanged |= this.chipIcon.setLayoutDirection(i10);
        }
        if (f0()) {
            zOnLayoutDirectionChanged |= this.checkedIcon.setLayoutDirection(i10);
        }
        if (h0()) {
            zOnLayoutDirectionChanged |= this.closeIcon.setLayoutDirection(i10);
        }
        if (!zOnLayoutDirectionChanged) {
            return true;
        }
        invalidateSelf();
        return true;
    }

    @Override // android.graphics.drawable.Drawable
    public final boolean onLevelChange(int i10) {
        boolean zOnLevelChange = super.onLevelChange(i10);
        if (g0()) {
            zOnLevelChange |= this.chipIcon.setLevel(i10);
        }
        if (f0()) {
            zOnLevelChange |= this.checkedIcon.setLevel(i10);
        }
        if (h0()) {
            zOnLevelChange |= this.closeIcon.setLevel(i10);
        }
        if (zOnLevelChange) {
            invalidateSelf();
        }
        return zOnLevelChange;
    }

    @Override // com.google.android.material.shape.k, android.graphics.drawable.Drawable
    public final boolean onStateChange(int[] iArr) {
        if (this.S0) {
            super.onStateChange(iArr);
        }
        return Q(iArr, this.M0);
    }

    @Override // android.graphics.drawable.Drawable.Callback
    public final void scheduleDrawable(Drawable drawable, Runnable runnable, long j10) {
        Drawable.Callback callback = getCallback();
        if (callback != null) {
            callback.scheduleDrawable(this, runnable, j10);
        }
    }

    @Override // com.google.android.material.shape.k, android.graphics.drawable.Drawable
    public final void setAlpha(int i10) {
        if (this.L0 != i10) {
            this.L0 = i10;
            invalidateSelf();
        }
    }

    public void setCheckedIcon(@Nullable Drawable drawable) {
        if (this.checkedIcon != drawable) {
            float fJ = J();
            this.checkedIcon = drawable;
            float fJ2 = J();
            unapplyChildDrawable(this.checkedIcon);
            applyChildDrawable(this.checkedIcon);
            invalidateSelf();
            if (fJ != fJ2) {
                P();
            }
        }
    }

    public void setCheckedIconTint(@Nullable ColorStateList colorStateList) {
        Drawable drawable;
        if (this.checkedIconTint != colorStateList) {
            this.checkedIconTint = colorStateList;
            if (this.f25966n0 && (drawable = this.checkedIcon) != null && this.f25965m0) {
                drawable.setTintList(colorStateList);
            }
            onStateChange(getState());
        }
    }

    public void setChipBackgroundColor(@Nullable ColorStateList colorStateList) {
        if (this.chipBackgroundColor != colorStateList) {
            this.chipBackgroundColor = colorStateList;
            onStateChange(getState());
        }
    }

    public void setChipIcon(@Nullable Drawable drawable) {
        Drawable chipIcon = getChipIcon();
        if (chipIcon != drawable) {
            float fJ = J();
            this.chipIcon = drawable != null ? drawable.mutate() : null;
            float fJ2 = J();
            unapplyChildDrawable(chipIcon);
            if (g0()) {
                applyChildDrawable(this.chipIcon);
            }
            invalidateSelf();
            if (fJ != fJ2) {
                P();
            }
        }
    }

    public void setChipIconTint(@Nullable ColorStateList colorStateList) {
        this.f25962j0 = true;
        if (this.chipIconTint != colorStateList) {
            this.chipIconTint = colorStateList;
            if (g0()) {
                this.chipIcon.setTintList(colorStateList);
            }
            onStateChange(getState());
        }
    }

    public void setChipStrokeColor(@Nullable ColorStateList colorStateList) {
        if (this.chipStrokeColor != colorStateList) {
            this.chipStrokeColor = colorStateList;
            if (this.S0) {
                setStrokeColor(colorStateList);
            }
            onStateChange(getState());
        }
    }

    public void setCloseIcon(@Nullable Drawable drawable) {
        Drawable closeIcon = getCloseIcon();
        if (closeIcon != drawable) {
            float fM = M();
            this.closeIcon = drawable != null ? drawable.mutate() : null;
            this.closeIconRipple = new RippleDrawable(r9.a.sanitizeRippleDrawableColor(getRippleColor()), this.closeIcon, U0);
            float fM2 = M();
            unapplyChildDrawable(closeIcon);
            if (h0()) {
                applyChildDrawable(this.closeIcon);
            }
            invalidateSelf();
            if (fM != fM2) {
                P();
            }
        }
    }

    public void setCloseIconContentDescription(@Nullable CharSequence charSequence) {
        if (this.closeIconContentDescription != charSequence) {
            o0.b bVarC = o0.b.c();
            this.closeIconContentDescription = bVarC.d(charSequence, bVarC.f31264c);
            invalidateSelf();
        }
    }

    public void setCloseIconTint(@Nullable ColorStateList colorStateList) {
        if (this.closeIconTint != colorStateList) {
            this.closeIconTint = colorStateList;
            if (h0()) {
                this.closeIcon.setTintList(colorStateList);
            }
            onStateChange(getState());
        }
    }

    @Override // com.google.android.material.shape.k, android.graphics.drawable.Drawable
    public void setColorFilter(@Nullable ColorFilter colorFilter) {
        if (this.colorFilter != colorFilter) {
            this.colorFilter = colorFilter;
            invalidateSelf();
        }
    }

    public void setDelegate(@Nullable d dVar) {
        this.O0 = new WeakReference(dVar);
    }

    public void setEllipsize(@Nullable TextUtils.TruncateAt truncateAt) {
        this.P0 = truncateAt;
    }

    public void setHideMotionSpec(@Nullable y8.g gVar) {
        this.hideMotionSpec = gVar;
    }

    public void setRippleColor(@Nullable ColorStateList colorStateList) {
        if (this.rippleColor != colorStateList) {
            this.rippleColor = colorStateList;
            i0();
            onStateChange(getState());
        }
    }

    public void setShowMotionSpec(@Nullable y8.g gVar) {
        this.showMotionSpec = gVar;
    }

    public void setText(@Nullable CharSequence charSequence) {
        if (charSequence == null) {
            charSequence = "";
        }
        if (TextUtils.equals(this.text, charSequence)) {
            return;
        }
        this.text = charSequence;
        this.C0.f22796e = true;
        invalidateSelf();
        P();
    }

    public void setTextAppearance(@Nullable q9.g gVar) {
        this.C0.setTextAppearance(gVar, this.f25975w0);
    }

    public void setTextColor(@Nullable ColorStateList colorStateList) {
        q9.g textAppearance = getTextAppearance();
        if (textAppearance != null) {
            textAppearance.setTextColor(colorStateList);
            invalidateSelf();
        }
    }

    @Override // com.google.android.material.shape.k, android.graphics.drawable.Drawable
    public void setTintList(@Nullable ColorStateList colorStateList) {
        if (this.tint != colorStateList) {
            this.tint = colorStateList;
            onStateChange(getState());
        }
    }

    @Override // com.google.android.material.shape.k, android.graphics.drawable.Drawable
    public final void setTintMode(PorterDuff.Mode mode) {
        if (this.tintMode != mode) {
            this.tintMode = mode;
            this.tintFilter = j9.c.updateTintFilter(this, this.tint, mode);
            invalidateSelf();
        }
    }

    @Override // android.graphics.drawable.Drawable
    public final boolean setVisible(boolean z10, boolean z11) {
        boolean visible = super.setVisible(z10, z11);
        if (g0()) {
            visible |= this.chipIcon.setVisible(z10, z11);
        }
        if (f0()) {
            visible |= this.checkedIcon.setVisible(z10, z11);
        }
        if (h0()) {
            visible |= this.closeIcon.setVisible(z10, z11);
        }
        if (visible) {
            invalidateSelf();
        }
        return visible;
    }

    @Override // android.graphics.drawable.Drawable.Callback
    public final void unscheduleDrawable(Drawable drawable, Runnable runnable) {
        Drawable.Callback callback = getCallback();
        if (callback != null) {
            callback.unscheduleDrawable(this, runnable);
        }
    }

    private static boolean isStateful(@Nullable ColorStateList colorStateList) {
        return colorStateList != null && colorStateList.isStateful();
    }

    private static boolean isStateful(@Nullable Drawable drawable) {
        return drawable != null && drawable.isStateful();
    }

    private static boolean isStateful(@Nullable q9.g gVar) {
        return (gVar == null || gVar.getTextColor() == null || !gVar.getTextColor().isStateful()) ? false : true;
    }
}
