package l;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Nullable;

/* JADX INFO: loaded from: classes.dex */
public final class y {

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

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

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f29906c = -1;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final c0 f29905b = c0.a();

    public y(View view) {
        this.f29904a = view;
    }

    public final void a() {
        View view = this.f29904a;
        Drawable background = view.getBackground();
        if (background != null) {
            if (this.f29907d != null) {
                if (this.f29909f == null) {
                    this.f29909f = new n3();
                }
                n3 n3Var = this.f29909f;
                n3Var.f29782a = null;
                n3Var.f29785d = false;
                n3Var.f29783b = null;
                n3Var.f29784c = false;
                ColorStateList backgroundTintList = androidx.core.view.s1.getBackgroundTintList(view);
                if (backgroundTintList != null) {
                    n3Var.f29785d = true;
                    n3Var.f29782a = backgroundTintList;
                }
                PorterDuff.Mode backgroundTintMode = androidx.core.view.s1.getBackgroundTintMode(view);
                if (backgroundTintMode != null) {
                    n3Var.f29784c = true;
                    n3Var.f29783b = backgroundTintMode;
                }
                if (n3Var.f29785d || n3Var.f29784c) {
                    c0.e(background, n3Var, view.getDrawableState());
                    return;
                }
            }
            n3 n3Var2 = this.f29908e;
            if (n3Var2 != null) {
                c0.e(background, n3Var2, view.getDrawableState());
                return;
            }
            n3 n3Var3 = this.f29907d;
            if (n3Var3 != null) {
                c0.e(background, n3Var3, view.getDrawableState());
            }
        }
    }

    public final ColorStateList b() {
        n3 n3Var = this.f29908e;
        if (n3Var != null) {
            return n3Var.f29782a;
        }
        return null;
    }

    public final PorterDuff.Mode c() {
        n3 n3Var = this.f29908e;
        if (n3Var != null) {
            return n3Var.f29783b;
        }
        return null;
    }

    public final void d() {
        this.f29906c = -1;
        f(null);
        a();
    }

    public final void e(int i10) {
        ColorStateList colorStateListH;
        this.f29906c = i10;
        c0 c0Var = this.f29905b;
        if (c0Var != null) {
            Context context = this.f29904a.getContext();
            synchronized (c0Var) {
                colorStateListH = c0Var.f29657a.h(context, i10);
            }
        } else {
            colorStateListH = null;
        }
        f(colorStateListH);
        a();
    }

    public final void f(ColorStateList colorStateList) {
        if (colorStateList != null) {
            if (this.f29907d == null) {
                this.f29907d = new n3();
            }
            n3 n3Var = this.f29907d;
            n3Var.f29782a = colorStateList;
            n3Var.f29785d = true;
        } else {
            this.f29907d = null;
        }
        a();
    }

    public final void g(ColorStateList colorStateList) {
        if (this.f29908e == null) {
            this.f29908e = new n3();
        }
        n3 n3Var = this.f29908e;
        n3Var.f29782a = colorStateList;
        n3Var.f29785d = true;
        a();
    }

    public final void h(PorterDuff.Mode mode) {
        if (this.f29908e == null) {
            this.f29908e = new n3();
        }
        n3 n3Var = this.f29908e;
        n3Var.f29783b = mode;
        n3Var.f29784c = true;
        a();
    }

    public void loadFromAttributes(@Nullable AttributeSet attributeSet, int i10) {
        ColorStateList colorStateListH;
        View view = this.f29904a;
        Context context = view.getContext();
        int[] iArr = d.j.ViewBackgroundHelper;
        p3 p3VarD = p3.d(context, attributeSet, iArr, i10);
        TypedArray typedArray = p3VarD.f29809b;
        View view2 = this.f29904a;
        androidx.core.view.s1.saveAttributeDataForStyleable(view2, view2.getContext(), iArr, attributeSet, p3VarD.f29809b, i10, 0);
        try {
            int i11 = d.j.ViewBackgroundHelper_android_background;
            if (typedArray.hasValue(i11)) {
                this.f29906c = typedArray.getResourceId(i11, -1);
                c0 c0Var = this.f29905b;
                Context context2 = view.getContext();
                int i12 = this.f29906c;
                synchronized (c0Var) {
                    colorStateListH = c0Var.f29657a.h(context2, i12);
                }
                if (colorStateListH != null) {
                    f(colorStateListH);
                }
            }
            int i13 = d.j.ViewBackgroundHelper_backgroundTint;
            if (typedArray.hasValue(i13)) {
                androidx.core.view.s1.setBackgroundTintList(view, p3VarD.a(i13));
            }
            int i14 = d.j.ViewBackgroundHelper_backgroundTintMode;
            if (typedArray.hasValue(i14)) {
                androidx.core.view.s1.setBackgroundTintMode(view, p1.c(typedArray.getInt(i14, -1), null));
            }
            p3VarD.e();
        } catch (Throwable th) {
            p3VarD.e();
            throw th;
        }
    }
}
