package ca.canadapost.module.epostprofile.userprofile;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import ca.canadapost.module.epostprofile.userprofile.c;
import java.util.ArrayList;
import java.util.HashMap;
import kotlin.jvm.internal.t;
import ob.l;
import zb.c2;

/* loaded from: classes4.dex */
public final class a extends RecyclerView.h {

    /* renamed from: d, reason: collision with root package name */
    private final Context f9113d;

    /* renamed from: e, reason: collision with root package name */
    private ArrayList f9114e;

    /* renamed from: f, reason: collision with root package name */
    private HashMap f9115f;

    /* renamed from: ca.canadapost.module.epostprofile.userprofile.a$a, reason: collision with other inner class name */
    /* loaded from: classes4.dex */
    public final class C0254a extends RecyclerView.e0 implements TextWatcher {
        private final c2 J;
        private int K;
        final /* synthetic */ a L;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C0254a(a aVar, c2 binding) {
            super(binding.x());
            t.g(binding, "binding");
            this.L = aVar;
            this.J = binding;
        }

        public final void O(c.a objClsNickName, int i10) {
            t.g(objClsNickName, "objClsNickName");
            this.K = i10;
            this.J.A.setCounterEnabled(true);
            this.J.A.setTextMaxLength(40);
            this.J.A.setCounterMaxLength(40);
            this.J.A.setLabel(this.L.f9113d.getString(l.f31263e) + " " + (i10 + 1));
            this.J.A.setText(objClsNickName.b());
            this.J.A.setError(objClsNickName.a());
            this.L.f9115f.put(Integer.valueOf(i10), new c.a(objClsNickName.b(), objClsNickName.a()));
            this.J.A.getTextInputEditText().addTextChangedListener(this);
        }

        @Override // android.text.TextWatcher
        public void afterTextChanged(Editable editable) {
        }

        @Override // android.text.TextWatcher
        public void beforeTextChanged(CharSequence charSequence, int i10, int i11, int i12) {
        }

        @Override // android.text.TextWatcher
        public void onTextChanged(CharSequence charSequence, int i10, int i11, int i12) {
            HashMap hashMap = this.L.f9115f;
            Integer valueOf = Integer.valueOf(this.K);
            String valueOf2 = String.valueOf(charSequence);
            CharSequence error = this.J.A.getTextInputEditText().getError();
            hashMap.put(valueOf, new c.a(valueOf2, error != null ? error.toString() : null));
            this.J.A.setError((String) null);
        }
    }

    public a(Context mContext) {
        t.g(mContext, "mContext");
        this.f9113d = mContext;
        this.f9114e = new ArrayList();
        this.f9115f = new HashMap();
    }

    public final void H() {
        int g10 = g();
        this.f9114e.add(g10, new c.a("", null));
        m(g10);
        o(g10, this.f9114e.size());
    }

    public final HashMap I() {
        return this.f9115f;
    }

    @Override // androidx.recyclerview.widget.RecyclerView.h
    /* renamed from: J, reason: merged with bridge method [inline-methods] */
    public void u(C0254a holder, int i10) {
        t.g(holder, "holder");
        Object obj = this.f9114e.get(i10);
        t.f(obj, "get(...)");
        holder.O((c.a) obj, i10);
    }

    @Override // androidx.recyclerview.widget.RecyclerView.h
    /* renamed from: K, reason: merged with bridge method [inline-methods] */
    public C0254a w(ViewGroup parent, int i10) {
        t.g(parent, "parent");
        c2 U = c2.U(LayoutInflater.from(parent.getContext()), parent, false);
        t.f(U, "inflate(...)");
        return new C0254a(this, U);
    }

    public final void L(ArrayList arrayList) {
        this.f9115f = new HashMap();
        if (arrayList == null) {
            arrayList = new ArrayList();
        }
        this.f9114e = arrayList;
        l();
    }

    @Override // androidx.recyclerview.widget.RecyclerView.h
    public int g() {
        return this.f9114e.size();
    }
}
