package l2;

import P.Q;
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.material.internal.CheckableImageButton;
import com.google.android.material.textfield.TextInputLayout;
import com.riyaz.zvytour.R;
import e4.AbstractC0566j;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.LinkedHashSet;
import m.C0840I;
import p0.AbstractC0928a;

/* JADX INFO: loaded from: classes.dex */
public final class o extends LinearLayout {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public final C0840I f8831A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public boolean f8832B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public EditText f8833C;

    /* JADX INFO: renamed from: D, reason: collision with root package name */
    public final AccessibilityManager f8834D;

    /* JADX INFO: renamed from: E, reason: collision with root package name */
    public N2.a f8835E;

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    public final l f8836F;

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

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

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

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

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public PorterDuff.Mode f8841o;
    public View.OnLongClickListener p;
    public final CheckableImageButton q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final n f8842r;

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

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

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

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

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

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public ImageView.ScaleType f8848x;

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

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public CharSequence f8850z;

    public o(TextInputLayout textInputLayout, B2.a aVar) {
        CharSequence text;
        super(textInputLayout.getContext());
        this.f8843s = 0;
        this.f8844t = new LinkedHashSet();
        this.f8836F = new l(this);
        m mVar = new m(this);
        this.f8834D = (AccessibilityManager) getContext().getSystemService("accessibility");
        this.f8837k = textInputLayout;
        setVisibility(8);
        setOrientation(0);
        setLayoutParams(new FrameLayout.LayoutParams(-2, -1, 8388613));
        FrameLayout frameLayout = new FrameLayout(getContext());
        this.f8838l = 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.f8839m = checkableImageButtonA;
        CheckableImageButton checkableImageButtonA2 = a(frameLayout, layoutInflaterFrom, R.id.text_input_end_icon);
        this.q = checkableImageButtonA2;
        this.f8842r = new n(this, aVar);
        C0840I c0840i = new C0840I(getContext(), null);
        this.f8831A = c0840i;
        TypedArray typedArray = (TypedArray) aVar.f136n;
        if (typedArray.hasValue(36)) {
            this.f8840n = S4.m.i(getContext(), aVar, 36);
        }
        if (typedArray.hasValue(37)) {
            this.f8841o = d2.k.f(typedArray.getInt(37, -1), null);
        }
        if (typedArray.hasValue(35)) {
            h(aVar.t(35));
        }
        checkableImageButtonA.setContentDescription(getResources().getText(R.string.error_icon_content_description));
        Field field = Q.f2392a;
        checkableImageButtonA.setImportantForAccessibility(2);
        checkableImageButtonA.setClickable(false);
        checkableImageButtonA.setPressable(false);
        checkableImageButtonA.setFocusable(false);
        if (!typedArray.hasValue(51)) {
            if (typedArray.hasValue(30)) {
                this.f8845u = S4.m.i(getContext(), aVar, 30);
            }
            if (typedArray.hasValue(31)) {
                this.f8846v = d2.k.f(typedArray.getInt(31, -1), null);
            }
        }
        if (typedArray.hasValue(28)) {
            f(typedArray.getInt(28, 0));
            if (typedArray.hasValue(25) && checkableImageButtonA2.getContentDescription() != (text = typedArray.getText(25))) {
                checkableImageButtonA2.setContentDescription(text);
            }
            checkableImageButtonA2.setCheckable(typedArray.getBoolean(24, true));
        } else if (typedArray.hasValue(51)) {
            if (typedArray.hasValue(52)) {
                this.f8845u = S4.m.i(getContext(), aVar, 52);
            }
            if (typedArray.hasValue(53)) {
                this.f8846v = d2.k.f(typedArray.getInt(53, -1), null);
            }
            f(typedArray.getBoolean(51, false) ? 1 : 0);
            CharSequence text2 = typedArray.getText(49);
            if (checkableImageButtonA2.getContentDescription() != text2) {
                checkableImageButtonA2.setContentDescription(text2);
            }
        }
        int dimensionPixelSize = typedArray.getDimensionPixelSize(27, getResources().getDimensionPixelSize(R.dimen.mtrl_min_touch_target_size));
        if (dimensionPixelSize < 0) {
            throw new IllegalArgumentException("endIconSize cannot be less than 0");
        }
        if (dimensionPixelSize != this.f8847w) {
            this.f8847w = dimensionPixelSize;
            checkableImageButtonA2.setMinimumWidth(dimensionPixelSize);
            checkableImageButtonA2.setMinimumHeight(dimensionPixelSize);
            checkableImageButtonA.setMinimumWidth(dimensionPixelSize);
            checkableImageButtonA.setMinimumHeight(dimensionPixelSize);
        }
        if (typedArray.hasValue(29)) {
            ImageView.ScaleType scaleTypeH = AbstractC0566j.h(typedArray.getInt(29, -1));
            this.f8848x = scaleTypeH;
            checkableImageButtonA2.setScaleType(scaleTypeH);
            checkableImageButtonA.setScaleType(scaleTypeH);
        }
        c0840i.setVisibility(8);
        c0840i.setId(R.id.textinput_suffix_text);
        c0840i.setLayoutParams(new LinearLayout.LayoutParams(-2, -2, 80.0f));
        c0840i.setAccessibilityLiveRegion(1);
        c0840i.setTextAppearance(typedArray.getResourceId(70, 0));
        if (typedArray.hasValue(71)) {
            c0840i.setTextColor(aVar.s(71));
        }
        CharSequence text3 = typedArray.getText(69);
        this.f8850z = TextUtils.isEmpty(text3) ? null : text3;
        c0840i.setText(text3);
        m();
        frameLayout.addView(checkableImageButtonA2);
        addView(c0840i);
        addView(frameLayout);
        addView(checkableImageButtonA);
        textInputLayout.f5628m0.add(mVar);
        if (textInputLayout.f5629n != null) {
            mVar.a(textInputLayout);
        }
        addOnAttachStateChangeListener(new io.sentry.android.core.internal.util.f(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 (S4.m.s(getContext())) {
            ((ViewGroup.MarginLayoutParams) checkableImageButton.getLayoutParams()).setMarginStart(0);
        }
        return checkableImageButton;
    }

    public final p b() {
        p fVar;
        int i = this.f8843s;
        n nVar = this.f8842r;
        SparseArray sparseArray = nVar.f8827a;
        p pVar = (p) sparseArray.get(i);
        if (pVar != null) {
            return pVar;
        }
        o oVar = nVar.f8828b;
        if (i == -1) {
            fVar = new f(oVar, 0);
        } else if (i == 0) {
            fVar = new f(oVar, 1);
        } else if (i == 1) {
            fVar = new t(oVar, nVar.f8830d);
        } else if (i == 2) {
            fVar = new e(oVar);
        } else {
            if (i != 3) {
                throw new IllegalArgumentException(AbstractC0928a.i(i, "Invalid end icon mode: "));
            }
            fVar = new k(oVar);
        }
        sparseArray.append(i, fVar);
        return fVar;
    }

    public final boolean c() {
        return this.f8838l.getVisibility() == 0 && this.q.getVisibility() == 0;
    }

    public final boolean d() {
        return this.f8839m.getVisibility() == 0;
    }

    public final void e(boolean z5) {
        boolean z6;
        boolean zIsActivated;
        boolean z7;
        p pVarB = b();
        boolean zK = pVarB.k();
        CheckableImageButton checkableImageButton = this.q;
        boolean z8 = true;
        if (!zK || (z7 = checkableImageButton.f5551n) == pVarB.l()) {
            z6 = false;
        } else {
            checkableImageButton.setChecked(!z7);
            z6 = true;
        }
        if (!(pVarB instanceof k) || (zIsActivated = checkableImageButton.isActivated()) == pVarB.j()) {
            z8 = z6;
        } else {
            checkableImageButton.setActivated(!zIsActivated);
        }
        if (z5 || z8) {
            AbstractC0566j.v(this.f8837k, checkableImageButton, this.f8845u);
        }
    }

    public final void f(int i) {
        if (this.f8843s == i) {
            return;
        }
        p pVarB = b();
        N2.a aVar = this.f8835E;
        AccessibilityManager accessibilityManager = this.f8834D;
        if (aVar != null && accessibilityManager != null) {
            accessibilityManager.removeTouchExplorationStateChangeListener(new Q.b(aVar));
        }
        this.f8835E = null;
        pVarB.s();
        this.f8843s = i;
        Iterator it = this.f8844t.iterator();
        if (it.hasNext()) {
            it.next().getClass();
            throw new ClassCastException();
        }
        g(i != 0);
        p pVarB2 = b();
        int iD = this.f8842r.f8829c;
        if (iD == 0) {
            iD = pVarB2.d();
        }
        Drawable drawableJ = iD != 0 ? AbstractC0566j.j(getContext(), iD) : null;
        CheckableImageButton checkableImageButton = this.q;
        checkableImageButton.setImageDrawable(drawableJ);
        TextInputLayout textInputLayout = this.f8837k;
        if (drawableJ != null) {
            AbstractC0566j.b(textInputLayout, checkableImageButton, this.f8845u, this.f8846v);
            AbstractC0566j.v(textInputLayout, checkableImageButton, this.f8845u);
        }
        int iC = pVarB2.c();
        CharSequence text = iC != 0 ? getResources().getText(iC) : null;
        if (checkableImageButton.getContentDescription() != text) {
            checkableImageButton.setContentDescription(text);
        }
        checkableImageButton.setCheckable(pVarB2.k());
        if (!pVarB2.i(textInputLayout.getBoxBackgroundMode())) {
            throw new IllegalStateException("The current box background mode " + textInputLayout.getBoxBackgroundMode() + " is not supported by the end icon mode " + i);
        }
        pVarB2.r();
        N2.a aVarH = pVarB2.h();
        this.f8835E = aVarH;
        if (aVarH != null && accessibilityManager != null) {
            Field field = Q.f2392a;
            if (isAttachedToWindow()) {
                accessibilityManager.addTouchExplorationStateChangeListener(new Q.b(this.f8835E));
            }
        }
        View.OnClickListener onClickListenerF = pVarB2.f();
        View.OnLongClickListener onLongClickListener = this.f8849y;
        checkableImageButton.setOnClickListener(onClickListenerF);
        AbstractC0566j.x(checkableImageButton, onLongClickListener);
        EditText editText = this.f8833C;
        if (editText != null) {
            pVarB2.m(editText);
            i(pVarB2);
        }
        AbstractC0566j.b(textInputLayout, checkableImageButton, this.f8845u, this.f8846v);
        e(true);
    }

    public final void g(boolean z5) {
        if (c() != z5) {
            this.q.setVisibility(z5 ? 0 : 8);
            j();
            l();
            this.f8837k.p();
        }
    }

    public final void h(Drawable drawable) {
        CheckableImageButton checkableImageButton = this.f8839m;
        checkableImageButton.setImageDrawable(drawable);
        k();
        AbstractC0566j.b(this.f8837k, checkableImageButton, this.f8840n, this.f8841o);
    }

    public final void i(p pVar) {
        if (this.f8833C == null) {
            return;
        }
        if (pVar.e() != null) {
            this.f8833C.setOnFocusChangeListener(pVar.e());
        }
        if (pVar.g() != null) {
            this.q.setOnFocusChangeListener(pVar.g());
        }
    }

    public final void j() {
        this.f8838l.setVisibility((this.q.getVisibility() != 0 || d()) ? 8 : 0);
        setVisibility((c() || d() || ((this.f8850z == null || this.f8832B) ? '\b' : (char) 0) == 0) ? 0 : 8);
    }

    public final void k() {
        CheckableImageButton checkableImageButton = this.f8839m;
        Drawable drawable = checkableImageButton.getDrawable();
        TextInputLayout textInputLayout = this.f8837k;
        checkableImageButton.setVisibility((drawable != null && textInputLayout.f5639t.q && textInputLayout.m()) ? 0 : 8);
        j();
        l();
        if (this.f8843s != 0) {
            return;
        }
        textInputLayout.p();
    }

    public final void l() {
        int paddingEnd;
        TextInputLayout textInputLayout = this.f8837k;
        if (textInputLayout.f5629n == null) {
            return;
        }
        if (c() || d()) {
            paddingEnd = 0;
        } else {
            EditText editText = textInputLayout.f5629n;
            Field field = Q.f2392a;
            paddingEnd = editText.getPaddingEnd();
        }
        int dimensionPixelSize = getContext().getResources().getDimensionPixelSize(R.dimen.material_input_text_to_prefix_suffix_padding);
        int paddingTop = textInputLayout.f5629n.getPaddingTop();
        int paddingBottom = textInputLayout.f5629n.getPaddingBottom();
        Field field2 = Q.f2392a;
        this.f8831A.setPaddingRelative(dimensionPixelSize, paddingTop, paddingEnd, paddingBottom);
    }

    public final void m() {
        C0840I c0840i = this.f8831A;
        int visibility = c0840i.getVisibility();
        int i = (this.f8850z == null || this.f8832B) ? 8 : 0;
        if (visibility != i) {
            b().p(i == 0);
        }
        j();
        c0840i.setVisibility(i);
        this.f8837k.p();
    }
}
