package d9;

import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.RippleDrawable;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;
import com.bumptech.glide.f;
import com.bumptech.glide.h;
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.shape.e;
import com.google.android.material.shape.k;
import com.google.android.material.shape.p;
import com.google.android.material.shape.q;
import com.google.android.material.shape.s;
import x8.g;
import x8.m;

/* JADX INFO: loaded from: classes2.dex */
public final class d {

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public static final double f25048o = Math.cos(Math.toRadians(45.0d));

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public static final ColorDrawable f25049p;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final MaterialCardView f25050a;

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

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

    @Nullable
    private Drawable checkedIcon;

    @Nullable
    private ColorStateList checkedIconTint;

    @Nullable
    private LayerDrawable clickableForegroundDrawable;

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

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

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

    @Nullable
    private Drawable fgDrawable;

    @Nullable
    private k foregroundShapeDrawable;

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

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

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

    @Nullable
    private ValueAnimator iconAnimator;

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final TimeInterpolator f25060k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final int f25061l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final int f25062m;

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

    @Nullable
    private ColorStateList rippleColor;

    @Nullable
    private Drawable rippleDrawable;

    @Nullable
    private s shapeAppearanceModel;

    @Nullable
    private ColorStateList strokeColor;

    static {
        f25049p = Build.VERSION.SDK_INT <= 28 ? new ColorDrawable() : null;
    }

    public d(MaterialCardView materialCardView, AttributeSet attributeSet, int i10) {
        int i11 = MaterialCardView.R;
        this.f25051b = new Rect();
        this.f25058i = false;
        this.f25063n = 0.0f;
        this.f25050a = materialCardView;
        k kVar = new k(materialCardView.getContext(), attributeSet, i10, i11);
        this.f25052c = kVar;
        kVar.s(materialCardView.getContext());
        kVar.A();
        q qVarH = kVar.f23095b.f23068a.h();
        TypedArray typedArrayObtainStyledAttributes = materialCardView.getContext().obtainStyledAttributes(attributeSet, r.d.CardView, i10, r.c.CardView);
        int i12 = r.d.CardView_cardCornerRadius;
        if (typedArrayObtainStyledAttributes.hasValue(i12)) {
            qVarH.c(typedArrayObtainStyledAttributes.getDimension(i12, 0.0f));
        }
        this.f25053d = new k();
        n(qVarH.a());
        this.f25060k = f.p(materialCardView.getContext(), x8.c.motionEasingLinearInterpolator, y8.a.f36864a);
        this.f25061l = f.o(materialCardView.getContext(), x8.c.motionDurationShort2, 300);
        this.f25062m = f.o(materialCardView.getContext(), x8.c.motionDurationShort1, 300);
        typedArrayObtainStyledAttributes.recycle();
    }

    public static /* synthetic */ void a(d dVar, ValueAnimator valueAnimator) {
        dVar.getClass();
        float fFloatValue = ((Float) valueAnimator.getAnimatedValue()).floatValue();
        dVar.checkedIcon.setAlpha((int) (255.0f * fFloatValue));
        dVar.f25063n = fFloatValue;
    }

    public static float c(h hVar, float f10) {
        if (hVar instanceof p) {
            return (float) ((1.0d - f25048o) * ((double) f10));
        }
        if (hVar instanceof e) {
            return f10 / 2.0f;
        }
        return 0.0f;
    }

    public final float b() {
        h hVar = this.shapeAppearanceModel.f23151a;
        k kVar = this.f25052c;
        return Math.max(Math.max(c(hVar, kVar.p()), c(this.shapeAppearanceModel.f23152b, kVar.q())), Math.max(c(this.shapeAppearanceModel.f23153c, kVar.k()), c(this.shapeAppearanceModel.f23154d, kVar.j())));
    }

    public final void d() {
        Drawable drawable = this.rippleDrawable;
        if (drawable != null) {
            Rect bounds = drawable.getBounds();
            int i10 = bounds.bottom;
            this.rippleDrawable.setBounds(bounds.left, bounds.top, bounds.right, i10 - 1);
            this.rippleDrawable.setBounds(bounds.left, bounds.top, bounds.right, i10);
        }
    }

    public final LayerDrawable e() {
        if (this.rippleDrawable == null) {
            this.foregroundShapeDrawable = new k(this.shapeAppearanceModel);
            this.rippleDrawable = new RippleDrawable(this.rippleColor, null, this.foregroundShapeDrawable);
        }
        if (this.clickableForegroundDrawable == null) {
            LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{this.rippleDrawable, this.f25053d, this.checkedIcon});
            this.clickableForegroundDrawable = layerDrawable;
            layerDrawable.setId(2, g.mtrl_card_checked_layer_id);
        }
        return this.clickableForegroundDrawable;
    }

    public final s f() {
        return this.shapeAppearanceModel;
    }

    public final int g() {
        ColorStateList colorStateList = this.strokeColor;
        if (colorStateList == null) {
            return -1;
        }
        return colorStateList.getDefaultColor();
    }

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

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

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

    @Nullable
    public ColorStateList getStrokeColorStateList() {
        return this.strokeColor;
    }

    public final c h(Drawable drawable) {
        int iCeil;
        int i10;
        if (this.f25050a.getUseCompatPadding()) {
            int iCeil2 = (int) Math.ceil((r0.getMaxCardElevation() * 1.5f) + (p() ? b() : 0.0f));
            iCeil = (int) Math.ceil(r0.getMaxCardElevation() + (p() ? b() : 0.0f));
            i10 = iCeil2;
        } else {
            iCeil = 0;
            i10 = 0;
        }
        return new c(drawable, iCeil, i10, iCeil, i10);
    }

    public final void i(TypedArray typedArray) {
        MaterialCardView materialCardView = this.f25050a;
        ColorStateList colorStateList = q9.d.getColorStateList(materialCardView.getContext(), typedArray, m.MaterialCardView_strokeColor);
        this.strokeColor = colorStateList;
        if (colorStateList == null) {
            this.strokeColor = ColorStateList.valueOf(-1);
        }
        this.f25057h = typedArray.getDimensionPixelSize(m.MaterialCardView_strokeWidth, 0);
        boolean z10 = typedArray.getBoolean(m.MaterialCardView_android_checkable, false);
        this.f25059j = z10;
        materialCardView.setLongClickable(z10);
        this.checkedIconTint = q9.d.getColorStateList(materialCardView.getContext(), typedArray, m.MaterialCardView_checkedIconTint);
        setCheckedIcon(q9.d.getDrawable(materialCardView.getContext(), typedArray, m.MaterialCardView_checkedIcon));
        this.f25055f = typedArray.getDimensionPixelSize(m.MaterialCardView_checkedIconSize, 0);
        this.f25054e = typedArray.getDimensionPixelSize(m.MaterialCardView_checkedIconMargin, 0);
        this.f25056g = typedArray.getInteger(m.MaterialCardView_checkedIconGravity, 8388661);
        ColorStateList colorStateList2 = q9.d.getColorStateList(materialCardView.getContext(), typedArray, m.MaterialCardView_rippleColor);
        this.rippleColor = colorStateList2;
        if (colorStateList2 == null) {
            this.rippleColor = ColorStateList.valueOf(h9.a.b(d.a.colorControlHighlight, materialCardView));
        }
        setCardForegroundColor(q9.d.getColorStateList(materialCardView.getContext(), typedArray, m.MaterialCardView_cardForegroundColor));
        Drawable drawable = this.rippleDrawable;
        if (drawable != null) {
            ((RippleDrawable) drawable).setColor(this.rippleColor);
        }
        k kVar = this.f25052c;
        kVar.w(materialCardView.getCardElevation());
        u();
        materialCardView.setBackgroundInternal(h(kVar));
        Drawable drawableE = q() ? e() : this.f25053d;
        this.fgDrawable = drawableE;
        materialCardView.setForeground(h(drawableE));
    }

    public final void j(int i10, int i11) {
        int iCeil;
        int iCeil2;
        int i12;
        int i13;
        if (this.clickableForegroundDrawable != null) {
            MaterialCardView materialCardView = this.f25050a;
            if (materialCardView.getUseCompatPadding()) {
                iCeil = (int) Math.ceil(((materialCardView.getMaxCardElevation() * 1.5f) + (p() ? b() : 0.0f)) * 2.0f);
                iCeil2 = (int) Math.ceil((materialCardView.getMaxCardElevation() + (p() ? b() : 0.0f)) * 2.0f);
            } else {
                iCeil = 0;
                iCeil2 = 0;
            }
            int i14 = this.f25056g;
            int i15 = (i14 & 8388613) == 8388613 ? ((i10 - this.f25054e) - this.f25055f) - iCeil2 : this.f25054e;
            int i16 = (i14 & 80) == 80 ? this.f25054e : ((i11 - this.f25054e) - this.f25055f) - iCeil;
            int i17 = (i14 & 8388613) == 8388613 ? this.f25054e : ((i10 - this.f25054e) - this.f25055f) - iCeil2;
            int i18 = (i14 & 80) == 80 ? ((i11 - this.f25054e) - this.f25055f) - iCeil : this.f25054e;
            if (materialCardView.getLayoutDirection() == 1) {
                i13 = i17;
                i12 = i15;
            } else {
                i12 = i17;
                i13 = i15;
            }
            this.clickableForegroundDrawable.setLayerInset(2, i13, i18, i12, i16);
        }
    }

    public final void k(boolean z10, boolean z11) {
        Drawable drawable = this.checkedIcon;
        if (drawable != null) {
            if (!z11) {
                drawable.setAlpha(z10 ? 255 : 0);
                this.f25063n = z10 ? 1.0f : 0.0f;
                return;
            }
            float f10 = z10 ? 1.0f : 0.0f;
            float f11 = z10 ? 1.0f - this.f25063n : this.f25063n;
            ValueAnimator valueAnimator = this.iconAnimator;
            if (valueAnimator != null) {
                valueAnimator.cancel();
                this.iconAnimator = null;
            }
            ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(this.f25063n, f10);
            this.iconAnimator = valueAnimatorOfFloat;
            valueAnimatorOfFloat.addUpdateListener(new b(this, i));
            this.iconAnimator.setInterpolator(this.f25060k);
            this.iconAnimator.setDuration((long) ((z10 ? this.f25061l : this.f25062m) * f11));
            this.iconAnimator.start();
        }
    }

    public final void l(float f10) {
        q qVarH = this.shapeAppearanceModel.h();
        qVarH.c(f10);
        n(qVarH.a());
        this.fgDrawable.invalidateSelf();
        if (p() || (this.f25050a.getPreventCornerOverlap() && !this.f25052c.u())) {
            s();
        }
        if (p()) {
            t();
        }
    }

    public final void m(float f10) {
        this.f25052c.x(f10);
        k kVar = this.f25053d;
        if (kVar != null) {
            kVar.x(f10);
        }
        k kVar2 = this.foregroundShapeDrawable;
        if (kVar2 != null) {
            kVar2.x(f10);
        }
    }

    public final void n(s sVar) {
        this.shapeAppearanceModel = sVar;
        k kVar = this.f25052c;
        kVar.setShapeAppearanceModel(sVar);
        kVar.Y = !kVar.u();
        k kVar2 = this.f25053d;
        if (kVar2 != null) {
            kVar2.setShapeAppearanceModel(sVar);
        }
        k kVar3 = this.foregroundShapeDrawable;
        if (kVar3 != null) {
            kVar3.setShapeAppearanceModel(sVar);
        }
    }

    public final void o(ColorStateList colorStateList) {
        if (this.strokeColor == colorStateList) {
            return;
        }
        this.strokeColor = colorStateList;
        u();
    }

    public final boolean p() {
        MaterialCardView materialCardView = this.f25050a;
        return materialCardView.getPreventCornerOverlap() && this.f25052c.u() && materialCardView.getUseCompatPadding();
    }

    public final boolean q() {
        View view = this.f25050a;
        if (view.isClickable()) {
            return true;
        }
        while (view.isDuplicateParentStateEnabled() && (view.getParent() instanceof View)) {
            view = (View) view.getParent();
        }
        return view.isClickable();
    }

    public final void r() {
        Drawable drawable = this.fgDrawable;
        Drawable drawableE = q() ? e() : this.f25053d;
        this.fgDrawable = drawableE;
        if (drawable != drawableE) {
            MaterialCardView materialCardView = this.f25050a;
            if (materialCardView.getForeground() instanceof InsetDrawable) {
                ((InsetDrawable) materialCardView.getForeground()).setDrawable(drawableE);
            } else {
                materialCardView.setForeground(h(drawableE));
            }
        }
    }

    public final void s() {
        MaterialCardView materialCardView = this.f25050a;
        float cardViewRadius = 0.0f;
        float fB = ((materialCardView.getPreventCornerOverlap() && !this.f25052c.u()) || p()) ? b() : 0.0f;
        if (materialCardView.getPreventCornerOverlap() && materialCardView.getUseCompatPadding()) {
            cardViewRadius = (float) ((1.0d - f25048o) * ((double) materialCardView.getCardViewRadius()));
        }
        int i10 = (int) (fB - cardViewRadius);
        Rect rect = this.f25051b;
        materialCardView.f(rect.left + i10, rect.top + i10, rect.right + i10, rect.bottom + i10);
    }

    public void setCardForegroundColor(@Nullable ColorStateList colorStateList) {
        k kVar = this.f25053d;
        if (colorStateList == null) {
            colorStateList = ColorStateList.valueOf(0);
        }
        kVar.setFillColor(colorStateList);
    }

    public void setCheckedIcon(@Nullable Drawable drawable) {
        if (drawable != null) {
            Drawable drawableMutate = drawable.mutate();
            this.checkedIcon = drawableMutate;
            drawableMutate.setTintList(this.checkedIconTint);
            k(this.f25050a.isChecked(), false);
        } else {
            this.checkedIcon = f25049p;
        }
        LayerDrawable layerDrawable = this.clickableForegroundDrawable;
        if (layerDrawable != null) {
            layerDrawable.setDrawableByLayerId(g.mtrl_card_checked_layer_id, this.checkedIcon);
        }
    }

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

    public void setRippleColor(@Nullable ColorStateList colorStateList) {
        this.rippleColor = colorStateList;
        Drawable drawable = this.rippleDrawable;
        if (drawable != null) {
            ((RippleDrawable) drawable).setColor(colorStateList);
        }
    }

    public final void t() {
        boolean z10 = this.f25058i;
        MaterialCardView materialCardView = this.f25050a;
        if (!z10) {
            materialCardView.setBackgroundInternal(h(this.f25052c));
        }
        materialCardView.setForeground(h(this.fgDrawable));
    }

    public final void u() {
        this.f25053d.setStroke(this.f25057h, this.strokeColor);
    }
}
