package jg;

import android.app.Application;
import android.content.Context;
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.PackageItemModel;
import java.util.LinkedHashMap;
import java.util.Map;

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

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

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

    /* renamed from: e, reason: collision with root package name */
    private final /* synthetic */ l8.i f24696e;

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

    /* renamed from: g, reason: collision with root package name */
    private final androidx.lifecycle.f0 f24698g;

    /* renamed from: h, reason: collision with root package name */
    private final androidx.lifecycle.a0 f24699h;

    /* renamed from: i, reason: collision with root package name */
    private final androidx.lifecycle.f0 f24700i;

    /* renamed from: j, reason: collision with root package name */
    private final androidx.lifecycle.a0 f24701j;

    /* renamed from: k, reason: collision with root package name */
    private final l8.g f24702k;

    /* renamed from: l, reason: collision with root package name */
    private final androidx.lifecycle.a0 f24703l;

    /* renamed from: m, reason: collision with root package name */
    private final androidx.lifecycle.a0 f24704m;

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

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

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f24705p;
            if (i10 == 0) {
                rm.y.b(obj);
                fg.c cVar = r1.this.f24694c;
                PackageItemModel it = this.f24707r;
                kotlin.jvm.internal.t.f(it, "$it");
                this.f24705p = 1;
                obj = cVar.r(it, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                rm.y.b(obj);
            }
            ResultWrapper resultWrapper = (ResultWrapper) obj;
            if (resultWrapper instanceof ResultWrapper.Error) {
                ResultWrapper.Error error = (ResultWrapper.Error) resultWrapper;
                if (error.getError() == RepositoryError.NoNetworkError) {
                    r1.this.a0(new ResultWrapper.Error(error.getException(), error.getMessage(), error.getError(), null, 8, null), true);
                } else {
                    r1.this.f24700i.q(new Event(kotlin.coroutines.jvm.internal.b.a(true)));
                }
            } else {
                r1.this.f24698g.q(new Event(kotlin.coroutines.jvm.internal.b.a(true)));
                LinkedHashMap linkedHashMap = new LinkedHashMap();
                linkedHashMap.put("e.Var3", "FlagNotMine");
                r1 r1Var = r1.this;
                PackageDetailsDTO details = this.f24707r.getDetails();
                linkedHashMap.putAll(r1Var.W(details != null ? kotlin.coroutines.jvm.internal.b.a(details.getReturnPinIndicator()) : null, this.f24707r.isFlaggedAsNotMine()));
                r1.this.f24695d.b("Track_Confirm_Flag_Not_Mine_Adobe", linkedHashMap);
            }
            return rm.n0.f34904a;
        }

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

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public r1(fg.c repository, t7.c contextService, d9.f analyticsService) {
        super((Application) r0);
        kotlin.jvm.internal.t.g(repository, "repository");
        kotlin.jvm.internal.t.g(contextService, "contextService");
        kotlin.jvm.internal.t.g(analyticsService, "analyticsService");
        Context a10 = contextService.a();
        kotlin.jvm.internal.t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f24694c = repository;
        this.f24695d = analyticsService;
        this.f24696e = new l8.i(contextService);
        this.f24697f = new l8.d();
        Boolean bool = Boolean.FALSE;
        androidx.lifecycle.f0 f0Var = new androidx.lifecycle.f0(new Event(bool));
        this.f24698g = f0Var;
        this.f24699h = f0Var;
        androidx.lifecycle.f0 f0Var2 = new androidx.lifecycle.f0(new Event(bool));
        this.f24700i = f0Var2;
        this.f24701j = f0Var2;
        l8.g gVar = new l8.g();
        this.f24702k = gVar;
        this.f24703l = gVar;
        this.f24704m = repository.s();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final Map W(Boolean bool, boolean z10) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("e.Var13", kotlin.jvm.internal.t.b(bool, Boolean.TRUE) ? "Return to sender - Available" : "Return to sender - N/A");
        linkedHashMap.put("e.Var88", z10 ? "Flag PIN as - Not Mine" : "Flag PIN as - Not Flagged");
        return linkedHashMap;
    }

    @Override // l8.h
    public androidx.lifecycle.a0 J() {
        return this.f24696e.J();
    }

    public final void V() {
        PackageItemModel packageItemModel = (PackageItemModel) this.f24694c.c().f();
        if (packageItemModel == null || packageItemModel.isFlaggedAsNotMine()) {
            return;
        }
        tp.k.d(androidx.lifecycle.a1.a(this), null, null, new a(packageItemModel, null), 3, null);
    }

    public final androidx.lifecycle.a0 X() {
        return this.f24703l;
    }

    public final androidx.lifecycle.a0 Y() {
        return this.f24704m;
    }

    public final androidx.lifecycle.a0 Z() {
        return this.f24699h;
    }

    public void a0(ResultWrapper.Error error, boolean z10) {
        kotlin.jvm.internal.t.g(error, "error");
        this.f24697f.a(error, z10);
    }

    public final androidx.lifecycle.a0 b0() {
        return this.f24701j;
    }

    public final void c0() {
        PackageItemModel packageItemModel = (PackageItemModel) this.f24694c.c().f();
        if (packageItemModel != null) {
            d9.f fVar = this.f24695d;
            PackageDetailsDTO details = packageItemModel.getDetails();
            fVar.c("Track_Select_Flag_Not_Mine_Adobe", W(details != null ? Boolean.valueOf(details.getReturnPinIndicator()) : null, packageItemModel.isFlaggedAsNotMine()));
        }
    }

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

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

    @Override // l8.h
    public tp.u1 u(tp.m0 m0Var, vm.g context, tp.o0 start, String str, dn.p block) {
        kotlin.jvm.internal.t.g(m0Var, "<this>");
        kotlin.jvm.internal.t.g(context, "context");
        kotlin.jvm.internal.t.g(start, "start");
        kotlin.jvm.internal.t.g(block, "block");
        return this.f24696e.u(m0Var, context, start, str, block);
    }
}
