package ca.canadapost.module.findrate;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import androidx.lifecycle.c1;
import androidx.lifecycle.e1;
import androidx.lifecycle.u;
import androidx.lifecycle.z0;
import androidx.recyclerview.widget.RecyclerView;
import ca.canadapost.core.common.navigation.ui.d;
import ca.canadapost.core.data.findrate.model.FindRateDataModel;
import ca.canadapost.core.data.findrate.model.FindRateResponseItem;
import ca.canadapost.core.data.model.RepositoryError;
import ca.canadapost.core.data.model.ResultWrapper;
import ca.canadapost.module.findrate.d;
import dc.d0;
import dc.e0;
import dc.h0;
import dc.r0;
import dc.u0;
import dc.v0;
import ec.a0;
import java.util.List;
import km.t;
import kotlin.Metadata;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.n;
import kotlin.jvm.internal.q;
import kotlin.jvm.internal.v;
import l8.h;
import o8.g0;
import org.joda.time.DateTime;
import rm.c0;
import rm.i;
import rm.n0;
import rm.o;
import u7.x;
import w8.l;
import w8.p0;
import w8.w;

@Metadata(d1 = {"\u0000°\u0001\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\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\u0000\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\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\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\u0007\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u000f\u0018\u0000 \\2\u00020\u00012\b\u0012\u0004\u0012\u00020\u00030\u00022\u00020\u00042\u00020\u0005:\u0001]B\u0007¢\u0006\u0004\bZ\u0010[J\u0010\u0010\t\u001a\u00020\b2\u0006\u0010\u0007\u001a\u00020\u0006H\u0002J5\u0010\u0015\u001a\u00020\u00142\u0006\u0010\u000b\u001a\u00020\n2\b\u0010\r\u001a\u0004\u0018\u00010\f2\b\u0010\u000f\u001a\u0004\u0018\u00010\u000e2\u0006\u0010\u0011\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u0012H\u0096\u0001J\u0019\u0010\u001a\u001a\u00020\b2\u0006\u0010\u0017\u001a\u00020\u00162\u0006\u0010\u0019\u001a\u00020\u0018H\u0096\u0001J\u0019\u0010\u001f\u001a\u00020\b2\u0006\u0010\u001c\u001a\u00020\u001b2\u0006\u0010\u001e\u001a\u00020\u001dH\u0096\u0001J\u0019\u0010 \u001a\u00020\b2\u0006\u0010\u0019\u001a\u00020\u00182\u0006\u0010\u001e\u001a\u00020\u001dH\u0096\u0001J#\u0010%\u001a\u00020\b2\u0006\u0010\"\u001a\u00020!2\u0006\u0010\u0019\u001a\u00020\u00182\b\b\u0002\u0010$\u001a\u00020#H\u0096\u0001J#\u0010'\u001a\u00020\b2\u0006\u0010\"\u001a\u00020!2\u0006\u0010\u001c\u001a\u00020&2\b\b\u0002\u0010$\u001a\u00020#H\u0096\u0001J\u0012\u0010(\u001a\u00020\b2\b\u0010\u000f\u001a\u0004\u0018\u00010\u000eH\u0016J$\u0010)\u001a\u00020\u00142\u0006\u0010\u000b\u001a\u00020\n2\b\u0010\r\u001a\u0004\u0018\u00010\f2\b\u0010\u000f\u001a\u0004\u0018\u00010\u000eH\u0016J\u001a\u0010+\u001a\u00020\b2\u0006\u0010*\u001a\u00020\u00142\b\u0010\u000f\u001a\u0004\u0018\u00010\u000eH\u0016J\u0010\u0010-\u001a\u00020#2\u0006\u0010\u0007\u001a\u00020,H\u0016R\"\u00105\u001a\u00020.8\u0006@\u0006X\u0087.¢\u0006\u0012\n\u0004\b/\u00100\u001a\u0004\b1\u00102\"\u0004\b3\u00104R\"\u0010=\u001a\u0002068\u0004@\u0004X\u0085.¢\u0006\u0012\n\u0004\b7\u00108\u001a\u0004\b9\u0010:\"\u0004\b;\u0010<R\"\u0010E\u001a\u00020>8\u0004@\u0004X\u0085.¢\u0006\u0012\n\u0004\b?\u0010@\u001a\u0004\bA\u0010B\"\u0004\bC\u0010DR\u001b\u0010\u0013\u001a\u00020F8FX\u0086\u0084\u0002¢\u0006\f\n\u0004\bG\u0010H\u001a\u0004\bI\u0010JR\u0016\u0010N\u001a\u00020K8\u0002@\u0002X\u0082.¢\u0006\u0006\n\u0004\bL\u0010MR\"\u0010V\u001a\u00020O8\u0006@\u0006X\u0086.¢\u0006\u0012\n\u0004\bP\u0010Q\u001a\u0004\bR\u0010S\"\u0004\bT\u0010UR\u0014\u0010Y\u001a\u00020\u00038\u0016X\u0096\u0005¢\u0006\u0006\u001a\u0004\bW\u0010X¨\u0006^"}, d2 = {"Lca/canadapost/module/findrate/e;", "Lu8/b;", "", "Lec/a0;", "Lw8/p0;", "Lca/canadapost/core/common/navigation/ui/d;", "Lca/canadapost/core/data/findrate/model/FindRateResponseItem;", "item", "Lrm/n0;", "Q", "Landroid/view/LayoutInflater;", "inflater", "Landroid/view/ViewGroup;", "container", "Landroid/os/Bundle;", "savedInstanceState", "Landroidx/lifecycle/u;", "viewLifecycleOwner", "Landroidx/lifecycle/z0;", "viewModel", "Landroid/view/View;", "P", "Ll8/h;", "spinnerVM", "Landroidx/fragment/app/f;", "fragment", "I", "Landroid/app/Activity;", "activity", "Ll8/h$b;", "event", "c", "p", "Lo8/h0;", "profileNavigationVMHandler", "", "showTwoSv", "f", "Landroidx/fragment/app/k;", "b", "onCreate", "onCreateView", "view", "onViewCreated", "Landroid/view/MenuItem;", "onOptionsItemSelected", "Lca/a;", "v", "Lca/a;", "K", "()Lca/a;", "setLanguageService", "(Lca/a;)V", "languageService", "Ldc/v0;", "w", "Ldc/v0;", "N", "()Ldc/v0;", "setRateListViewModelFactory", "(Ldc/v0;)V", "rateListViewModelFactory", "Lkm/t;", "x", "Lkm/t;", "L", "()Lkm/t;", "setMoshi", "(Lkm/t;)V", "moshi", "Ldc/u0;", "y", "Lrm/o;", "O", "()Ldc/u0;", "Ldc/r0;", "z", "Ldc/r0;", "adapter", "Lca/canadapost/module/findrate/d$a;", "A", "Lca/canadapost/module/findrate/d$a;", "M", "()Lca/canadapost/module/findrate/d$a;", "R", "(Lca/canadapost/module/findrate/d$a;)V", "pageType", "J", "()Lec/a0;", "binding", "<init>", "()V", "B", "a", "findrate_productionRelease"}, k = 1, mv = {1, 9, 0})
/* loaded from: classes4.dex */
public final class e extends u8.b implements p0, ca.canadapost.core.common.navigation.ui.d {

    /* renamed from: B, reason: from kotlin metadata */
    public static final Companion INSTANCE = new Companion(null);

    /* renamed from: A, reason: from kotlin metadata */
    public d.a pageType;

    /* renamed from: s, reason: collision with root package name */
    private final /* synthetic */ x f9337s = new x(e0.f16052q);

    /* renamed from: t, reason: collision with root package name */
    private final /* synthetic */ l f9338t = new l();

    /* renamed from: u, reason: collision with root package name */
    private final /* synthetic */ g0 f9339u = new g0();

    /* renamed from: v, reason: collision with root package name and from kotlin metadata */
    public ca.a languageService;

    /* renamed from: w, reason: collision with root package name and from kotlin metadata */
    protected v0 rateListViewModelFactory;

    /* renamed from: x, reason: collision with root package name and from kotlin metadata */
    protected t moshi;

    /* renamed from: y, reason: collision with root package name and from kotlin metadata */
    private final o viewModel;

    /* renamed from: z, reason: collision with root package name and from kotlin metadata */
    private r0 adapter;

    /* renamed from: ca.canadapost.module.findrate.e$a, reason: from kotlin metadata */
    /* loaded from: classes4.dex */
    public static final class Companion {
        private Companion() {
        }

        public /* synthetic */ Companion(k kVar) {
            this();
        }

        public final e a(d.a pageType, FindRateDataModel findRateDataModel) {
            kotlin.jvm.internal.t.g(pageType, "pageType");
            e eVar = new e();
            eVar.R(pageType);
            if (findRateDataModel != null) {
                Bundle bundle = new Bundle();
                bundle.putSerializable("ARG_DATA_MODEL", findRateDataModel);
                eVar.setArguments(bundle);
            }
            return eVar;
        }
    }

    /* loaded from: classes4.dex */
    /* synthetic */ class b extends q implements dn.l {
        b(Object obj) {
            super(1, obj, e.class, "onListItemClickListener", "onListItemClickListener(Lca/canadapost/core/data/findrate/model/FindRateResponseItem;)V", 0);
        }

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

        public final void l(FindRateResponseItem p02) {
            kotlin.jvm.internal.t.g(p02, "p0");
            ((e) this.receiver).Q(p02);
        }
    }

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

        public final void a(List list) {
            r0 r0Var = e.this.adapter;
            if (r0Var == null) {
                kotlin.jvm.internal.t.y("adapter");
                r0Var = null;
            }
            r0Var.W(list);
        }

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

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

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

            /* renamed from: p, reason: collision with root package name */
            final /* synthetic */ e f9347p;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            a(e eVar) {
                super(0);
                this.f9347p = eVar;
            }

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

            /* renamed from: invoke, reason: collision with other method in class */
            public final void m135invoke() {
                this.f9347p.requireActivity().onBackPressed();
            }
        }

        /* loaded from: classes4.dex */
        public /* synthetic */ class b {

            /* renamed from: a, reason: collision with root package name */
            public static final /* synthetic */ int[] f9348a;

            static {
                int[] iArr = new int[RepositoryError.values().length];
                try {
                    iArr[RepositoryError.NoNetworkError.ordinal()] = 1;
                } catch (NoSuchFieldError unused) {
                }
                f9348a = iArr;
            }
        }

        d() {
            super(1);
        }

        public final void a(ResultWrapper.Error error) {
            if (b.f9348a[error.getError().ordinal()] == 1) {
                u8.g.f36993k.i(e.this.requireContext()).x(e.this.requireContext());
                return;
            }
            String message = error.getMessage();
            if (message == null) {
                message = e.this.getString(h0.U0);
                kotlin.jvm.internal.t.f(message, "getString(...)");
            }
            u8.g j10 = u8.g.f36993k.j(e.this.requireContext(), message, e.this.getString(h0.V0));
            j10.o(new a(e.this));
            j10.x(e.this.requireContext());
        }

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

    /* renamed from: ca.canadapost.module.findrate.e$e, reason: collision with other inner class name */
    /* loaded from: classes4.dex */
    static final class C0257e implements androidx.lifecycle.g0, n {

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

        C0257e(dn.l function) {
            kotlin.jvm.internal.t.g(function, "function");
            this.f9349a = function;
        }

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

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

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

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

    /* loaded from: classes4.dex */
    public static final class f extends v implements dn.a {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ androidx.fragment.app.f f9350p;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public f(androidx.fragment.app.f fVar) {
            super(0);
            this.f9350p = fVar;
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final androidx.fragment.app.f invoke() {
            return this.f9350p;
        }
    }

    /* loaded from: classes4.dex */
    public static final class g extends v implements dn.a {

        /* renamed from: p, reason: collision with root package name */
        final /* synthetic */ dn.a f9351p;

        /* renamed from: q, reason: collision with root package name */
        final /* synthetic */ e f9352q;

        /* loaded from: classes4.dex */
        public static final class a implements c1.c {

            /* renamed from: b, reason: collision with root package name */
            final /* synthetic */ e f9353b;

            public a(e eVar) {
                this.f9353b = eVar;
            }

            @Override // androidx.lifecycle.c1.c
            public z0 a(Class modelClass) {
                kotlin.jvm.internal.t.g(modelClass, "modelClass");
                v0 N = this.f9353b.N();
                Bundle arguments = this.f9353b.getArguments();
                Object serializable = arguments != null ? arguments.getSerializable("ARG_DATA_MODEL") : null;
                u0 a10 = N.a(serializable instanceof FindRateDataModel ? (FindRateDataModel) serializable : null);
                kotlin.jvm.internal.t.e(a10, "null cannot be cast to non-null type U of ca.canadapost.core.common.utils.KotlinExtensionsKt.viewModels.<no name provided>.invoke.<no name provided>.create");
                return a10;
            }
        }

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public g(dn.a aVar, e eVar) {
            super(0);
            this.f9351p = aVar;
            this.f9352q = eVar;
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final z0 invoke() {
            return new c1((e1) this.f9351p.invoke(), new a(this.f9352q)).a(u0.class);
        }
    }

    public e() {
        o a10;
        a10 = rm.q.a(new g(new f(this), this));
        this.viewModel = a10;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void Q(FindRateResponseItem findRateResponseItem) {
        O().X(findRateResponseItem);
        O().k0();
        C();
        FindRateDataModel Z = O().Z();
        kotlin.jvm.internal.t.d(Z);
        Bundle a10 = androidx.core.os.c.a(c0.a("ARG_DATA_MODEL", Z.clone()), c0.a("ARG_RESPONSE_ITEM", L().c(FindRateResponseItem.class).h(findRateResponseItem)));
        x().a();
        v4.o B = x4.d.a(this).B();
        boolean z10 = false;
        if (B != null && B.D() == d0.f16009n0) {
            z10 = true;
        }
        if (z10) {
            w.d(x4.d.a(this), d0.f15984b, a10, null, 4, null);
        }
    }

    public void I(h spinnerVM, androidx.fragment.app.f fragment) {
        kotlin.jvm.internal.t.g(spinnerVM, "spinnerVM");
        kotlin.jvm.internal.t.g(fragment, "fragment");
        this.f9338t.b(spinnerVM, fragment);
    }

    public a0 J() {
        return (a0) this.f9337s.b();
    }

    public final ca.a K() {
        ca.a aVar = this.languageService;
        if (aVar != null) {
            return aVar;
        }
        kotlin.jvm.internal.t.y("languageService");
        return null;
    }

    protected final t L() {
        t tVar = this.moshi;
        if (tVar != null) {
            return tVar;
        }
        kotlin.jvm.internal.t.y("moshi");
        return null;
    }

    public final d.a M() {
        d.a aVar = this.pageType;
        if (aVar != null) {
            return aVar;
        }
        kotlin.jvm.internal.t.y("pageType");
        return null;
    }

    protected final v0 N() {
        v0 v0Var = this.rateListViewModelFactory;
        if (v0Var != null) {
            return v0Var;
        }
        kotlin.jvm.internal.t.y("rateListViewModelFactory");
        return null;
    }

    public final u0 O() {
        return (u0) this.viewModel.getValue();
    }

    public View P(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState, u viewLifecycleOwner, z0 viewModel) {
        kotlin.jvm.internal.t.g(inflater, "inflater");
        kotlin.jvm.internal.t.g(viewLifecycleOwner, "viewLifecycleOwner");
        kotlin.jvm.internal.t.g(viewModel, "viewModel");
        return this.f9337s.c(inflater, container, savedInstanceState, viewLifecycleOwner, viewModel);
    }

    public final void R(d.a aVar) {
        kotlin.jvm.internal.t.g(aVar, "<set-?>");
        this.pageType = aVar;
    }

    @Override // ca.canadapost.core.common.navigation.ui.d
    public void b(o8.h0 profileNavigationVMHandler, androidx.fragment.app.k activity, boolean z10) {
        kotlin.jvm.internal.t.g(profileNavigationVMHandler, "profileNavigationVMHandler");
        kotlin.jvm.internal.t.g(activity, "activity");
        this.f9339u.b(profileNavigationVMHandler, activity, z10);
    }

    @Override // w8.p0
    public void c(Activity activity, h.b event) {
        kotlin.jvm.internal.t.g(activity, "activity");
        kotlin.jvm.internal.t.g(event, "event");
        this.f9338t.c(activity, event);
    }

    @Override // ca.canadapost.core.common.navigation.ui.d
    public void f(o8.h0 profileNavigationVMHandler, androidx.fragment.app.f fragment, boolean z10) {
        kotlin.jvm.internal.t.g(profileNavigationVMHandler, "profileNavigationVMHandler");
        kotlin.jvm.internal.t.g(fragment, "fragment");
        this.f9339u.f(profileNavigationVMHandler, fragment, z10);
    }

    @Override // u8.b, androidx.fragment.app.f
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        om.a.b(this);
        if (!O().f0()) {
            O().Y();
        }
        b bVar = new b(this);
        ca.a K = K();
        Context requireContext = requireContext();
        kotlin.jvm.internal.t.f(requireContext, "requireContext(...)");
        this.adapter = new r0(bVar, K, requireContext, (Integer) O().d0().f(), (DateTime) O().c0().f(), (List) O().a0().f(), O().h0());
    }

    @Override // androidx.fragment.app.f
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        kotlin.jvm.internal.t.g(inflater, "inflater");
        u viewLifecycleOwner = getViewLifecycleOwner();
        kotlin.jvm.internal.t.f(viewLifecycleOwner, "getViewLifecycleOwner(...)");
        return P(inflater, container, savedInstanceState, viewLifecycleOwner, O());
    }

    @Override // androidx.fragment.app.f
    public boolean onOptionsItemSelected(MenuItem item) {
        kotlin.jvm.internal.t.g(item, "item");
        if (item.getItemId() != d0.f16031y0) {
            return super.onOptionsItemSelected(item);
        }
        C();
        x4.d.a(this).M(d0.f16029x0);
        return true;
    }

    @Override // u8.b, androidx.fragment.app.f
    public void onViewCreated(View view, Bundle bundle) {
        kotlin.jvm.internal.t.g(view, "view");
        super.onViewCreated(view, bundle);
        I(O(), this);
        d.a.a(this, O(), this, false, 4, null);
        RecyclerView recyclerView = J().A;
        r0 r0Var = this.adapter;
        if (r0Var == null) {
            kotlin.jvm.internal.t.y("adapter");
            r0Var = null;
        }
        recyclerView.setAdapter(r0Var);
        O().b0().j(getViewLifecycleOwner(), new C0257e(new c()));
        O().t().j(getViewLifecycleOwner(), new C0257e(new d()));
    }

    @Override // w8.p0
    public void p(androidx.fragment.app.f fragment, h.b event) {
        kotlin.jvm.internal.t.g(fragment, "fragment");
        kotlin.jvm.internal.t.g(event, "event");
        this.f9338t.p(fragment, event);
    }
}
