package ca.canadapost.module.addresscomplete;

import ab.e;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import androidx.databinding.f;
import androidx.databinding.n;
import androidx.lifecycle.c1;
import androidx.lifecycle.g0;
import ca.canadapost.core.common.customView.i;
import ca.canadapost.core.data.model.Event;
import ca.canadapost.module.addresscomplete.AddOrEditManualAddressFragment;
import i.c;
import java.util.List;
import kotlin.Metadata;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import rm.n0;
import sm.c0;
import u8.g;
import w8.r;
import x4.d;
import z7.b;
import za.e0;
import za.f0;
import za.h0;
import za.j0;
import za.k;

@Metadata(d1 = {"\u0000N\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0018\u0002\n\u0002\b\r\u0018\u00002\u00020\u00012\u00020\u0002B\u0007¢\u0006\u0004\b.\u0010/J\b\u0010\u0004\u001a\u00020\u0003H\u0002J\b\u0010\u0005\u001a\u00020\u0003H\u0002J\u0012\u0010\b\u001a\u00020\u00032\b\u0010\u0007\u001a\u0004\u0018\u00010\u0006H\u0016J&\u0010\u000e\u001a\u0004\u0018\u00010\r2\u0006\u0010\n\u001a\u00020\t2\b\u0010\f\u001a\u0004\u0018\u00010\u000b2\b\u0010\u0007\u001a\u0004\u0018\u00010\u0006H\u0016J\u001a\u0010\u0010\u001a\u00020\u00032\u0006\u0010\u000f\u001a\u00020\r2\b\u0010\u0007\u001a\u0004\u0018\u00010\u0006H\u0016J\b\u0010\u0012\u001a\u00020\u0011H\u0016R\"\u0010\u001a\u001a\u00020\u00138\u0006@\u0006X\u0086.¢\u0006\u0012\n\u0004\b\u0014\u0010\u0015\u001a\u0004\b\u0016\u0010\u0017\"\u0004\b\u0018\u0010\u0019R\"\u0010\"\u001a\u00020\u001b8\u0006@\u0006X\u0086.¢\u0006\u0012\n\u0004\b\u001c\u0010\u001d\u001a\u0004\b\u001e\u0010\u001f\"\u0004\b \u0010!R\"\u0010*\u001a\u00020#8\u0006@\u0006X\u0087.¢\u0006\u0012\n\u0004\b$\u0010%\u001a\u0004\b&\u0010'\"\u0004\b(\u0010)R\u0016\u0010-\u001a\u00020\u00118\u0002@\u0002X\u0082\u000e¢\u0006\u0006\n\u0004\b+\u0010,¨\u00060"}, d2 = {"Lca/canadapost/module/addresscomplete/AddOrEditManualAddressFragment;", "Lu8/b;", "", "Lrm/n0;", "c0", "f0", "Landroid/os/Bundle;", "savedInstanceState", "onCreate", "Landroid/view/LayoutInflater;", "inflater", "Landroid/view/ViewGroup;", "container", "Landroid/view/View;", "onCreateView", "view", "onViewCreated", "", "E", "Lab/e;", "s", "Lab/e;", "Q", "()Lab/e;", "b0", "(Lab/e;)V", "binding", "Lza/k;", "t", "Lza/k;", "S", "()Lza/k;", "e0", "(Lza/k;)V", "viewModel", "Lw8/r;", "u", "Lw8/r;", "R", "()Lw8/r;", "setShareDataService", "(Lw8/r;)V", "shareDataService", "v", "Z", "isDismissDirectly", "<init>", "()V", "addresscomplete_productionRelease"}, k = 1, mv = {1, 9, 0})
/* loaded from: classes4.dex */
public final class AddOrEditManualAddressFragment extends u8.b {

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

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

    /* renamed from: u, reason: collision with root package name and from kotlin metadata */
    public r shareDataService;

    /* renamed from: v, reason: collision with root package name and from kotlin metadata */
    private boolean isDismissDirectly;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class a extends v implements dn.a {
        a() {
            super(0);
        }

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

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m56invoke() {
            AddOrEditManualAddressFragment.this.isDismissDirectly = true;
            AddOrEditManualAddressFragment.this.S().S();
            AddOrEditManualAddressFragment.this.E();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class b extends v implements dn.a {
        b() {
            super(0);
        }

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

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m57invoke() {
            AddOrEditManualAddressFragment.this.isDismissDirectly = false;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void T(AddOrEditManualAddressFragment this$0, View view) {
        t.g(this$0, "this$0");
        this$0.S().h0();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void U(final AddOrEditManualAddressFragment this$0, Boolean bool) {
        t.g(this$0, "this$0");
        t.d(bool);
        if (bool.booleanValue()) {
            this$0.Q().B.setTitle(this$0.getString(j0.f53345k));
        } else {
            this$0.Q().B.setTitle(this$0.getString(j0.f53335a));
        }
        androidx.fragment.app.k activity = this$0.getActivity();
        t.e(activity, "null cannot be cast to non-null type androidx.appcompat.app.AppCompatActivity");
        ((c) activity).N(this$0.Q().B);
        this$0.Q().B.setNavigationOnClickListener(new View.OnClickListener() { // from class: za.h
            @Override // android.view.View.OnClickListener
            public final void onClick(View view) {
                AddOrEditManualAddressFragment.V(AddOrEditManualAddressFragment.this, view);
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void V(AddOrEditManualAddressFragment this$0, View view) {
        t.g(this$0, "this$0");
        this$0.E();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void W(AddOrEditManualAddressFragment this$0, Boolean bool) {
        t.g(this$0, "this$0");
        t.d(bool);
        if (bool.booleanValue()) {
            this$0.Q().A.C.setError(this$0.getString(j0.f53337c));
        }
        this$0.Q().A.C.setErrorEnabled(bool.booleanValue());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void X(AddOrEditManualAddressFragment this$0, Boolean bool) {
        t.g(this$0, "this$0");
        t.d(bool);
        if (bool.booleanValue()) {
            this$0.Q().A.A.setError(this$0.getString(j0.f53338d));
        }
        this$0.Q().A.A.setErrorEnabled(bool.booleanValue());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void Y(AddOrEditManualAddressFragment this$0, Boolean bool) {
        t.g(this$0, "this$0");
        t.d(bool);
        if (bool.booleanValue()) {
            this$0.Q().A.E.setError(this$0.getString(j0.f53341g));
        }
        this$0.Q().A.E.setErrorEnabled(bool.booleanValue());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void Z(AddOrEditManualAddressFragment this$0, Boolean bool) {
        t.g(this$0, "this$0");
        t.d(bool);
        if (bool.booleanValue()) {
            this$0.Q().A.B.setError(this$0.getString(j0.f53340f));
        }
        this$0.Q().A.B.setErrorEnabled(bool.booleanValue());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void a0(AddOrEditManualAddressFragment this$0, Event event) {
        t.g(this$0, "this$0");
        Boolean bool = (Boolean) event.getContentIfNotHandled();
        if (bool == null || !bool.booleanValue()) {
            return;
        }
        this$0.requireActivity().finish();
    }

    private final void c0() {
        List V0;
        b.a aVar = z7.b.Companion;
        Context requireContext = requireContext();
        t.f(requireContext, "requireContext(...)");
        List b10 = aVar.b(requireContext);
        Context context = getContext();
        V0 = c0.V0(b10);
        Q().A.F.setAdapter(new i(context, V0));
        Q().A.F.setOnItemClickListener(new AdapterView.OnItemClickListener() { // from class: za.i
            @Override // android.widget.AdapterView.OnItemClickListener
            public final void onItemClick(AdapterView adapterView, View view, int i10, long j10) {
                AddOrEditManualAddressFragment.d0(AddOrEditManualAddressFragment.this, adapterView, view, i10, j10);
            }
        });
        int size = b10.size();
        for (int i10 = 0; i10 < size; i10++) {
            if (t.b(((z7.a) ((qa.c) b10.get(i10)).a()).getCode(), S().Z().f())) {
                Q().A.F.setSelection(i10);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void d0(AddOrEditManualAddressFragment this$0, AdapterView adapterView, View view, int i10, long j10) {
        t.g(this$0, "this$0");
        Object itemAtPosition = adapterView != null ? adapterView.getItemAtPosition(i10) : null;
        t.e(itemAtPosition, "null cannot be cast to non-null type ca.canadapost.core.data.util.StringWithTag<*>");
        k S = this$0.S();
        Object a10 = ((qa.c) itemAtPosition).a();
        t.e(a10, "null cannot be cast to non-null type ca.canadapost.core.common.enums.ProvinceCode");
        S.Q((z7.a) a10);
    }

    private final void f0() {
        g.a aVar = g.f36993k;
        androidx.fragment.app.k requireActivity = requireActivity();
        String string = requireActivity().getString(j0.f53343i);
        t.f(string, "getString(...)");
        g l10 = aVar.l(requireActivity, string, requireActivity().getString(j0.f53344j));
        l10.n(requireActivity().getString(j0.f53342h));
        l10.p(requireActivity().getString(j0.f53336b));
        l10.o(new a());
        l10.q(new b());
        l10.x(requireActivity());
    }

    @Override // u8.b
    public boolean E() {
        C();
        boolean e02 = S().e0();
        if (!this.isDismissDirectly && e02) {
            f0();
            return true;
        }
        this.isDismissDirectly = false;
        d.a(this).U();
        R().d("Manual_address_loaded_once", Boolean.FALSE);
        return true;
    }

    public final e Q() {
        e eVar = this.binding;
        if (eVar != null) {
            return eVar;
        }
        t.y("binding");
        return null;
    }

    public final r R() {
        r rVar = this.shareDataService;
        if (rVar != null) {
            return rVar;
        }
        t.y("shareDataService");
        return null;
    }

    public final k S() {
        k kVar = this.viewModel;
        if (kVar != null) {
            return kVar;
        }
        t.y("viewModel");
        return null;
    }

    public final void b0(e eVar) {
        t.g(eVar, "<set-?>");
        this.binding = eVar;
    }

    public final void e0(k kVar) {
        t.g(kVar, "<set-?>");
        this.viewModel = kVar;
    }

    @Override // u8.b, androidx.fragment.app.f
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setHasOptionsMenu(true);
        androidx.fragment.app.k requireActivity = requireActivity();
        t.f(requireActivity, "requireActivity(...)");
        e0((k) new c1(requireActivity, y()).a(k.class));
    }

    @Override // androidx.fragment.app.f
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        t.g(inflater, "inflater");
        n h10 = f.h(inflater, h0.f53330c, container, false);
        t.f(h10, "inflate(...)");
        b0((e) h10);
        Q().O(getViewLifecycleOwner());
        Q().U(S());
        return Q().x();
    }

    @Override // u8.b, androidx.fragment.app.f
    public void onViewCreated(View view, Bundle bundle) {
        t.g(view, "view");
        super.onViewCreated(view, bundle);
        Boolean bool = (Boolean) R().e("Manual_address_loaded_once");
        if (bool == null || !bool.booleanValue()) {
            R().d("Manual_address_loaded_once", Boolean.TRUE);
            S().f0();
            S().i0();
        }
        Q().B.setNavigationIcon(f0.f53316a);
        Q().A.B.getTextInputEditText().setEnabled(false);
        Q().A.B.getTextInputEditText().setTextColor(requireActivity().getColor(e0.f53314a));
        Q().A.G.A.setOnClickListener(new View.OnClickListener() { // from class: za.a
            @Override // android.view.View.OnClickListener
            public final void onClick(View view2) {
                AddOrEditManualAddressFragment.T(AddOrEditManualAddressFragment.this, view2);
            }
        });
        S().g0().j(getViewLifecycleOwner(), new g0() { // from class: za.b
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                AddOrEditManualAddressFragment.U(AddOrEditManualAddressFragment.this, (Boolean) obj);
            }
        });
        S().c0().j(getViewLifecycleOwner(), new g0() { // from class: za.c
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                AddOrEditManualAddressFragment.W(AddOrEditManualAddressFragment.this, (Boolean) obj);
            }
        });
        S().a0().j(getViewLifecycleOwner(), new g0() { // from class: za.d
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                AddOrEditManualAddressFragment.X(AddOrEditManualAddressFragment.this, (Boolean) obj);
            }
        });
        S().d0().j(getViewLifecycleOwner(), new g0() { // from class: za.e
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                AddOrEditManualAddressFragment.Y(AddOrEditManualAddressFragment.this, (Boolean) obj);
            }
        });
        S().b0().j(getViewLifecycleOwner(), new g0() { // from class: za.f
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                AddOrEditManualAddressFragment.Z(AddOrEditManualAddressFragment.this, (Boolean) obj);
            }
        });
        S().Y().j(getViewLifecycleOwner(), new g0() { // from class: za.g
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                AddOrEditManualAddressFragment.a0(AddOrEditManualAddressFragment.this, (Event) obj);
            }
        });
        c0();
    }
}
