package com.google.android.material.textfield;

import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;
import com.google.android.gms.measurement.internal.u1;
import com.google.android.material.internal.CheckableImageButton;
import com.google.android.material.internal.w0;
import java.util.Iterator;
import java.util.LinkedHashSet;
import l.p3;

/* JADX INFO: loaded from: classes2.dex */
public final class o extends LinearLayout {
    public static final /* synthetic */ int W = 0;
    public ImageView.ScaleType Q;
    public View.OnLongClickListener R;
    public final AppCompatTextView S;
    public boolean T;
    public EditText U;
    public final m V;

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

    @Nullable
    private final AccessibilityManager accessibilityManager;

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

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public PorterDuff.Mode f23430e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public View.OnLongClickListener f23431f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final CheckableImageButton f23432g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final androidx.activity.result.k f23433h;

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final LinkedHashSet f23435j;

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public PorterDuff.Mode f23437l;

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

    @Nullable
    private CharSequence suffixText;

    @Nullable
    private AccessibilityManager.TouchExplorationStateChangeListener touchExplorationStateChangeListener;

    public o(TextInputLayout textInputLayout, p3 p3Var) {
        super(textInputLayout.getContext());
        this.f23434i = 0;
        this.f23435j = new LinkedHashSet();
        this.V = new m(this);
        n nVar = new n(this);
        this.accessibilityManager = (AccessibilityManager) getContext().getSystemService("accessibility");
        this.f23426a = textInputLayout;
        setVisibility(8);
        setOrientation(0);
        setLayoutParams(new FrameLayout.LayoutParams(-2, -1, 8388613));
        FrameLayout frameLayout = new FrameLayout(getContext());
        this.f23427b = frameLayout;
        frameLayout.setVisibility(8);
        frameLayout.setLayoutParams(new LinearLayout.LayoutParams(-2, -1));
        LayoutInflater layoutInflaterFrom = LayoutInflater.from(getContext());
        CheckableImageButton checkableImageButtonB = b(x8.g.text_input_error_icon, layoutInflaterFrom, this);
        this.f23428c = checkableImageButtonB;
        CheckableImageButton checkableImageButtonB2 = b(x8.g.text_input_end_icon, layoutInflaterFrom, frameLayout);
        this.f23432g = checkableImageButtonB2;
        this.f23433h = new androidx.activity.result.k(this, p3Var);
        AppCompatTextView appCompatTextView = new AppCompatTextView(getContext());
        this.S = appCompatTextView;
        int i10 = x8.m.TextInputLayout_errorIconTint;
        TypedArray typedArray = p3Var.f29809b;
        if (typedArray.hasValue(i10)) {
            this.f23429d = q9.d.getColorStateList(getContext(), p3Var, i10);
        }
        int i11 = x8.m.TextInputLayout_errorIconTintMode;
        if (typedArray.hasValue(i11)) {
            this.f23430e = w0.f(typedArray.getInt(i11, -1), null);
        }
        int i12 = x8.m.TextInputLayout_errorIconDrawable;
        if (typedArray.hasValue(i12)) {
            setErrorIconDrawable(p3Var.b(i12));
        }
        checkableImageButtonB.setContentDescription(getResources().getText(x8.k.error_icon_content_description));
        checkableImageButtonB.setImportantForAccessibility(2);
        checkableImageButtonB.setClickable(false);
        checkableImageButtonB.setPressable(false);
        checkableImageButtonB.setCheckable(false);
        checkableImageButtonB.setFocusable(false);
        int i13 = x8.m.TextInputLayout_passwordToggleEnabled;
        if (!typedArray.hasValue(i13)) {
            int i14 = x8.m.TextInputLayout_endIconTint;
            if (typedArray.hasValue(i14)) {
                this.f23436k = q9.d.getColorStateList(getContext(), p3Var, i14);
            }
            int i15 = x8.m.TextInputLayout_endIconTintMode;
            if (typedArray.hasValue(i15)) {
                this.f23437l = w0.f(typedArray.getInt(i15, -1), null);
            }
        }
        int i16 = x8.m.TextInputLayout_endIconMode;
        if (typedArray.hasValue(i16)) {
            i(typedArray.getInt(i16, 0));
            int i17 = x8.m.TextInputLayout_endIconContentDescription;
            if (typedArray.hasValue(i17)) {
                setEndIconContentDescription(typedArray.getText(i17));
            }
            checkableImageButtonB2.setCheckable(typedArray.getBoolean(x8.m.TextInputLayout_endIconCheckable, true));
        } else if (typedArray.hasValue(i13)) {
            int i18 = x8.m.TextInputLayout_passwordToggleTint;
            if (typedArray.hasValue(i18)) {
                this.f23436k = q9.d.getColorStateList(getContext(), p3Var, i18);
            }
            int i19 = x8.m.TextInputLayout_passwordToggleTintMode;
            if (typedArray.hasValue(i19)) {
                this.f23437l = w0.f(typedArray.getInt(i19, -1), null);
            }
            i(typedArray.getBoolean(i13, false) ? 1 : 0);
            setEndIconContentDescription(typedArray.getText(x8.m.TextInputLayout_passwordToggleContentDescription));
        }
        int dimensionPixelSize = typedArray.getDimensionPixelSize(x8.m.TextInputLayout_endIconMinSize, getResources().getDimensionPixelSize(x8.e.mtrl_min_touch_target_size));
        if (dimensionPixelSize < 0) {
            throw new IllegalArgumentException("endIconSize cannot be less than 0");
        }
        if (dimensionPixelSize != this.f23438m) {
            this.f23438m = dimensionPixelSize;
            checkableImageButtonB2.setMinimumWidth(dimensionPixelSize);
            checkableImageButtonB2.setMinimumHeight(dimensionPixelSize);
            checkableImageButtonB.setMinimumWidth(dimensionPixelSize);
            checkableImageButtonB.setMinimumHeight(dimensionPixelSize);
        }
        int i20 = x8.m.TextInputLayout_endIconScaleType;
        if (typedArray.hasValue(i20)) {
            ImageView.ScaleType scaleTypeB = q.b(typedArray.getInt(i20, -1));
            this.Q = scaleTypeB;
            checkableImageButtonB2.setScaleType(scaleTypeB);
            checkableImageButtonB.setScaleType(scaleTypeB);
        }
        appCompatTextView.setVisibility(8);
        appCompatTextView.setId(x8.g.textinput_suffix_text);
        appCompatTextView.setLayoutParams(new LinearLayout.LayoutParams(-2, -2, 80.0f));
        appCompatTextView.setAccessibilityLiveRegion(1);
        appCompatTextView.setTextAppearance(typedArray.getResourceId(x8.m.TextInputLayout_suffixTextAppearance, 0));
        int i21 = x8.m.TextInputLayout_suffixTextColor;
        if (typedArray.hasValue(i21)) {
            appCompatTextView.setTextColor(p3Var.a(i21));
        }
        setSuffixText(typedArray.getText(x8.m.TextInputLayout_suffixText));
        frameLayout.addView(checkableImageButtonB2);
        addView(appCompatTextView);
        addView(frameLayout);
        addView(checkableImageButtonB);
        textInputLayout.f23387w0.add(nVar);
        if (textInputLayout.f23360e != null) {
            nVar.a(textInputLayout);
        }
        addOnAttachStateChangeListener(new k.g(this, 4));
    }

    public final void a() {
        if (this.touchExplorationStateChangeListener == null || this.accessibilityManager == null || !isAttachedToWindow()) {
            return;
        }
        this.accessibilityManager.addTouchExplorationStateChangeListener(this.touchExplorationStateChangeListener);
    }

    public final CheckableImageButton b(int i10, LayoutInflater layoutInflater, ViewGroup viewGroup) {
        CheckableImageButton checkableImageButton = (CheckableImageButton) layoutInflater.inflate(x8.i.design_text_input_end_icon, viewGroup, false);
        checkableImageButton.setId(i10);
        if (q9.d.c(getContext())) {
            ((ViewGroup.MarginLayoutParams) checkableImageButton.getLayoutParams()).setMarginStart(0);
        }
        return checkableImageButton;
    }

    public final p c() {
        int i10 = this.f23434i;
        androidx.activity.result.k kVar = this.f23433h;
        SparseArray sparseArray = (SparseArray) kVar.f528c;
        p fVar = (p) sparseArray.get(i10);
        if (fVar == null) {
            if (i10 != -1) {
                int i11 = 1;
                if (i10 == 0) {
                    fVar = new f((o) kVar.f529d, i11);
                } else if (i10 == 1) {
                    fVar = new u((o) kVar.f529d, kVar.f527b);
                } else if (i10 == 2) {
                    fVar = new e((o) kVar.f529d);
                } else {
                    if (i10 != 3) {
                        throw new IllegalArgumentException(u1.g("Invalid end icon mode: ", i10));
                    }
                    fVar = new l((o) kVar.f529d);
                }
            } else {
                fVar = new f((o) kVar.f529d, 0);
            }
            sparseArray.append(i10, fVar);
        }
        return fVar;
    }

    public final int d() {
        int marginStart;
        if (e() || f()) {
            CheckableImageButton checkableImageButton = this.f23432g;
            marginStart = ((ViewGroup.MarginLayoutParams) checkableImageButton.getLayoutParams()).getMarginStart() + checkableImageButton.getMeasuredWidth();
        } else {
            marginStart = 0;
        }
        return this.S.getPaddingEnd() + getPaddingEnd() + marginStart;
    }

    public final boolean e() {
        return this.f23427b.getVisibility() == 0 && this.f23432g.getVisibility() == 0;
    }

    public final boolean f() {
        return this.f23428c.getVisibility() == 0;
    }

    public final void g(boolean z10) {
        boolean z11;
        boolean zIsActivated;
        boolean zIsChecked;
        p pVarC = c();
        boolean zK = pVarC.k();
        CheckableImageButton checkableImageButton = this.f23432g;
        boolean z12 = true;
        if (!zK || (zIsChecked = checkableImageButton.isChecked()) == pVarC.l()) {
            z11 = false;
        } else {
            checkableImageButton.setChecked(!zIsChecked);
            z11 = true;
        }
        if (!(pVarC instanceof l) || (zIsActivated = checkableImageButton.isActivated()) == pVarC.j()) {
            z12 = z11;
        } else {
            checkableImageButton.setActivated(!zIsActivated);
        }
        if (z10 || z12) {
            q.c(this.f23426a, checkableImageButton, this.f23436k);
        }
    }

    @Nullable
    public CheckableImageButton getCurrentEndIconView() {
        if (f()) {
            return this.f23428c;
        }
        if (this.f23434i == 0 || !e()) {
            return null;
        }
        return this.f23432g;
    }

    @Nullable
    public CharSequence getEndIconContentDescription() {
        return this.f23432g.getContentDescription();
    }

    @Nullable
    public Drawable getEndIconDrawable() {
        return this.f23432g.getDrawable();
    }

    @Nullable
    public CharSequence getPasswordVisibilityToggleContentDescription() {
        return this.f23432g.getContentDescription();
    }

    @Nullable
    public Drawable getPasswordVisibilityToggleDrawable() {
        return this.f23432g.getDrawable();
    }

    @Nullable
    public CharSequence getSuffixText() {
        return this.suffixText;
    }

    @Nullable
    public ColorStateList getSuffixTextColor() {
        return this.S.getTextColors();
    }

    public final void h() {
        AccessibilityManager accessibilityManager;
        AccessibilityManager.TouchExplorationStateChangeListener touchExplorationStateChangeListener = this.touchExplorationStateChangeListener;
        if (touchExplorationStateChangeListener == null || (accessibilityManager = this.accessibilityManager) == null) {
            return;
        }
        accessibilityManager.removeTouchExplorationStateChangeListener(touchExplorationStateChangeListener);
    }

    public final void i(int i10) {
        if (this.f23434i == i10) {
            return;
        }
        p pVarC = c();
        h();
        this.touchExplorationStateChangeListener = null;
        pVarC.r();
        this.f23434i = i10;
        Iterator it = this.f23435j.iterator();
        if (it.hasNext()) {
            u1.x(it.next());
            throw null;
        }
        j(i10 != 0);
        p pVarC2 = c();
        int iD = this.f23433h.f526a;
        if (iD == 0) {
            iD = pVarC2.d();
        }
        setEndIconDrawable(iD != 0 ? f.a.getDrawable(getContext(), iD) : null);
        int iC = pVarC2.c();
        setEndIconContentDescription(iC != 0 ? getResources().getText(iC) : null);
        boolean zK = pVarC2.k();
        CheckableImageButton checkableImageButton = this.f23432g;
        checkableImageButton.setCheckable(zK);
        TextInputLayout textInputLayout = this.f23426a;
        if (!pVarC2.i(textInputLayout.getBoxBackgroundMode())) {
            throw new IllegalStateException("The current box background mode " + textInputLayout.getBoxBackgroundMode() + " is not supported by the end icon mode " + i10);
        }
        pVarC2.q();
        this.touchExplorationStateChangeListener = pVarC2.h();
        a();
        setEndIconOnClickListener(pVarC2.f());
        EditText editText = this.U;
        if (editText != null) {
            pVarC2.onEditTextAttached(editText);
            k(pVarC2);
        }
        q.a(textInputLayout, checkableImageButton, this.f23436k, this.f23437l);
        g(true);
    }

    public final void j(boolean z10) {
        if (e() != z10) {
            this.f23432g.setVisibility(z10 ? 0 : 8);
            l();
            n();
            this.f23426a.r();
        }
    }

    public final void k(p pVar) {
        if (this.U == null) {
            return;
        }
        if (pVar.e() != null) {
            this.U.setOnFocusChangeListener(pVar.e());
        }
        if (pVar.g() != null) {
            this.f23432g.setOnFocusChangeListener(pVar.g());
        }
    }

    public final void l() {
        this.f23427b.setVisibility((this.f23432g.getVisibility() != 0 || f()) ? 8 : 0);
        setVisibility((e() || f() || ((this.suffixText == null || this.T) ? '\b' : (char) 0) == 0) ? 0 : 8);
    }

    /* JADX WARN: Removed duplicated region for block: B:9:0x0018  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void m() {
        int i10;
        CheckableImageButton checkableImageButton = this.f23428c;
        Drawable drawable = checkableImageButton.getDrawable();
        TextInputLayout textInputLayout = this.f23426a;
        if (drawable != null) {
            s sVar = textInputLayout.f23372k;
            i10 = (sVar.f23462o && sVar.f()) ? 0 : 8;
        }
        checkableImageButton.setVisibility(i10);
        l();
        n();
        if (this.f23434i != 0) {
            return;
        }
        textInputLayout.r();
    }

    public final void n() {
        TextInputLayout textInputLayout = this.f23426a;
        if (textInputLayout.f23360e == null) {
            return;
        }
        this.S.setPaddingRelative(getContext().getResources().getDimensionPixelSize(x8.e.material_input_text_to_prefix_suffix_padding), textInputLayout.f23360e.getPaddingTop(), (e() || f()) ? 0 : textInputLayout.f23360e.getPaddingEnd(), textInputLayout.f23360e.getPaddingBottom());
    }

    public final void o() {
        AppCompatTextView appCompatTextView = this.S;
        int visibility = appCompatTextView.getVisibility();
        int i10 = (this.suffixText == null || this.T) ? 8 : 0;
        if (visibility != i10) {
            c().o(i10 == 0);
        }
        l();
        appCompatTextView.setVisibility(i10);
        this.f23426a.r();
    }

    public void setEndIconContentDescription(@Nullable CharSequence charSequence) {
        if (getEndIconContentDescription() != charSequence) {
            this.f23432g.setContentDescription(charSequence);
        }
    }

    public void setEndIconDrawable(@Nullable Drawable drawable) {
        CheckableImageButton checkableImageButton = this.f23432g;
        checkableImageButton.setImageDrawable(drawable);
        if (drawable != null) {
            ColorStateList colorStateList = this.f23436k;
            PorterDuff.Mode mode = this.f23437l;
            TextInputLayout textInputLayout = this.f23426a;
            q.a(textInputLayout, checkableImageButton, colorStateList, mode);
            q.c(textInputLayout, checkableImageButton, this.f23436k);
        }
    }

    public void setEndIconOnClickListener(@Nullable View.OnClickListener onClickListener) {
        q.setIconOnClickListener(this.f23432g, onClickListener, this.R);
    }

    public void setEndIconOnLongClickListener(@Nullable View.OnLongClickListener onLongClickListener) {
        this.R = onLongClickListener;
        q.setIconOnLongClickListener(this.f23432g, onLongClickListener);
    }

    public void setEndIconTintList(@Nullable ColorStateList colorStateList) {
        if (this.f23436k != colorStateList) {
            this.f23436k = colorStateList;
            q.a(this.f23426a, this.f23432g, colorStateList, this.f23437l);
        }
    }

    public void setEndIconTintMode(@Nullable PorterDuff.Mode mode) {
        if (this.f23437l != mode) {
            this.f23437l = mode;
            q.a(this.f23426a, this.f23432g, this.f23436k, mode);
        }
    }

    public void setErrorIconDrawable(@Nullable Drawable drawable) {
        CheckableImageButton checkableImageButton = this.f23428c;
        checkableImageButton.setImageDrawable(drawable);
        m();
        q.a(this.f23426a, checkableImageButton, this.f23429d, this.f23430e);
    }

    public void setErrorIconOnClickListener(@Nullable View.OnClickListener onClickListener) {
        q.setIconOnClickListener(this.f23428c, onClickListener, this.f23431f);
    }

    public void setErrorIconOnLongClickListener(@Nullable View.OnLongClickListener onLongClickListener) {
        this.f23431f = onLongClickListener;
        q.setIconOnLongClickListener(this.f23428c, onLongClickListener);
    }

    public void setErrorIconTintList(@Nullable ColorStateList colorStateList) {
        if (this.f23429d != colorStateList) {
            this.f23429d = colorStateList;
            q.a(this.f23426a, this.f23428c, colorStateList, this.f23430e);
        }
    }

    public void setErrorIconTintMode(@Nullable PorterDuff.Mode mode) {
        if (this.f23430e != mode) {
            this.f23430e = mode;
            q.a(this.f23426a, this.f23428c, this.f23429d, mode);
        }
    }

    public void setPasswordVisibilityToggleContentDescription(@Nullable CharSequence charSequence) {
        this.f23432g.setContentDescription(charSequence);
    }

    public void setPasswordVisibilityToggleDrawable(@Nullable Drawable drawable) {
        this.f23432g.setImageDrawable(drawable);
    }

    public void setPasswordVisibilityToggleTintList(@Nullable ColorStateList colorStateList) {
        this.f23436k = colorStateList;
        q.a(this.f23426a, this.f23432g, colorStateList, this.f23437l);
    }

    public void setPasswordVisibilityToggleTintMode(@Nullable PorterDuff.Mode mode) {
        this.f23437l = mode;
        q.a(this.f23426a, this.f23432g, this.f23436k, mode);
    }

    public void setSuffixText(@Nullable CharSequence charSequence) {
        this.suffixText = TextUtils.isEmpty(charSequence) ? null : charSequence;
        this.S.setText(charSequence);
        o();
    }
}
