package ca.canadapost.module.track.views;

import android.app.Application;
import android.content.Context;
import androidx.lifecycle.a0;
import androidx.lifecycle.a1;
import androidx.lifecycle.f0;
import ca.canadapost.core.data.model.Event;
import ca.canadapost.core.data.model.RepositoryError;
import ca.canadapost.core.data.model.ResultWrapper;
import ca.canadapost.module.track.model.PackageDetailsDTO;
import ca.canadapost.module.track.model.PackageDutyAndTaxesCommitDutiesPaymentResponse;
import ca.canadapost.module.track.model.PackageItemModel;
import ca.canadapost.module.track.views.PackageDTCreateCPWAViewModel;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.android.gms.common.Scopes;
import com.google.firebase.remoteconfig.RemoteConfigConstants;
import d9.f;
import java.util.HashMap;
import java.util.LinkedHashMap;
import jg.w3;
import kotlin.Metadata;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import rm.n0;
import rm.y;
import tp.m0;
import w8.p;
import w8.r;

/* loaded from: classes4.dex */
public final class PackageDTCreateCPWAViewModel extends androidx.lifecycle.b implements l8.c {

    /* renamed from: c, reason: collision with root package name */
    private final t7.c f10911c;

    /* renamed from: d, reason: collision with root package name */
    private final o9.c f10912d;

    /* renamed from: e, reason: collision with root package name */
    private final fg.c f10913e;

    /* renamed from: f, reason: collision with root package name */
    private final d9.f f10914f;

    /* renamed from: g, reason: collision with root package name */
    private final ca.b f10915g;

    /* renamed from: h, reason: collision with root package name */
    private final r f10916h;

    /* renamed from: i, reason: collision with root package name */
    private final ja.d f10917i;

    /* renamed from: j, reason: collision with root package name */
    private final p f10918j;

    /* renamed from: k, reason: collision with root package name */
    private final gg.a f10919k;

    /* renamed from: l, reason: collision with root package name */
    private final g9.d f10920l;

    /* renamed from: m, reason: collision with root package name */
    private final /* synthetic */ l8.d f10921m;

    /* renamed from: n, reason: collision with root package name */
    private final f0 f10922n;

    /* renamed from: o, reason: collision with root package name */
    private final f0 f10923o;

    /* renamed from: p, reason: collision with root package name */
    private PackageItemModel f10924p;

    /* renamed from: q, reason: collision with root package name */
    private w3 f10925q;

    /* renamed from: r, reason: collision with root package name */
    private final f0 f10926r;

    /* renamed from: s, reason: collision with root package name */
    private final a0 f10927s;

    /* renamed from: t, reason: collision with root package name */
    private final f0 f10928t;

    /* renamed from: u, reason: collision with root package name */
    private final a0 f10929u;

    @JsonIgnoreProperties(ignoreUnknown = true)
    @Metadata(d1 = {"\u0000\u0014\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\u000b\b\u0007\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002R\u001c\u0010\u0003\u001a\u0004\u0018\u00010\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0005\u0010\u0006\"\u0004\b\u0007\u0010\bR\u001c\u0010\t\u001a\u0004\u0018\u00010\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\n\u0010\u0006\"\u0004\b\u000b\u0010\bR\u001c\u0010\f\u001a\u0004\u0018\u00010\u0004X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\r\u0010\u0006\"\u0004\b\u000e\u0010\b¨\u0006\u000f"}, d2 = {"Lca/canadapost/module/track/views/PackageDTCreateCPWAViewModel$CPWAWebData;", "", "()V", "event", "", "getEvent", "()Ljava/lang/String;", "setEvent", "(Ljava/lang/String;)V", "payload", "getPayload", "setPayload", "rs", "getRs", "setRs", "track_productionRelease"}, k = 1, mv = {1, 9, 0}, xi = 48)
    /* loaded from: classes4.dex */
    public static final class CPWAWebData {
        private String event;
        private String payload;
        private String rs;

        public final String getEvent() {
            return this.event;
        }

        public final String getPayload() {
            return this.payload;
        }

        public final String getRs() {
            return this.rs;
        }

        public final void setEvent(String str) {
            this.event = str;
        }

        public final void setPayload(String str) {
            this.payload = str;
        }

        public final void setRs(String str) {
            this.rs = str;
        }
    }

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

        /* renamed from: a, reason: collision with root package name */
        private final HashMap f10930a;

        public a(String str, Double d10, String str2, String str3, String str4, String str5, String str6) {
            HashMap hashMap = new HashMap();
            this.f10930a = hashMap;
            hashMap.put(RemoteConfigConstants.RequestFieldKey.APP_ID, "MOBILE");
            HashMap hashMap2 = new HashMap();
            hashMap2.put("language", str6);
            HashMap hashMap3 = new HashMap();
            hashMap3.put("emailAddr", str);
            hashMap2.put(Scopes.EMAIL, hashMap3);
            hashMap.put("user", hashMap2);
            HashMap hashMap4 = new HashMap();
            hashMap4.put("transType", "D_T");
            hashMap4.put("value", d10);
            HashMap[] hashMapArr = new HashMap[2];
            HashMap hashMap5 = new HashMap();
            hashMapArr[0] = hashMap5;
            hashMap5.put("pinType", "cu_pin");
            HashMap hashMap6 = hashMapArr[0];
            if (hashMap6 != null) {
                t.e(str2, "null cannot be cast to non-null type kotlin.Any");
                hashMap6.put("pinValue", str2);
            }
            HashMap hashMap7 = new HashMap();
            hashMapArr[1] = hashMap7;
            hashMap7.put("pinType", "foreign_pin");
            HashMap hashMap8 = hashMapArr[1];
            if (hashMap8 != null) {
                t.e(str3, "null cannot be cast to non-null type kotlin.Any");
                hashMap8.put("pinValue", str3);
            }
            hashMap4.put("references", hashMapArr);
            HashMap hashMap9 = new HashMap();
            hashMap9.put("pymtType", "credit_card");
            hashMap9.put("encryptedPymtResult", str4);
            hashMap9.put("origEncryptedPayload", str5);
            hashMap4.put("pymt", hashMap9);
            hashMap.put("trans", hashMap4);
        }

        public final HashMap a() {
            return this.f10930a;
        }
    }

    /* loaded from: classes4.dex */
    static final class b extends kotlin.coroutines.jvm.internal.l implements dn.p {

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

        /* renamed from: q, reason: collision with root package name */
        private /* synthetic */ Object f10932q;

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ a f10934s;

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

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

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

            /* JADX INFO: Access modifiers changed from: package-private */
            /* renamed from: ca.canadapost.module.track.views.PackageDTCreateCPWAViewModel$b$a$a, reason: collision with other inner class name */
            /* loaded from: classes4.dex */
            public static final class C0270a extends kotlin.coroutines.jvm.internal.l implements dn.p {

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

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

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

                /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
                C0270a(PackageDTCreateCPWAViewModel packageDTCreateCPWAViewModel, PackageItemModel packageItemModel, vm.d dVar) {
                    super(2, dVar);
                    this.f10938q = packageDTCreateCPWAViewModel;
                    this.f10939r = packageItemModel;
                }

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

                @Override // kotlin.coroutines.jvm.internal.a
                public final Object invokeSuspend(Object obj) {
                    Object f10;
                    f10 = wm.d.f();
                    int i10 = this.f10937p;
                    if (i10 == 0) {
                        y.b(obj);
                        fg.c X = this.f10938q.X();
                        PackageItemModel packageItemModel = this.f10939r;
                        this.f10937p = 1;
                        if (X.x(packageItemModel, this) == f10) {
                            return f10;
                        }
                    } else {
                        if (i10 != 1) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        y.b(obj);
                    }
                    return n0.f34904a;
                }

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

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            a(PackageDTCreateCPWAViewModel packageDTCreateCPWAViewModel, m0 m0Var) {
                super(1);
                this.f10935p = packageDTCreateCPWAViewModel;
                this.f10936q = m0Var;
            }

            /* JADX INFO: Access modifiers changed from: private */
            public static final void g(PackageDTCreateCPWAViewModel this$0) {
                PackageItemModel G0;
                t.g(this$0, "this$0");
                o9.c U = this$0.U();
                if (U != null) {
                    w3 a02 = this$0.a0();
                    U.c(new bg.c((a02 == null || (G0 = a02.G0()) == null) ? null : G0.getItemNumber(), Boolean.FALSE));
                }
            }

            /* JADX INFO: Access modifiers changed from: private */
            public static final void h(PackageDTCreateCPWAViewModel this$0) {
                PackageItemModel G0;
                t.g(this$0, "this$0");
                o9.c U = this$0.U();
                if (U != null) {
                    w3 a02 = this$0.a0();
                    U.c(new bg.c((a02 == null || (G0 = a02.G0()) == null) ? null : G0.getItemNumber(), Boolean.FALSE));
                }
            }

            /* JADX INFO: Access modifiers changed from: private */
            public static final void i(PackageDTCreateCPWAViewModel this$0) {
                t.g(this$0, "this$0");
                this$0.R();
            }

            public final void d(PackageItemModel packageItemModel) {
                LinkedHashMap linkedHashMap = new LinkedHashMap();
                linkedHashMap.put("e.Var17", this.f10935p.Y().h() ? "registered" : "anonymous");
                linkedHashMap.put("e.Var13", "Duty and Taxes paid credit card Confirmation");
                this.f10935p.S().b("Duty_and_taxes_Paid_credit_card_click_Adobe", linkedHashMap);
                if (packageItemModel != null) {
                    m0 m0Var = this.f10936q;
                    tp.k.d(m0Var, m0Var.getCoroutineContext(), null, new C0270a(this.f10935p, packageItemModel, null), 2, null);
                }
                p T = this.f10935p.T();
                final PackageDTCreateCPWAViewModel packageDTCreateCPWAViewModel = this.f10935p;
                T.b(new Runnable() { // from class: ca.canadapost.module.track.views.b
                    @Override // java.lang.Runnable
                    public final void run() {
                        PackageDTCreateCPWAViewModel.b.a.g(PackageDTCreateCPWAViewModel.this);
                    }
                }, 1000L);
                p T2 = this.f10935p.T();
                final PackageDTCreateCPWAViewModel packageDTCreateCPWAViewModel2 = this.f10935p;
                T2.b(new Runnable() { // from class: ca.canadapost.module.track.views.c
                    @Override // java.lang.Runnable
                    public final void run() {
                        PackageDTCreateCPWAViewModel.b.a.h(PackageDTCreateCPWAViewModel.this);
                    }
                }, 30000L);
                p T3 = this.f10935p.T();
                final PackageDTCreateCPWAViewModel packageDTCreateCPWAViewModel3 = this.f10935p;
                T3.b(new Runnable() { // from class: ca.canadapost.module.track.views.d
                    @Override // java.lang.Runnable
                    public final void run() {
                        PackageDTCreateCPWAViewModel.b.a.i(PackageDTCreateCPWAViewModel.this);
                    }
                }, 100L);
            }

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

        /* JADX INFO: Access modifiers changed from: package-private */
        /* renamed from: ca.canadapost.module.track.views.PackageDTCreateCPWAViewModel$b$b, reason: collision with other inner class name */
        /* loaded from: classes4.dex */
        public static final class C0271b extends v implements dn.a {

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

            /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
            C0271b(PackageDTCreateCPWAViewModel packageDTCreateCPWAViewModel) {
                super(0);
                this.f10940p = packageDTCreateCPWAViewModel;
            }

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

            /* renamed from: invoke, reason: collision with other method in class */
            public final void m180invoke() {
                this.f10940p.R();
            }
        }

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            m0 m0Var;
            f10 = wm.d.f();
            int i10 = this.f10931p;
            if (i10 == 0) {
                y.b(obj);
                m0 m0Var2 = (m0) this.f10932q;
                fg.c X = PackageDTCreateCPWAViewModel.this.X();
                String c10 = PackageDTCreateCPWAViewModel.this.W().c();
                HashMap a10 = this.f10934s.a();
                this.f10932q = m0Var2;
                this.f10931p = 1;
                Object D = X.D(c10, a10, this);
                if (D == f10) {
                    return f10;
                }
                m0Var = m0Var2;
                obj = D;
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                m0Var = (m0) this.f10932q;
                y.b(obj);
            }
            ResultWrapper resultWrapper = (ResultWrapper) obj;
            if (resultWrapper instanceof ResultWrapper.Success) {
                ResultWrapper.Success success = (ResultWrapper.Success) resultWrapper;
                if (qa.d.h(((PackageDutyAndTaxesCommitDutiesPaymentResponse) success.getData()).getProofOfPymt())) {
                    PackageDTCreateCPWAViewModel.this.c0(new ResultWrapper.Error(null, null, RepositoryError.ServiceError, null, 8, null), true);
                }
                gg.a b02 = PackageDTCreateCPWAViewModel.this.b0();
                if (b02 != null) {
                    b02.a(PackageDTCreateCPWAViewModel.this.a0(), (PackageDutyAndTaxesCommitDutiesPaymentResponse) success.getData(), new a(PackageDTCreateCPWAViewModel.this, m0Var), new C0271b(PackageDTCreateCPWAViewModel.this));
                }
            } else if (resultWrapper instanceof ResultWrapper.Error) {
                LinkedHashMap linkedHashMap = new LinkedHashMap();
                linkedHashMap.put("e.Var17", PackageDTCreateCPWAViewModel.this.Y().h() ? "registered" : "anonymous");
                linkedHashMap.put("e.Var13", "Duty and Taxes paid credit card Failure");
                PackageDTCreateCPWAViewModel.this.S().b("Duty_and_taxes_Paid_credit_card_click_Adobe", linkedHashMap);
                PackageDTCreateCPWAViewModel.this.c0((ResultWrapper.Error) resultWrapper, true);
                PackageDTCreateCPWAViewModel.this.R();
            }
            return n0.f34904a;
        }

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

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public PackageDTCreateCPWAViewModel(t7.c cVar, o9.c cpEventBus, fg.c repository, d9.f analyticsService, ca.b languageService, r shareDataService, ja.d sharedPreferencesService, p appExecutors, gg.a aVar, g9.d sessionRepository) {
        super((Application) r1);
        t.g(cpEventBus, "cpEventBus");
        t.g(repository, "repository");
        t.g(analyticsService, "analyticsService");
        t.g(languageService, "languageService");
        t.g(shareDataService, "shareDataService");
        t.g(sharedPreferencesService, "sharedPreferencesService");
        t.g(appExecutors, "appExecutors");
        t.g(sessionRepository, "sessionRepository");
        Context a10 = cVar != null ? cVar.a() : null;
        t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f10911c = cVar;
        this.f10912d = cpEventBus;
        this.f10913e = repository;
        this.f10914f = analyticsService;
        this.f10915g = languageService;
        this.f10916h = shareDataService;
        this.f10917i = sharedPreferencesService;
        this.f10918j = appExecutors;
        this.f10919k = aVar;
        this.f10920l = sessionRepository;
        this.f10921m = new l8.d();
        this.f10922n = new f0();
        Boolean bool = Boolean.FALSE;
        this.f10923o = new f0(bool);
        f0 f0Var = new f0(new Event(bool));
        this.f10926r = f0Var;
        this.f10927s = f0Var;
        f0 f0Var2 = new f0();
        this.f10928t = f0Var2;
        this.f10929u = f0Var2;
        if (analyticsService != null) {
            f.a.c(analyticsService, "Duty and Taxes Payment Info", null, 2, null);
        }
        if (shareDataService.a("TRACK_SHARE_DATA_TRACK__DETAIL_SELECTED_ITEM")) {
            w3 w3Var = (w3) shareDataService.e("TRACK_SHARE_DATA_TRACK__DETAIL_SELECTED_ITEM");
            this.f10925q = w3Var;
            this.f10924p = w3Var != null ? w3Var.G0() : null;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void R() {
        this.f10926r.q(new Event(Boolean.TRUE));
    }

    public final d9.f S() {
        return this.f10914f;
    }

    public final p T() {
        return this.f10918j;
    }

    public final o9.c U() {
        return this.f10912d;
    }

    public final a0 V() {
        return this.f10927s;
    }

    public final ca.b W() {
        return this.f10915g;
    }

    public final fg.c X() {
        return this.f10913e;
    }

    public final g9.d Y() {
        return this.f10920l;
    }

    public final a0 Z() {
        return this.f10929u;
    }

    public final w3 a0() {
        return this.f10925q;
    }

    public final gg.a b0() {
        return this.f10919k;
    }

    public void c0(ResultWrapper.Error error, boolean z10) {
        t.g(error, "error");
        this.f10921m.a(error, z10);
    }

    public final void d0(CPWAWebData cPWAWebData) {
        PackageItemModel G0;
        PackageItemModel G02;
        PackageItemModel G03;
        PackageItemModel G04;
        PackageDetailsDTO details;
        f0 a02;
        PackageItemModel G05;
        if (cPWAWebData == null || qa.d.h(cPWAWebData.getPayload())) {
            d9.f fVar = this.f10914f;
            if (fVar != null) {
                fVar.b("Duty and Taxes common web declined/failed credit cards", null);
                return;
            }
            return;
        }
        d9.f fVar2 = this.f10914f;
        if (fVar2 != null) {
            fVar2.b("Duty_and_taxes_Paid_credit_card_click_Adobe", null);
        }
        w3 w3Var = this.f10925q;
        PackageItemModel G06 = w3Var != null ? w3Var.G0() : null;
        if (G06 != null) {
            G06.setDutyAndTaxesCPWAPayload(cPWAWebData.getPayload());
        }
        w3 w3Var2 = this.f10925q;
        String dutyAndTaxesEmail = (w3Var2 == null || (G05 = w3Var2.G0()) == null) ? null : G05.getDutyAndTaxesEmail();
        w3 w3Var3 = this.f10925q;
        Double d10 = (w3Var3 == null || (a02 = w3Var3.a0()) == null) ? null : (Double) a02.f();
        w3 w3Var4 = this.f10925q;
        String cuPin = (w3Var4 == null || (G04 = w3Var4.G0()) == null || (details = G04.getDetails()) == null) ? null : details.getCuPin();
        w3 w3Var5 = this.f10925q;
        String itemNumber = (w3Var5 == null || (G03 = w3Var5.G0()) == null) ? null : G03.getItemNumber();
        w3 w3Var6 = this.f10925q;
        String dutyAndTaxesCPWAPayload = (w3Var6 == null || (G02 = w3Var6.G0()) == null) ? null : G02.getDutyAndTaxesCPWAPayload();
        w3 w3Var7 = this.f10925q;
        tp.k.d(a1.a(this), null, null, new b(new a(dutyAndTaxesEmail, d10, cuPin, itemNumber, dutyAndTaxesCPWAPayload, (w3Var7 == null || (G0 = w3Var7.G0()) == null) ? null : G0.getDutyAndTaxesPaymentPayload(), this.f10915g.c()), null), 3, null);
    }

    @Override // l8.c
    public a0 o() {
        return this.f10921m.o();
    }

    @Override // l8.c
    public a0 t() {
        return this.f10921m.t();
    }
}
