package com.google.android.material.switchmaterial;

import android.R;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewParent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
import com.google.android.material.internal.q0;
import k9.a;
import x8.c;
import x8.e;
import x8.l;
import x8.m;

/* JADX INFO: loaded from: classes2.dex */
public class SwitchMaterial extends SwitchCompat {

    @Nullable
    private ColorStateList materialThemeColorsThumbTintList;

    @Nullable
    private ColorStateList materialThemeColorsTrackTintList;

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

    /* JADX INFO: renamed from: y0, reason: collision with root package name */
    public boolean f23279y0;
    public static final int z0 = l.Widget_MaterialComponents_CompoundButton_Switch;
    public static final int[][] A0 = {new int[]{R.attr.state_enabled, R.attr.state_checked}, new int[]{R.attr.state_enabled, -16842912}, new int[]{-16842910, R.attr.state_checked}, new int[]{-16842910, -16842912}};

    public SwitchMaterial(@NonNull Context context) {
        this(context, null);
    }

    private ColorStateList getMaterialThemeColorsThumbTintList() {
        if (this.materialThemeColorsThumbTintList == null) {
            int iB = h9.a.b(c.colorSurface, this);
            int iB2 = h9.a.b(d.a.colorControlActivated, this);
            float dimension = getResources().getDimension(e.mtrl_switch_thumb_elevation);
            a aVar = this.f23278x0;
            if (aVar.f29082a) {
                float elevation = 0.0f;
                for (ViewParent parent = getParent(); parent instanceof View; parent = parent.getParent()) {
                    elevation += ((View) parent).getElevation();
                }
                dimension += elevation;
            }
            int iA = aVar.a(dimension, iB);
            this.materialThemeColorsThumbTintList = new ColorStateList(A0, new int[]{h9.a.e(1.0f, iB, iB2), iA, h9.a.e(0.38f, iB, iB2), iA});
        }
        return this.materialThemeColorsThumbTintList;
    }

    private ColorStateList getMaterialThemeColorsTrackTintList() {
        if (this.materialThemeColorsTrackTintList == null) {
            int iB = h9.a.b(c.colorSurface, this);
            int iB2 = h9.a.b(d.a.colorControlActivated, this);
            int iB3 = h9.a.b(c.colorOnSurface, this);
            this.materialThemeColorsTrackTintList = new ColorStateList(A0, new int[]{h9.a.e(0.54f, iB, iB2), h9.a.e(0.32f, iB, iB3), h9.a.e(0.12f, iB, iB2), h9.a.e(0.12f, iB, iB3)});
        }
        return this.materialThemeColorsTrackTintList;
    }

    @Override // android.widget.TextView, android.view.View
    public final void onAttachedToWindow() {
        super.onAttachedToWindow();
        if (this.f23279y0 && getThumbTintList() == null) {
            setThumbTintList(getMaterialThemeColorsThumbTintList());
        }
        if (this.f23279y0 && getTrackTintList() == null) {
            setTrackTintList(getMaterialThemeColorsTrackTintList());
        }
    }

    public void setUseMaterialThemeColors(boolean z10) {
        this.f23279y0 = z10;
        if (z10) {
            setThumbTintList(getMaterialThemeColorsThumbTintList());
            setTrackTintList(getMaterialThemeColorsTrackTintList());
        } else {
            setThumbTintList(null);
            setTrackTintList(null);
        }
    }

    public SwitchMaterial(@NonNull Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, d.a.switchStyle);
    }

    /* JADX WARN: Illegal instructions before constructor call */
    public SwitchMaterial(@NonNull Context context, @Nullable AttributeSet attributeSet, int i10) {
        int i11 = z0;
        super(x9.a.wrap(context, attributeSet, i10, i11), attributeSet, i10);
        Context context2 = getContext();
        this.f23278x0 = new a(context2);
        TypedArray typedArrayC = q0.c(context2, attributeSet, m.SwitchMaterial, i10, i11, new int[0]);
        this.f23279y0 = typedArrayC.getBoolean(m.SwitchMaterial_useMaterialThemeColors, false);
        typedArrayC.recycle();
    }
}
