package ca.canadapost.module.customsform;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.k;
import androidx.fragment.app.p0;
import androidx.lifecycle.c1;
import androidx.lifecycle.d1;
import androidx.lifecycle.e1;
import androidx.lifecycle.g0;
import androidx.lifecycle.u;
import androidx.lifecycle.z0;
import ca.canadapost.core.data.db.cupboard.model.CustomsFormObject;
import ca.canadapost.module.customsform.CustomsFormFragment;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import dn.p;
import ib.b1;
import ib.q0;
import ib.t0;
import ib.x0;
import ib.y0;
import java.util.List;
import kotlin.Metadata;
import kotlin.coroutines.jvm.internal.l;
import kotlin.jvm.internal.n;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import rm.n0;
import rm.o;
import rm.y;
import tp.a1;
import tp.i0;
import tp.m0;
import u7.x;
import w8.d0;
import w8.j0;
import w8.w;

@Metadata(d1 = {"\u0000b\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0000\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\u0002\b\u0006\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\n\b\u0007\u0018\u00002\u00020\u00012\b\u0012\u0004\u0012\u00020\u00030\u0002B\u0007¢\u0006\u0004\b9\u0010:J\u0010\u0010\u0007\u001a\u00020\u00062\u0006\u0010\u0005\u001a\u00020\u0004H\u0002J5\u0010\u0013\u001a\u00020\u00122\u0006\u0010\t\u001a\u00020\b2\b\u0010\u000b\u001a\u0004\u0018\u00010\n2\b\u0010\r\u001a\u0004\u0018\u00010\f2\u0006\u0010\u000f\u001a\u00020\u000e2\u0006\u0010\u0011\u001a\u00020\u0010H\u0096\u0001J\u0012\u0010\u0014\u001a\u00020\u00062\b\u0010\r\u001a\u0004\u0018\u00010\fH\u0016J\b\u0010\u0015\u001a\u00020\u0006H\u0016J$\u0010\u0016\u001a\u00020\u00122\u0006\u0010\t\u001a\u00020\b2\b\u0010\u000b\u001a\u0004\u0018\u00010\n2\b\u0010\r\u001a\u0004\u0018\u00010\fH\u0016J\u001a\u0010\u0018\u001a\u00020\u00062\u0006\u0010\u0017\u001a\u00020\u00122\b\u0010\r\u001a\u0004\u0018\u00010\fH\u0016R\"\u0010 \u001a\u00020\u00198\u0004@\u0004X\u0085.¢\u0006\u0012\n\u0004\b\u001a\u0010\u001b\u001a\u0004\b\u001c\u0010\u001d\"\u0004\b\u001e\u0010\u001fR\"\u0010(\u001a\u00020!8\u0004@\u0004X\u0085.¢\u0006\u0012\n\u0004\b\"\u0010#\u001a\u0004\b$\u0010%\"\u0004\b&\u0010'R\"\u00100\u001a\u00020)8\u0004@\u0004X\u0085.¢\u0006\u0012\n\u0004\b*\u0010+\u001a\u0004\b,\u0010-\"\u0004\b.\u0010/R\u001b\u0010\u0011\u001a\u0002018BX\u0082\u0084\u0002¢\u0006\f\n\u0004\b2\u00103\u001a\u0004\b4\u00105R\u0014\u00108\u001a\u00020\u00038\u0016X\u0096\u0005¢\u0006\u0006\u001a\u0004\b6\u00107¨\u0006;"}, d2 = {"Lca/canadapost/module/customsform/CustomsFormFragment;", "Lu8/b;", "", "Ljb/g;", "Lca/canadapost/core/data/db/cupboard/model/CustomsFormObject;", "customsFormObject", "Lrm/n0;", "K", "Landroid/view/LayoutInflater;", "inflater", "Landroid/view/ViewGroup;", "container", "Landroid/os/Bundle;", "savedInstanceState", "Landroidx/lifecycle/u;", "viewLifecycleOwner", "Landroidx/lifecycle/z0;", "viewModel", "Landroid/view/View;", "O", "onCreate", "onResume", "onCreateView", "view", "onViewCreated", "Lt7/c;", "t", "Lt7/c;", "getContextService", "()Lt7/c;", "setContextService", "(Lt7/c;)V", "contextService", "Ld9/f;", "u", "Ld9/f;", "getAnalyticsService", "()Ld9/f;", "setAnalyticsService", "(Ld9/f;)V", "analyticsService", "Lib/t0;", "v", "Lib/t0;", "M", "()Lib/t0;", "setCustomsFormQRCodeService", "(Lib/t0;)V", "customsFormQRCodeService", "Lib/q0;", "w", "Lrm/o;", "N", "()Lib/q0;", "L", "()Ljb/g;", "binding", "<init>", "()V", "customsform_productionRelease"}, k = 1, mv = {1, 9, 0})
/* loaded from: classes4.dex */
public final class CustomsFormFragment extends u8.b {

    /* renamed from: t, reason: collision with root package name and from kotlin metadata */
    protected t7.c contextService;

    /* renamed from: u, reason: collision with root package name and from kotlin metadata */
    protected d9.f analyticsService;

    /* renamed from: v, reason: collision with root package name and from kotlin metadata */
    protected t0 customsFormQRCodeService;

    /* renamed from: s, reason: collision with root package name */
    private final /* synthetic */ x f8332s = new x(y0.f23126h);

    /* renamed from: w, reason: collision with root package name and from kotlin metadata */
    private final o viewModel = p0.a(this, kotlin.jvm.internal.p0.b(q0.class), new h(new g(this)), new i());

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

        /* renamed from: p, reason: collision with root package name */
        int f8337p;

        /* renamed from: r, reason: collision with root package name */
        final /* synthetic */ Bitmap f8339r;

        /* JADX INFO: Access modifiers changed from: package-private */
        /* renamed from: ca.canadapost.module.customsform.CustomsFormFragment$a$a, reason: collision with other inner class name */
        /* loaded from: classes4.dex */
        public static final class C0219a extends l implements p {

            /* renamed from: p, reason: collision with root package name */
            int f8340p;

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

            /* renamed from: r, reason: collision with root package name */
            final /* synthetic */ Bitmap f8342r;

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            C0219a(CustomsFormFragment customsFormFragment, Bitmap bitmap, vm.d dVar) {
                super(2, dVar);
                this.f8341q = customsFormFragment;
                this.f8342r = bitmap;
            }

            @Override // kotlin.coroutines.jvm.internal.a
            public final vm.d create(Object obj, vm.d dVar) {
                return new C0219a(this.f8341q, this.f8342r, dVar);
            }

            @Override // kotlin.coroutines.jvm.internal.a
            public final Object invokeSuspend(Object obj) {
                Object f10;
                f10 = wm.d.f();
                int i10 = this.f8340p;
                if (i10 == 0) {
                    y.b(obj);
                    Context requireContext = this.f8341q.requireContext();
                    t.f(requireContext, "requireContext(...)");
                    Bitmap bitmap = this.f8342r;
                    this.f8340p = 1;
                    obj = w8.t.a(requireContext, bitmap, this);
                    if (obj == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    y.b(obj);
                }
                return obj;
            }

            @Override // dn.p
            public final Object invoke(m0 m0Var, vm.d dVar) {
                return ((C0219a) create(m0Var, dVar)).invokeSuspend(n0.f34904a);
            }
        }

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        a(Bitmap bitmap, vm.d dVar) {
            super(2, dVar);
            this.f8339r = bitmap;
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final vm.d create(Object obj, vm.d dVar) {
            return new a(this.f8339r, dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f8337p;
            if (i10 == 0) {
                y.b(obj);
                i0 b10 = a1.b();
                C0219a c0219a = new C0219a(CustomsFormFragment.this, this.f8339r, null);
                this.f8337p = 1;
                obj = tp.i.g(b10, c0219a, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            Uri uri = (Uri) obj;
            if (uri != null) {
                CustomsFormFragment customsFormFragment = CustomsFormFragment.this;
                Intent intent = new Intent("android.intent.action.SEND");
                intent.setType("image/png");
                intent.addFlags(1);
                intent.putExtra("android.intent.extra.STREAM", uri);
                customsFormFragment.startActivity(Intent.createChooser(intent, customsFormFragment.getString(b1.f22624y0)));
            }
            return n0.f34904a;
        }

        @Override // dn.p
        public final Object invoke(m0 m0Var, vm.d dVar) {
            return ((a) create(m0Var, dVar)).invokeSuspend(n0.f34904a);
        }
    }

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

        public final void a(List list) {
            if (list != null) {
                CustomsFormFragment customsFormFragment = CustomsFormFragment.this;
                if (!(!list.isEmpty())) {
                    customsFormFragment.N().u0();
                    return;
                }
                j0.a aVar = j0.f40981a;
                k requireActivity = customsFormFragment.requireActivity();
                t.f(requireActivity, "requireActivity(...)");
                aVar.d(requireActivity);
            }
        }

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

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

        public final void a(n0 n0Var) {
            w.d(x4.d.a(CustomsFormFragment.this), x0.f23092b, null, null, 6, null);
        }

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

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

        public final void a(n0 n0Var) {
            w.d(x4.d.a(CustomsFormFragment.this), x0.f23090a, null, null, 6, null);
        }

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

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

        public final void a(CustomsFormObject customsFormObject) {
            if (customsFormObject != null) {
                CustomsFormFragment.this.K(customsFormObject);
            }
        }

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

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

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

        f(dn.l function) {
            t.g(function, "function");
            this.f8347a = function;
        }

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

        @Override // androidx.lifecycle.g0
        public final /* synthetic */ void d(Object obj) {
            this.f8347a.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();
        }
    }

    /* 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 */ androidx.fragment.app.f f8348p;

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

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

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

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public h(dn.a aVar) {
            super(0);
            this.f8349p = aVar;
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final d1 invoke() {
            d1 viewModelStore = ((e1) this.f8349p.invoke()).getViewModelStore();
            t.f(viewModelStore, "ownerProducer().viewModelStore");
            return viewModelStore;
        }
    }

    /* loaded from: classes4.dex */
    static final class i extends v implements dn.a {
        i() {
            super(0);
        }

        @Override // dn.a
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final c1.c invoke() {
            return CustomsFormFragment.this.y();
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void K(CustomsFormObject customsFormObject) {
        Bitmap c10 = M().c(M().b(N().l0(customsFormObject)), 200, 200);
        if (c10 != null) {
            tp.k.d(androidx.lifecycle.v.a(this), null, null, new a(c10, null), 3, null);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final q0 N() {
        return (q0) this.viewModel.getValue();
    }

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

    public jb.g L() {
        return (jb.g) this.f8332s.b();
    }

    protected final t0 M() {
        t0 t0Var = this.customsFormQRCodeService;
        if (t0Var != null) {
            return t0Var;
        }
        t.y("customsFormQRCodeService");
        return null;
    }

    public View O(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState, u viewLifecycleOwner, z0 viewModel) {
        t.g(inflater, "inflater");
        t.g(viewLifecycleOwner, "viewLifecycleOwner");
        t.g(viewModel, "viewModel");
        return this.f8332s.c(inflater, container, savedInstanceState, viewLifecycleOwner, viewModel);
    }

    @Override // u8.b, androidx.fragment.app.f
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setHasOptionsMenu(true);
    }

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

    @Override // u8.b, androidx.fragment.app.f
    public void onResume() {
        super.onResume();
        N().c0();
    }

    @Override // u8.b, androidx.fragment.app.f
    public void onViewCreated(View view, Bundle bundle) {
        t.g(view, "view");
        super.onViewCreated(view, bundle);
        N().o0().j(getViewLifecycleOwner(), new f(new b()));
        N().q0().j(getViewLifecycleOwner(), new f(new c()));
        N().p0().j(getViewLifecycleOwner(), new f(new d()));
        N().r0().j(getViewLifecycleOwner(), new f(new e()));
        L().D.B.setOnClickListener(new View.OnClickListener() { // from class: ib.k
            @Override // android.view.View.OnClickListener
            public final void onClick(View view2) {
                CustomsFormFragment.P(CustomsFormFragment.this, view2);
            }
        });
        FloatingActionButton cpcCustomGenerateAddParcel = L().A;
        t.f(cpcCustomGenerateAddParcel, "cpcCustomGenerateAddParcel");
        d0.g(cpcCustomGenerateAddParcel);
    }
}
