package o;

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 com.google.android.gms.common.R;
import com.google.android.material.internal.CheckableImageButton;
import com.google.android.material.textfield.TextInputLayout;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.WeakHashMap;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.cw, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C0957cw extends LinearLayout {
    public CharSequence A;
    public final E8 B;
    public boolean C;
    public EditText D;
    public final AccessibilityManager E;
    public G1 F;
    public final C0670Zv G;
    public final TextInputLayout l;
    public final FrameLayout m;
    public final CheckableImageButton n;

    /* renamed from: o, reason: collision with root package name */
    public ColorStateList f482o;
    public PorterDuff.Mode p;
    public View.OnLongClickListener q;
    public final CheckableImageButton r;
    public final C0862bw s;
    public int t;
    public final LinkedHashSet u;
    public ColorStateList v;
    public PorterDuff.Mode w;
    public int x;
    public ImageView.ScaleType y;
    public View.OnLongClickListener z;

    public C0957cw(TextInputLayout textInputLayout, C70 c70) {
        CharSequence text;
        super(textInputLayout.getContext());
        this.t = 0;
        this.u = new LinkedHashSet();
        this.G = new C0670Zv(this);
        C0766aw c0766aw = new C0766aw(this);
        this.E = (AccessibilityManager) getContext().getSystemService("accessibility");
        this.l = textInputLayout;
        setVisibility(8);
        setOrientation(0);
        setLayoutParams(new FrameLayout.LayoutParams(-2, -1, 8388613));
        FrameLayout frameLayout = new FrameLayout(getContext());
        this.m = frameLayout;
        frameLayout.setVisibility(8);
        frameLayout.setLayoutParams(new LinearLayout.LayoutParams(-2, -1));
        LayoutInflater layoutInflaterFrom = LayoutInflater.from(getContext());
        CheckableImageButton checkableImageButtonA = a(this, layoutInflaterFrom, R.id.text_input_error_icon);
        this.n = checkableImageButtonA;
        CheckableImageButton checkableImageButtonA2 = a(frameLayout, layoutInflaterFrom, R.id.text_input_end_icon);
        this.r = checkableImageButtonA2;
        this.s = new C0862bw(this, c70);
        E8 e8 = new E8(getContext(), null);
        this.B = e8;
        TypedArray typedArray = (TypedArray) c70.n;
        if (typedArray.hasValue(38)) {
            this.f482o = AbstractC2461sm0.r(getContext(), c70, 38);
        }
        if (typedArray.hasValue(39)) {
            this.p = Co0.J(typedArray.getInt(39, -1), null);
        }
        if (typedArray.hasValue(37)) {
            i(c70.m(37));
        }
        checkableImageButtonA.setContentDescription(getResources().getText(R.string.error_icon_content_description));
        WeakHashMap weakHashMap = Oj0.a;
        checkableImageButtonA.setImportantForAccessibility(2);
        checkableImageButtonA.setClickable(false);
        checkableImageButtonA.setPressable(false);
        checkableImageButtonA.setFocusable(false);
        if (!typedArray.hasValue(53)) {
            if (typedArray.hasValue(32)) {
                this.v = AbstractC2461sm0.r(getContext(), c70, 32);
            }
            if (typedArray.hasValue(33)) {
                this.w = Co0.J(typedArray.getInt(33, -1), null);
            }
        }
        if (typedArray.hasValue(30)) {
            g(typedArray.getInt(30, 0));
            if (typedArray.hasValue(27) && checkableImageButtonA2.getContentDescription() != (text = typedArray.getText(27))) {
                checkableImageButtonA2.setContentDescription(text);
            }
            checkableImageButtonA2.setCheckable(typedArray.getBoolean(26, true));
        } else if (typedArray.hasValue(53)) {
            if (typedArray.hasValue(54)) {
                this.v = AbstractC2461sm0.r(getContext(), c70, 54);
            }
            if (typedArray.hasValue(55)) {
                this.w = Co0.J(typedArray.getInt(55, -1), null);
            }
            g(typedArray.getBoolean(53, false) ? 1 : 0);
            CharSequence text2 = typedArray.getText(51);
            if (checkableImageButtonA2.getContentDescription() != text2) {
                checkableImageButtonA2.setContentDescription(text2);
            }
        }
        int dimensionPixelSize = typedArray.getDimensionPixelSize(29, getResources().getDimensionPixelSize(R.dimen.mtrl_min_touch_target_size));
        if (dimensionPixelSize < 0) {
            throw new IllegalArgumentException("endIconSize cannot be less than 0");
        }
        if (dimensionPixelSize != this.x) {
            this.x = dimensionPixelSize;
            checkableImageButtonA2.setMinimumWidth(dimensionPixelSize);
            checkableImageButtonA2.setMinimumHeight(dimensionPixelSize);
            checkableImageButtonA.setMinimumWidth(dimensionPixelSize);
            checkableImageButtonA.setMinimumHeight(dimensionPixelSize);
        }
        if (typedArray.hasValue(31)) {
            ImageView.ScaleType scaleTypeH = IJ.h(typedArray.getInt(31, -1));
            this.y = scaleTypeH;
            checkableImageButtonA2.setScaleType(scaleTypeH);
            checkableImageButtonA.setScaleType(scaleTypeH);
        }
        e8.setVisibility(8);
        e8.setId(R.id.textinput_suffix_text);
        e8.setLayoutParams(new LinearLayout.LayoutParams(-2, -2, 80.0f));
        e8.setAccessibilityLiveRegion(1);
        e8.setTextAppearance(typedArray.getResourceId(72, 0));
        if (typedArray.hasValue(73)) {
            e8.setTextColor(c70.l(73));
        }
        CharSequence text3 = typedArray.getText(71);
        this.A = TextUtils.isEmpty(text3) ? null : text3;
        e8.setText(text3);
        n();
        frameLayout.addView(checkableImageButtonA2);
        addView(e8);
        addView(frameLayout);
        addView(checkableImageButtonA);
        textInputLayout.p0.add(c0766aw);
        if (textInputLayout.f30o != null) {
            c0766aw.a(textInputLayout);
        }
        addOnAttachStateChangeListener(new ViewOnAttachStateChangeListenerC2491t3(3, this));
    }

    public final CheckableImageButton a(ViewGroup viewGroup, LayoutInflater layoutInflater, int i) {
        CheckableImageButton checkableImageButton = (CheckableImageButton) layoutInflater.inflate(R.layout.design_text_input_end_icon, viewGroup, false);
        checkableImageButton.setId(i);
        if (AbstractC2461sm0.B(getContext())) {
            ((ViewGroup.MarginLayoutParams) checkableImageButton.getLayoutParams()).setMarginStart(0);
        }
        return checkableImageButton;
    }

    public final AbstractC1052dw b() {
        AbstractC1052dw c0300Lo;
        int i = this.t;
        C0862bw c0862bw = this.s;
        SparseArray sparseArray = (SparseArray) c0862bw.d;
        AbstractC1052dw abstractC1052dw = (AbstractC1052dw) sparseArray.get(i);
        if (abstractC1052dw != null) {
            return abstractC1052dw;
        }
        C0957cw c0957cw = (C0957cw) c0862bw.e;
        if (i == -1) {
            c0300Lo = new C0300Lo(c0957cw, 0);
        } else if (i == 0) {
            c0300Lo = new C0300Lo(c0957cw, 1);
        } else if (i == 1) {
            c0300Lo = new QV(c0957cw, c0862bw.c);
        } else if (i == 2) {
            c0300Lo = new C0738ai(c0957cw);
        } else {
            if (i != 3) {
                throw new IllegalArgumentException(AbstractC0126Ew.j(i, "Invalid end icon mode: "));
            }
            c0300Lo = new C0253Jt(c0957cw);
        }
        sparseArray.append(i, c0300Lo);
        return c0300Lo;
    }

    public final int c() {
        int marginStart;
        if (d() || e()) {
            CheckableImageButton checkableImageButton = this.r;
            marginStart = ((ViewGroup.MarginLayoutParams) checkableImageButton.getLayoutParams()).getMarginStart() + checkableImageButton.getMeasuredWidth();
        } else {
            marginStart = 0;
        }
        WeakHashMap weakHashMap = Oj0.a;
        return this.B.getPaddingEnd() + getPaddingEnd() + marginStart;
    }

    public final boolean d() {
        return this.m.getVisibility() == 0 && this.r.getVisibility() == 0;
    }

    public final boolean e() {
        return this.n.getVisibility() == 0;
    }

    public final void f(boolean z) {
        boolean z2;
        boolean zIsActivated;
        boolean z3;
        AbstractC1052dw abstractC1052dwB = b();
        boolean zJ = abstractC1052dwB.j();
        CheckableImageButton checkableImageButton = this.r;
        boolean z4 = true;
        if (!zJ || (z3 = checkableImageButton.f28o) == abstractC1052dwB.k()) {
            z2 = false;
        } else {
            checkableImageButton.setChecked(!z3);
            z2 = true;
        }
        if (!(abstractC1052dwB instanceof C0253Jt) || (zIsActivated = checkableImageButton.isActivated()) == ((C0253Jt) abstractC1052dwB).l) {
            z4 = z2;
        } else {
            checkableImageButton.setActivated(!zIsActivated);
        }
        if (z || z4) {
            IJ.C(this.l, checkableImageButton, this.v);
        }
    }

    public final void g(int i) {
        if (this.t == i) {
            return;
        }
        AbstractC1052dw abstractC1052dwB = b();
        G1 g1 = this.F;
        AccessibilityManager accessibilityManager = this.E;
        if (g1 != null && accessibilityManager != null) {
            accessibilityManager.removeTouchExplorationStateChangeListener(new AccessibilityManagerTouchExplorationStateChangeListenerC2675v0(g1));
        }
        this.F = null;
        abstractC1052dwB.r();
        this.t = i;
        Iterator it = this.u.iterator();
        if (it.hasNext()) {
            it.next().getClass();
            throw new ClassCastException();
        }
        h(i != 0);
        AbstractC1052dw abstractC1052dwB2 = b();
        int iD = this.s.b;
        if (iD == 0) {
            iD = abstractC1052dwB2.d();
        }
        Drawable drawableX = iD != 0 ? C80.x(getContext(), iD) : null;
        CheckableImageButton checkableImageButton = this.r;
        checkableImageButton.setImageDrawable(drawableX);
        TextInputLayout textInputLayout = this.l;
        if (drawableX != null) {
            IJ.b(textInputLayout, checkableImageButton, this.v, this.w);
            IJ.C(textInputLayout, checkableImageButton, this.v);
        }
        int iC = abstractC1052dwB2.c();
        CharSequence text = iC != 0 ? getResources().getText(iC) : null;
        if (checkableImageButton.getContentDescription() != text) {
            checkableImageButton.setContentDescription(text);
        }
        checkableImageButton.setCheckable(abstractC1052dwB2.j());
        if (!abstractC1052dwB2.i(textInputLayout.getBoxBackgroundMode())) {
            throw new IllegalStateException("The current box background mode " + textInputLayout.getBoxBackgroundMode() + " is not supported by the end icon mode " + i);
        }
        abstractC1052dwB2.q();
        G1 g1H = abstractC1052dwB2.h();
        this.F = g1H;
        if (g1H != null && accessibilityManager != null) {
            WeakHashMap weakHashMap = Oj0.a;
            if (isAttachedToWindow()) {
                accessibilityManager.addTouchExplorationStateChangeListener(new AccessibilityManagerTouchExplorationStateChangeListenerC2675v0(this.F));
            }
        }
        View.OnClickListener onClickListenerF = abstractC1052dwB2.f();
        View.OnLongClickListener onLongClickListener = this.z;
        checkableImageButton.setOnClickListener(onClickListenerF);
        IJ.F(checkableImageButton, onLongClickListener);
        EditText editText = this.D;
        if (editText != null) {
            abstractC1052dwB2.l(editText);
            j(abstractC1052dwB2);
        }
        IJ.b(textInputLayout, checkableImageButton, this.v, this.w);
        f(true);
    }

    public final void h(boolean z) {
        if (d() != z) {
            this.r.setVisibility(z ? 0 : 8);
            k();
            m();
            this.l.q();
        }
    }

    public final void i(Drawable drawable) {
        CheckableImageButton checkableImageButton = this.n;
        checkableImageButton.setImageDrawable(drawable);
        l();
        IJ.b(this.l, checkableImageButton, this.f482o, this.p);
    }

    public final void j(AbstractC1052dw abstractC1052dw) {
        if (this.D == null) {
            return;
        }
        if (abstractC1052dw.e() != null) {
            this.D.setOnFocusChangeListener(abstractC1052dw.e());
        }
        if (abstractC1052dw.g() != null) {
            this.r.setOnFocusChangeListener(abstractC1052dw.g());
        }
    }

    public final void k() {
        this.m.setVisibility((this.r.getVisibility() != 0 || e()) ? 8 : 0);
        setVisibility((d() || e() || !((this.A == null || this.C) ? 8 : false)) ? 0 : 8);
    }

    public final void l() {
        CheckableImageButton checkableImageButton = this.n;
        Drawable drawable = checkableImageButton.getDrawable();
        TextInputLayout textInputLayout = this.l;
        checkableImageButton.setVisibility((drawable != null && textInputLayout.u.q && textInputLayout.m()) ? 0 : 8);
        k();
        m();
        if (this.t != 0) {
            return;
        }
        textInputLayout.q();
    }

    public final void m() {
        int paddingEnd;
        TextInputLayout textInputLayout = this.l;
        if (textInputLayout.f30o == null) {
            return;
        }
        if (d() || e()) {
            paddingEnd = 0;
        } else {
            EditText editText = textInputLayout.f30o;
            WeakHashMap weakHashMap = Oj0.a;
            paddingEnd = editText.getPaddingEnd();
        }
        int dimensionPixelSize = getContext().getResources().getDimensionPixelSize(R.dimen.material_input_text_to_prefix_suffix_padding);
        int paddingTop = textInputLayout.f30o.getPaddingTop();
        int paddingBottom = textInputLayout.f30o.getPaddingBottom();
        WeakHashMap weakHashMap2 = Oj0.a;
        this.B.setPaddingRelative(dimensionPixelSize, paddingTop, paddingEnd, paddingBottom);
    }

    public final void n() {
        E8 e8 = this.B;
        int visibility = e8.getVisibility();
        int i = (this.A == null || this.C) ? 8 : 0;
        if (visibility != i) {
            b().o(i == 0);
        }
        k();
        e8.setVisibility(i);
        this.l.q();
    }
}
