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 android.os.Build;
import androidx.core.view.y;
import c1.g;
import c1.k;
import c1.n;
import com.google.android.material.internal.o;
import l0.b;
import z0.c;

/* JADX INFO: compiled from: MaterialButtonHelper.java */
/* JADX INFO: loaded from: classes.dex */
class a {

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    private static final boolean f3728t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    private static final boolean f3729u;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private k f3731b;

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

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

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

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

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

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

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private PorterDuff.Mode f3738i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private ColorStateList f3739j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private ColorStateList f3740k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private ColorStateList f3741l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private Drawable f3742m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    private boolean f3743n = false;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    private boolean f3744o = false;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    private boolean f3745p = false;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    private boolean f3746q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    private LayerDrawable f3747r;

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

    static {
        int i3 = Build.VERSION.SDK_INT;
        f3728t = i3 >= 21;
        f3729u = i3 >= 21 && i3 <= 22;
    }

    a(MaterialButton materialButton, k kVar) {
        this.f3730a = materialButton;
        this.f3731b = kVar;
    }

    private void E(int i3, int i4) {
        int iJ = y.J(this.f3730a);
        int paddingTop = this.f3730a.getPaddingTop();
        int I = y.I(this.f3730a);
        int paddingBottom = this.f3730a.getPaddingBottom();
        int i5 = this.f3734e;
        int i6 = this.f3735f;
        this.f3735f = i4;
        this.f3734e = i3;
        if (!this.f3744o) {
            F();
        }
        y.E0(this.f3730a, iJ, (paddingTop + i3) - i5, I, (paddingBottom + i4) - i6);
    }

    private void F() {
        this.f3730a.setInternalBackground(a());
        g gVarF = f();
        if (gVarF != null) {
            gVarF.W(this.f3748s);
        }
    }

    private void G(k kVar) {
        if (f3729u && !this.f3744o) {
            int iJ = y.J(this.f3730a);
            int paddingTop = this.f3730a.getPaddingTop();
            int I = y.I(this.f3730a);
            int paddingBottom = this.f3730a.getPaddingBottom();
            F();
            y.E0(this.f3730a, iJ, paddingTop, I, paddingBottom);
            return;
        }
        if (f() != null) {
            f().setShapeAppearanceModel(kVar);
        }
        if (n() != null) {
            n().setShapeAppearanceModel(kVar);
        }
        if (e() != null) {
            e().setShapeAppearanceModel(kVar);
        }
    }

    private void I() {
        g gVarF = f();
        g gVarN = n();
        if (gVarF != null) {
            gVarF.d0(this.f3737h, this.f3740k);
            if (gVarN != null) {
                gVarN.c0(this.f3737h, this.f3743n ? r0.a.d(this.f3730a, b.f5328k) : 0);
            }
        }
    }

    private InsetDrawable J(Drawable drawable) {
        return new InsetDrawable(drawable, this.f3732c, this.f3734e, this.f3733d, this.f3735f);
    }

    private Drawable a() {
        g gVar = new g(this.f3731b);
        gVar.N(this.f3730a.getContext());
        androidx.core.graphics.drawable.a.o(gVar, this.f3739j);
        PorterDuff.Mode mode = this.f3738i;
        if (mode != null) {
            androidx.core.graphics.drawable.a.p(gVar, mode);
        }
        gVar.d0(this.f3737h, this.f3740k);
        g gVar2 = new g(this.f3731b);
        gVar2.setTint(0);
        gVar2.c0(this.f3737h, this.f3743n ? r0.a.d(this.f3730a, b.f5328k) : 0);
        if (f3728t) {
            g gVar3 = new g(this.f3731b);
            this.f3742m = gVar3;
            androidx.core.graphics.drawable.a.n(gVar3, -1);
            RippleDrawable rippleDrawable = new RippleDrawable(a1.b.a(this.f3741l), J(new LayerDrawable(new Drawable[]{gVar2, gVar})), this.f3742m);
            this.f3747r = rippleDrawable;
            return rippleDrawable;
        }
        a1.a aVar = new a1.a(this.f3731b);
        this.f3742m = aVar;
        androidx.core.graphics.drawable.a.o(aVar, a1.b.a(this.f3741l));
        LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{gVar2, gVar, this.f3742m});
        this.f3747r = layerDrawable;
        return J(layerDrawable);
    }

    private g g(boolean z2) {
        LayerDrawable layerDrawable = this.f3747r;
        if (layerDrawable == null || layerDrawable.getNumberOfLayers() <= 0) {
            return null;
        }
        return f3728t ? (g) ((LayerDrawable) ((InsetDrawable) this.f3747r.getDrawable(0)).getDrawable()).getDrawable(!z2 ? 1 : 0) : (g) this.f3747r.getDrawable(!z2 ? 1 : 0);
    }

    private g n() {
        return g(true);
    }

    void A(ColorStateList colorStateList) {
        if (this.f3740k != colorStateList) {
            this.f3740k = colorStateList;
            I();
        }
    }

    void B(int i3) {
        if (this.f3737h != i3) {
            this.f3737h = i3;
            I();
        }
    }

    void C(ColorStateList colorStateList) {
        if (this.f3739j != colorStateList) {
            this.f3739j = colorStateList;
            if (f() != null) {
                androidx.core.graphics.drawable.a.o(f(), this.f3739j);
            }
        }
    }

    void D(PorterDuff.Mode mode) {
        if (this.f3738i != mode) {
            this.f3738i = mode;
            if (f() == null || this.f3738i == null) {
                return;
            }
            androidx.core.graphics.drawable.a.p(f(), this.f3738i);
        }
    }

    void H(int i3, int i4) {
        Drawable drawable = this.f3742m;
        if (drawable != null) {
            drawable.setBounds(this.f3732c, this.f3734e, i4 - this.f3733d, i3 - this.f3735f);
        }
    }

    int b() {
        return this.f3736g;
    }

    public int c() {
        return this.f3735f;
    }

    public int d() {
        return this.f3734e;
    }

    public n e() {
        LayerDrawable layerDrawable = this.f3747r;
        if (layerDrawable == null || layerDrawable.getNumberOfLayers() <= 1) {
            return null;
        }
        return this.f3747r.getNumberOfLayers() > 2 ? (n) this.f3747r.getDrawable(2) : (n) this.f3747r.getDrawable(1);
    }

    g f() {
        return g(false);
    }

    ColorStateList h() {
        return this.f3741l;
    }

    k i() {
        return this.f3731b;
    }

    ColorStateList j() {
        return this.f3740k;
    }

    int k() {
        return this.f3737h;
    }

    ColorStateList l() {
        return this.f3739j;
    }

    PorterDuff.Mode m() {
        return this.f3738i;
    }

    boolean o() {
        return this.f3744o;
    }

    boolean p() {
        return this.f3746q;
    }

    void q(TypedArray typedArray) {
        this.f3732c = typedArray.getDimensionPixelOffset(l0.k.X0, 0);
        this.f3733d = typedArray.getDimensionPixelOffset(l0.k.Y0, 0);
        this.f3734e = typedArray.getDimensionPixelOffset(l0.k.Z0, 0);
        this.f3735f = typedArray.getDimensionPixelOffset(l0.k.f5462a1, 0);
        int i3 = l0.k.f5478e1;
        if (typedArray.hasValue(i3)) {
            int dimensionPixelSize = typedArray.getDimensionPixelSize(i3, -1);
            this.f3736g = dimensionPixelSize;
            y(this.f3731b.w(dimensionPixelSize));
            this.f3745p = true;
        }
        this.f3737h = typedArray.getDimensionPixelSize(l0.k.f5515o1, 0);
        this.f3738i = o.f(typedArray.getInt(l0.k.f5474d1, -1), PorterDuff.Mode.SRC_IN);
        this.f3739j = c.a(this.f3730a.getContext(), typedArray, l0.k.f5470c1);
        this.f3740k = c.a(this.f3730a.getContext(), typedArray, l0.k.f5512n1);
        this.f3741l = c.a(this.f3730a.getContext(), typedArray, l0.k.f5509m1);
        this.f3746q = typedArray.getBoolean(l0.k.f5466b1, false);
        this.f3748s = typedArray.getDimensionPixelSize(l0.k.f5482f1, 0);
        int iJ = y.J(this.f3730a);
        int paddingTop = this.f3730a.getPaddingTop();
        int I = y.I(this.f3730a);
        int paddingBottom = this.f3730a.getPaddingBottom();
        if (typedArray.hasValue(l0.k.W0)) {
            s();
        } else {
            F();
        }
        y.E0(this.f3730a, iJ + this.f3732c, paddingTop + this.f3734e, I + this.f3733d, paddingBottom + this.f3735f);
    }

    void r(int i3) {
        if (f() != null) {
            f().setTint(i3);
        }
    }

    void s() {
        this.f3744o = true;
        this.f3730a.setSupportBackgroundTintList(this.f3739j);
        this.f3730a.setSupportBackgroundTintMode(this.f3738i);
    }

    void t(boolean z2) {
        this.f3746q = z2;
    }

    void u(int i3) {
        if (this.f3745p && this.f3736g == i3) {
            return;
        }
        this.f3736g = i3;
        this.f3745p = true;
        y(this.f3731b.w(i3));
    }

    public void v(int i3) {
        E(this.f3734e, i3);
    }

    public void w(int i3) {
        E(i3, this.f3735f);
    }

    void x(ColorStateList colorStateList) {
        if (this.f3741l != colorStateList) {
            this.f3741l = colorStateList;
            boolean z2 = f3728t;
            if (z2 && (this.f3730a.getBackground() instanceof RippleDrawable)) {
                ((RippleDrawable) this.f3730a.getBackground()).setColor(a1.b.a(colorStateList));
            } else {
                if (z2 || !(this.f3730a.getBackground() instanceof a1.a)) {
                    return;
                }
                ((a1.a) this.f3730a.getBackground()).setTintList(a1.b.a(colorStateList));
            }
        }
    }

    void y(k kVar) {
        this.f3731b = kVar;
        G(kVar);
    }

    void z(boolean z2) {
        this.f3743n = z2;
        I();
    }
}
