package com.google.android.material.button;

import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.RippleDrawable;
import androidx.annotation.Nullable;
import com.google.android.material.internal.w0;
import com.google.android.material.shape.g0;
import com.google.android.material.shape.i;
import com.google.android.material.shape.k;
import com.google.android.material.shape.n0;
import com.google.android.material.shape.q;
import com.google.android.material.shape.s;
import e1.n;
import x8.m;

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public s f22375b;

    @Nullable
    private ColorStateList backgroundTint;

    @Nullable
    private PorterDuff.Mode backgroundTintMode;

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

    @Nullable
    private n cornerSpringForce;

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

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

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

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

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

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

    @Nullable
    private Drawable maskDrawable;

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

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

    @Nullable
    private i onCornerSizeChangeListener;

    @Nullable
    private ColorStateList rippleColor;

    @Nullable
    private n0 stateListShapeAppearanceModel;

    @Nullable
    private ColorStateList strokeColor;

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

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public boolean f22384k = false;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public boolean f22386m = true;

    public d(MaterialButton materialButton, s sVar) {
        this.f22374a = materialButton;
        this.f22375b = sVar;
    }

    @Nullable
    private k getMaterialShapeDrawable(boolean z10) {
        RippleDrawable rippleDrawable = this.f22387n;
        if (rippleDrawable == null || rippleDrawable.getNumberOfLayers() <= 0) {
            return null;
        }
        return (k) ((LayerDrawable) ((InsetDrawable) this.f22387n.getDrawable(0)).getDrawable()).getDrawable(!z10 ? 1 : 0);
    }

    @Nullable
    private k getSurfaceColorStrokeDrawable() {
        return getMaterialShapeDrawable(true);
    }

    public final ColorStateList a() {
        return this.backgroundTint;
    }

    public final PorterDuff.Mode b() {
        return this.backgroundTintMode;
    }

    public final void c(TypedArray typedArray) {
        this.f22376c = typedArray.getDimensionPixelOffset(m.MaterialButton_android_insetLeft, 0);
        this.f22377d = typedArray.getDimensionPixelOffset(m.MaterialButton_android_insetRight, 0);
        this.f22378e = typedArray.getDimensionPixelOffset(m.MaterialButton_android_insetTop, 0);
        this.f22379f = typedArray.getDimensionPixelOffset(m.MaterialButton_android_insetBottom, 0);
        int i10 = m.MaterialButton_cornerRadius;
        if (typedArray.hasValue(i10)) {
            int dimensionPixelSize = typedArray.getDimensionPixelSize(i10, -1);
            this.f22380g = dimensionPixelSize;
            q qVarH = this.f22375b.h();
            qVarH.c(dimensionPixelSize);
            f(qVarH.a());
            this.f22384k = true;
        }
        this.f22381h = typedArray.getDimensionPixelSize(m.MaterialButton_strokeWidth, 0);
        this.backgroundTintMode = w0.f(typedArray.getInt(m.MaterialButton_backgroundTintMode, -1), PorterDuff.Mode.SRC_IN);
        MaterialButton materialButton = this.f22374a;
        this.backgroundTint = q9.d.getColorStateList(materialButton.getContext(), typedArray, m.MaterialButton_backgroundTint);
        this.strokeColor = q9.d.getColorStateList(materialButton.getContext(), typedArray, m.MaterialButton_strokeColor);
        this.rippleColor = q9.d.getColorStateList(materialButton.getContext(), typedArray, m.MaterialButton_rippleColor);
        this.f22385l = typedArray.getBoolean(m.MaterialButton_android_checkable, false);
        this.f22388o = typedArray.getDimensionPixelSize(m.MaterialButton_elevation, 0);
        this.f22386m = typedArray.getBoolean(m.MaterialButton_toggleCheckedStateOnClick, true);
        int paddingStart = materialButton.getPaddingStart();
        int paddingTop = materialButton.getPaddingTop();
        int paddingEnd = materialButton.getPaddingEnd();
        int paddingBottom = materialButton.getPaddingBottom();
        if (typedArray.hasValue(m.MaterialButton_android_background)) {
            d();
        } else {
            i();
        }
        materialButton.setPaddingRelative(paddingStart + this.f22376c, paddingTop + this.f22378e, paddingEnd + this.f22377d, paddingBottom + this.f22379f);
    }

    public final void d() {
        this.f22383j = true;
        ColorStateList colorStateList = this.backgroundTint;
        MaterialButton materialButton = this.f22374a;
        materialButton.setSupportBackgroundTintList(colorStateList);
        materialButton.setSupportBackgroundTintMode(this.backgroundTintMode);
    }

    public final void e(n nVar) {
        this.cornerSpringForce = nVar;
        if (this.stateListShapeAppearanceModel != null) {
            j();
        }
    }

    public final void f(s sVar) {
        this.f22375b = sVar;
        this.stateListShapeAppearanceModel = null;
        j();
    }

    public final void g(n0 n0Var) {
        this.stateListShapeAppearanceModel = n0Var;
        j();
    }

    @Nullable
    public n getCornerSpringForce() {
        return this.cornerSpringForce;
    }

    @Nullable
    public g0 getMaskDrawable() {
        RippleDrawable rippleDrawable = this.f22387n;
        if (rippleDrawable == null || rippleDrawable.getNumberOfLayers() <= 1) {
            return null;
        }
        return this.f22387n.getNumberOfLayers() > 2 ? (g0) this.f22387n.getDrawable(2) : (g0) this.f22387n.getDrawable(1);
    }

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

    @Nullable
    public n0 getStateListShapeAppearanceModel() {
        return this.stateListShapeAppearanceModel;
    }

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

    public final void h(int i10, int i11) {
        MaterialButton materialButton = this.f22374a;
        int paddingStart = materialButton.getPaddingStart();
        int paddingTop = materialButton.getPaddingTop();
        int paddingEnd = materialButton.getPaddingEnd();
        int paddingBottom = materialButton.getPaddingBottom();
        int i12 = this.f22378e;
        int i13 = this.f22379f;
        this.f22379f = i11;
        this.f22378e = i10;
        if (!this.f22383j) {
            i();
        }
        materialButton.setPaddingRelative(paddingStart, (paddingTop + i10) - i12, paddingEnd, (paddingBottom + i11) - i13);
    }

    public final void i() {
        k kVar = new k(this.f22375b);
        n0 n0Var = this.stateListShapeAppearanceModel;
        if (n0Var != null) {
            kVar.C(n0Var);
        }
        n nVar = this.cornerSpringForce;
        if (nVar != null) {
            kVar.v(nVar);
        }
        i iVar = this.onCornerSizeChangeListener;
        if (iVar != null) {
            kVar.setOnCornerSizeChangeListener(iVar);
        }
        MaterialButton materialButton = this.f22374a;
        kVar.s(materialButton.getContext());
        kVar.setTintList(this.backgroundTint);
        PorterDuff.Mode mode = this.backgroundTintMode;
        if (mode != null) {
            kVar.setTintMode(mode);
        }
        kVar.setStroke(this.f22381h, this.strokeColor);
        k kVar2 = new k(this.f22375b);
        n0 n0Var2 = this.stateListShapeAppearanceModel;
        if (n0Var2 != null) {
            kVar2.C(n0Var2);
        }
        n nVar2 = this.cornerSpringForce;
        if (nVar2 != null) {
            kVar2.v(nVar2);
        }
        kVar2.setTint(0);
        float f10 = this.f22381h;
        int iB = this.f22382i ? h9.a.b(x8.c.colorSurface, materialButton) : 0;
        kVar2.D(f10);
        kVar2.setStrokeColor(ColorStateList.valueOf(iB));
        k kVar3 = new k(this.f22375b);
        this.maskDrawable = kVar3;
        n0 n0Var3 = this.stateListShapeAppearanceModel;
        if (n0Var3 != null) {
            kVar3.C(n0Var3);
        }
        n nVar3 = this.cornerSpringForce;
        if (nVar3 != null) {
            ((k) this.maskDrawable).v(nVar3);
        }
        this.maskDrawable.setTint(-1);
        RippleDrawable rippleDrawable = new RippleDrawable(r9.a.sanitizeRippleDrawableColor(this.rippleColor), new InsetDrawable((Drawable) new LayerDrawable(new Drawable[]{kVar2, kVar}), this.f22376c, this.f22378e, this.f22377d, this.f22379f), this.maskDrawable);
        this.f22387n = rippleDrawable;
        materialButton.setInternalBackground(rippleDrawable);
        k materialShapeDrawable = getMaterialShapeDrawable();
        if (materialShapeDrawable != null) {
            materialShapeDrawable.w(this.f22388o);
            materialShapeDrawable.setState(materialButton.getDrawableState());
        }
    }

    public final void j() {
        k materialShapeDrawable = getMaterialShapeDrawable();
        if (materialShapeDrawable != null) {
            n0 n0Var = this.stateListShapeAppearanceModel;
            if (n0Var != null) {
                materialShapeDrawable.C(n0Var);
            } else {
                materialShapeDrawable.setShapeAppearanceModel(this.f22375b);
            }
            n nVar = this.cornerSpringForce;
            if (nVar != null) {
                materialShapeDrawable.v(nVar);
            }
        }
        k surfaceColorStrokeDrawable = getSurfaceColorStrokeDrawable();
        if (surfaceColorStrokeDrawable != null) {
            n0 n0Var2 = this.stateListShapeAppearanceModel;
            if (n0Var2 != null) {
                surfaceColorStrokeDrawable.C(n0Var2);
            } else {
                surfaceColorStrokeDrawable.setShapeAppearanceModel(this.f22375b);
            }
            n nVar2 = this.cornerSpringForce;
            if (nVar2 != null) {
                surfaceColorStrokeDrawable.v(nVar2);
            }
        }
        g0 maskDrawable = getMaskDrawable();
        if (maskDrawable != null) {
            maskDrawable.setShapeAppearanceModel(this.f22375b);
            if (maskDrawable instanceof k) {
                k kVar = (k) maskDrawable;
                n0 n0Var3 = this.stateListShapeAppearanceModel;
                if (n0Var3 != null) {
                    kVar.C(n0Var3);
                }
                n nVar3 = this.cornerSpringForce;
                if (nVar3 != null) {
                    kVar.v(nVar3);
                }
            }
        }
    }

    public final void k() {
        int iB;
        k materialShapeDrawable = getMaterialShapeDrawable();
        k surfaceColorStrokeDrawable = getSurfaceColorStrokeDrawable();
        if (materialShapeDrawable != null) {
            materialShapeDrawable.setStroke(this.f22381h, this.strokeColor);
            if (surfaceColorStrokeDrawable != null) {
                float f10 = this.f22381h;
                if (this.f22382i) {
                    iB = h9.a.b(x8.c.colorSurface, this.f22374a);
                } else {
                    iB = 0;
                }
                surfaceColorStrokeDrawable.D(f10);
                surfaceColorStrokeDrawable.setStrokeColor(ColorStateList.valueOf(iB));
            }
        }
    }

    public void setCornerSizeChangeListener(@Nullable i iVar) {
        this.onCornerSizeChangeListener = iVar;
        k materialShapeDrawable = getMaterialShapeDrawable();
        if (materialShapeDrawable != null) {
            materialShapeDrawable.setOnCornerSizeChangeListener(iVar);
        }
    }

    public void setRippleColor(@Nullable ColorStateList colorStateList) {
        if (this.rippleColor != colorStateList) {
            this.rippleColor = colorStateList;
            MaterialButton materialButton = this.f22374a;
            if (materialButton.getBackground() instanceof RippleDrawable) {
                ((RippleDrawable) materialButton.getBackground()).setColor(r9.a.sanitizeRippleDrawableColor(colorStateList));
            }
        }
    }

    public void setStrokeColor(@Nullable ColorStateList colorStateList) {
        if (this.strokeColor != colorStateList) {
            this.strokeColor = colorStateList;
            k();
        }
    }

    public void setSupportBackgroundTintList(@Nullable ColorStateList colorStateList) {
        if (this.backgroundTint != colorStateList) {
            this.backgroundTint = colorStateList;
            if (getMaterialShapeDrawable() != null) {
                getMaterialShapeDrawable().setTintList(this.backgroundTint);
            }
        }
    }

    public void setSupportBackgroundTintMode(@Nullable PorterDuff.Mode mode) {
        if (this.backgroundTintMode != mode) {
            this.backgroundTintMode = mode;
            if (getMaterialShapeDrawable() == null || this.backgroundTintMode == null) {
                return;
            }
            getMaterialShapeDrawable().setTintMode(this.backgroundTintMode);
        }
    }

    @Nullable
    public k getMaterialShapeDrawable() {
        return getMaterialShapeDrawable(false);
    }
}
