package ca.canadapost.module.registration;

import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import androidx.fragment.app.f0;
import androidx.fragment.app.k;
import androidx.lifecycle.c1;
import androidx.lifecycle.g0;
import ca.canadapost.core.data.addresscomplete.webservice.AddressCompleteFindItem;
import ca.canadapost.core.data.auth.model.RegistrationAddressDetails;
import ca.canadapost.core.data.model.Event;
import ca.canadapost.module.registration.RegistrationStep2Fragment;
import dn.l;
import kotlin.Metadata;
import kotlin.jvm.internal.n;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import rm.n0;
import u8.g;
import w8.d0;
import w8.w;
import we.r;
import xe.q;

@Metadata(d1 = {"\u00008\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\b\u0018\u0000 \u00182\u00020\u0001:\u0001\u0019B\u0007¢\u0006\u0004\b\u0016\u0010\u0017J\u0012\u0010\u0005\u001a\u00020\u00042\b\u0010\u0003\u001a\u0004\u0018\u00010\u0002H\u0016J$\u0010\u000b\u001a\u00020\n2\u0006\u0010\u0007\u001a\u00020\u00062\b\u0010\t\u001a\u0004\u0018\u00010\b2\b\u0010\u0003\u001a\u0004\u0018\u00010\u0002H\u0016J\u001a\u0010\r\u001a\u00020\u00042\u0006\u0010\f\u001a\u00020\n2\b\u0010\u0003\u001a\u0004\u0018\u00010\u0002H\u0016R\u0016\u0010\u0011\u001a\u00020\u000e8\u0002@\u0002X\u0082.¢\u0006\u0006\n\u0004\b\u000f\u0010\u0010R\u0016\u0010\u0015\u001a\u00020\u00128\u0002@\u0002X\u0082.¢\u0006\u0006\n\u0004\b\u0013\u0010\u0014¨\u0006\u001a"}, d2 = {"Lca/canadapost/module/registration/RegistrationStep2Fragment;", "Lu8/b;", "Landroid/os/Bundle;", "savedInstanceState", "Lrm/n0;", "onCreate", "Landroid/view/LayoutInflater;", "inflater", "Landroid/view/ViewGroup;", "container", "Landroid/view/View;", "onCreateView", "view", "onViewCreated", "Lxe/q;", "s", "Lxe/q;", "binding", "Lwe/r;", "t", "Lwe/r;", "viewModel", "<init>", "()V", "u", "a", "registration_productionRelease"}, k = 1, mv = {1, 9, 0})
/* loaded from: classes4.dex */
public final class RegistrationStep2Fragment extends u8.b {

    /* renamed from: s, reason: collision with root package name and from kotlin metadata */
    private q binding;

    /* renamed from: t, reason: collision with root package name and from kotlin metadata */
    private r viewModel;

    /* loaded from: classes4.dex */
    public static final class b implements TextWatcher {
        public b() {
        }

        @Override // android.text.TextWatcher
        public void afterTextChanged(Editable editable) {
            q qVar = RegistrationStep2Fragment.this.binding;
            if (qVar == null) {
                t.y("binding");
                qVar = null;
            }
            qVar.A.B.setError((String) null);
        }

        @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) {
        }
    }

    /* loaded from: classes4.dex */
    public static final class c implements TextWatcher {
        public c() {
        }

        @Override // android.text.TextWatcher
        public void afterTextChanged(Editable editable) {
            q qVar = RegistrationStep2Fragment.this.binding;
            if (qVar == null) {
                t.y("binding");
                qVar = null;
            }
            qVar.A.D.setError((String) null);
        }

        @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) {
        }
    }

    /* loaded from: classes4.dex */
    public static final class d implements TextWatcher {
        public d() {
        }

        @Override // android.text.TextWatcher
        public void afterTextChanged(Editable editable) {
            q qVar = RegistrationStep2Fragment.this.binding;
            if (qVar == null) {
                t.y("binding");
                qVar = null;
            }
            qVar.A.F.setError((String) null);
        }

        @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) {
        }
    }

    /* loaded from: classes4.dex */
    static final class e extends v implements l {
        e() {
            super(1);
        }

        public final void a(Boolean bool) {
            r rVar = RegistrationStep2Fragment.this.viewModel;
            if (rVar == null) {
                t.y("viewModel");
                rVar = null;
            }
            rVar.O1();
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((Boolean) obj);
            return n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class f extends v implements l {
        f() {
            super(1);
        }

        public final void a(Event event) {
            Boolean bool = (Boolean) event.getContentIfNotHandled();
            if (bool != null) {
                RegistrationStep2Fragment registrationStep2Fragment = RegistrationStep2Fragment.this;
                if (bool.booleanValue()) {
                    registrationStep2Fragment.C();
                    w.d(x4.d.a(registrationStep2Fragment), we.d.f49143e, null, null, 6, null);
                }
            }
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((Event) obj);
            return n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class g extends v implements l {
        g() {
            super(1);
        }

        public final void a(Boolean bool) {
            g.a aVar = u8.g.f36993k;
            Context requireContext = RegistrationStep2Fragment.this.requireContext();
            String string = RegistrationStep2Fragment.this.getString(we.f.f49200u);
            t.f(string, "getString(...)");
            aVar.l(requireContext, string, RegistrationStep2Fragment.this.getString(we.f.f49199t)).x(RegistrationStep2Fragment.this.requireContext());
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((Boolean) obj);
            return n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class h extends v implements l {

        /* renamed from: p, reason: collision with root package name */
        public static final h f10668p = new h();

        h() {
            super(1);
        }

        public final void a(RegistrationAddressDetails registrationAddressDetails) {
        }

        @Override // dn.l
        public /* bridge */ /* synthetic */ Object invoke(Object obj) {
            a((RegistrationAddressDetails) obj);
            return n0.f34904a;
        }
    }

    /* loaded from: classes4.dex */
    static final class i implements g0, n {

        /* renamed from: a, reason: collision with root package name */
        private final /* synthetic */ l f10669a;

        i(l function) {
            t.g(function, "function");
            this.f10669a = function;
        }

        @Override // kotlin.jvm.internal.n
        public final rm.i b() {
            return this.f10669a;
        }

        @Override // androidx.lifecycle.g0
        public final /* synthetic */ void d(Object obj) {
            this.f10669a.invoke(obj);
        }

        public final boolean equals(Object obj) {
            if ((obj instanceof g0) && (obj instanceof n)) {
                return t.b(b(), ((n) obj).b());
            }
            return false;
        }

        public final int hashCode() {
            return b().hashCode();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void K(RegistrationStep2Fragment this$0, View view) {
        t.g(this$0, "this$0");
        r rVar = this$0.viewModel;
        if (rVar == null) {
            t.y("viewModel");
            rVar = null;
        }
        rVar.N1();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void L(s8.e decorator, RegistrationStep2Fragment this$0, String str, Bundle bundle) {
        t.g(decorator, "$decorator");
        t.g(this$0, "this$0");
        t.g(str, "<anonymous parameter 0>");
        t.g(bundle, "<anonymous parameter 1>");
        q qVar = this$0.binding;
        r rVar = null;
        if (qVar == null) {
            t.y("binding");
            qVar = null;
        }
        u7.a addressCompleteContent = qVar.A.A;
        t.f(addressCompleteContent, "addressCompleteContent");
        decorator.g(addressCompleteContent);
        r rVar2 = this$0.viewModel;
        if (rVar2 == null) {
            t.y("viewModel");
            rVar2 = null;
        }
        AddressCompleteFindItem addressCompleteFindItem = (AddressCompleteFindItem) rVar2.E0().f();
        if (addressCompleteFindItem != null) {
            r rVar3 = this$0.viewModel;
            if (rVar3 == null) {
                t.y("viewModel");
            } else {
                rVar = rVar3;
            }
            rVar.w0(addressCompleteFindItem);
        }
    }

    @Override // u8.b, androidx.fragment.app.f
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setRetainInstance(true);
        setHasOptionsMenu(true);
        this.viewModel = (r) new c1(this, y()).a(r.class);
    }

    @Override // androidx.fragment.app.f
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        t.g(inflater, "inflater");
        androidx.databinding.n h10 = androidx.databinding.f.h(inflater, we.e.f49172i, container, false);
        t.f(h10, "inflate(...)");
        q qVar = (q) h10;
        this.binding = qVar;
        q qVar2 = null;
        if (qVar == null) {
            t.y("binding");
            qVar = null;
        }
        qVar.O(getViewLifecycleOwner());
        q qVar3 = this.binding;
        if (qVar3 == null) {
            t.y("binding");
            qVar3 = null;
        }
        r rVar = this.viewModel;
        if (rVar == null) {
            t.y("viewModel");
            rVar = null;
        }
        qVar3.U(rVar);
        q qVar4 = this.binding;
        if (qVar4 == null) {
            t.y("binding");
        } else {
            qVar2 = qVar4;
        }
        View x10 = qVar2.x();
        t.f(x10, "getRoot(...)");
        return x10;
    }

    @Override // u8.b, androidx.fragment.app.f
    public void onViewCreated(View view, Bundle bundle) {
        r rVar;
        t.g(view, "view");
        super.onViewCreated(view, bundle);
        k activity = getActivity();
        r rVar2 = null;
        if (activity != null) {
            r rVar3 = this.viewModel;
            if (rVar3 == null) {
                t.y("viewModel");
                rVar3 = null;
            }
            activity.setTitle((CharSequence) rVar3.E1().f());
        }
        q qVar = this.binding;
        if (qVar == null) {
            t.y("binding");
            qVar = null;
        }
        qVar.A.B.getTextInputEditText().addTextChangedListener(new b());
        q qVar2 = this.binding;
        if (qVar2 == null) {
            t.y("binding");
            qVar2 = null;
        }
        qVar2.A.D.getTextInputEditText().addTextChangedListener(new c());
        q qVar3 = this.binding;
        if (qVar3 == null) {
            t.y("binding");
            qVar3 = null;
        }
        qVar3.A.F.getTextInputEditText().addTextChangedListener(new d());
        q qVar4 = this.binding;
        if (qVar4 == null) {
            t.y("binding");
            qVar4 = null;
        }
        Button nextActionButton = qVar4.A.E.A;
        t.f(nextActionButton, "nextActionButton");
        d0.p(nextActionButton, new View.OnClickListener() { // from class: we.p
            @Override // android.view.View.OnClickListener
            public final void onClick(View view2) {
                RegistrationStep2Fragment.K(RegistrationStep2Fragment.this, view2);
            }
        });
        r rVar4 = this.viewModel;
        if (rVar4 == null) {
            t.y("viewModel");
            rVar4 = null;
        }
        rVar4.J1().j(getViewLifecycleOwner(), new i(new e()));
        r rVar5 = this.viewModel;
        if (rVar5 == null) {
            t.y("viewModel");
            rVar5 = null;
        }
        rVar5.D1().j(getViewLifecycleOwner(), new i(new f()));
        r rVar6 = this.viewModel;
        if (rVar6 == null) {
            t.y("viewModel");
            rVar6 = null;
        }
        rVar6.I1().j(getViewLifecycleOwner(), new i(new g()));
        Context requireContext = requireContext();
        t.f(requireContext, "requireContext(...)");
        final s8.e eVar = new s8.e(requireContext);
        q qVar5 = this.binding;
        if (qVar5 == null) {
            t.y("binding");
            qVar5 = null;
        }
        u7.a addressCompleteContent = qVar5.A.A;
        t.f(addressCompleteContent, "addressCompleteContent");
        r rVar7 = this.viewModel;
        if (rVar7 == null) {
            t.y("viewModel");
            rVar = null;
        } else {
            rVar = rVar7;
        }
        q qVar6 = this.binding;
        if (qVar6 == null) {
            t.y("binding");
            qVar6 = null;
        }
        eVar.j(addressCompleteContent, rVar, this, (r13 & 8) != 0 ? null : qVar6.A.G, (r13 & 16) != 0 ? null : null);
        q qVar7 = this.binding;
        if (qVar7 == null) {
            t.y("binding");
            qVar7 = null;
        }
        Button nextActionButton2 = qVar7.A.E.A;
        t.f(nextActionButton2, "nextActionButton");
        d0.g(nextActionButton2);
        getParentFragmentManager().E1("BACK_FROM_STEP_3", this, new f0() { // from class: we.q
            @Override // androidx.fragment.app.f0
            public final void a(String str, Bundle bundle2) {
                RegistrationStep2Fragment.L(s8.e.this, this, str, bundle2);
            }
        });
        r rVar8 = this.viewModel;
        if (rVar8 == null) {
            t.y("viewModel");
        } else {
            rVar2 = rVar8;
        }
        rVar2.H1().b().j(getViewLifecycleOwner(), new i(h.f10668p));
    }
}
