package wb;

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.ResultWrapper;
import ca.canadapost.core.data.mymail.model.MyMailStatus;
import ca.canadapost.core.data.mymail.model.MyMailSubscriptionResponse;
import ca.canadapost.core.data.mymail.model.Preferences;
import ca.canadapost.core.data.profile.model.AMSPrerequisitesResponse;
import ca.canadapost.core.data.profile.model.EmailNotificationPreferenceItems;
import ca.canadapost.core.data.profile.model.SetForgetPreferenceResponse;
import d9.f;
import java.util.ArrayList;
import kotlin.jvm.internal.g0;
import kotlin.jvm.internal.p0;
import kotlin.jvm.internal.v;
import l8.h;
import rm.n0;
import rm.y;
import tp.m0;
import tp.o0;
import tp.t0;
import tp.u1;

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

    /* renamed from: x, reason: collision with root package name */
    static final /* synthetic */ kn.l[] f48979x = {p0.h(new g0(i.class, "doubleClickGuard", "getDoubleClickGuard()Z", 0))};

    /* renamed from: y, reason: collision with root package name */
    public static final int f48980y = 8;

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

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

    /* renamed from: e, reason: collision with root package name */
    private final ka.b f48983e;

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

    /* renamed from: g, reason: collision with root package name */
    private final p8.a f48985g;

    /* renamed from: h, reason: collision with root package name */
    private final fa.a f48986h;

    /* renamed from: i, reason: collision with root package name */
    private final p9.h f48987i;

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

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

    /* renamed from: l, reason: collision with root package name */
    private final l8.e f48990l;

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

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

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

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

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

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

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

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

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

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

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

    /* 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 f49002p;

        a(vm.d dVar) {
            super(2, dVar);
        }

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f49002p;
            if (i10 == 0) {
                y.b(obj);
                if (i.this.f48985g.a() && i.this.f48985g.b(z7.c.MYMAIL) && i.this.f48986h.u()) {
                    fa.a aVar = i.this.f48986h;
                    this.f49002p = 1;
                    if (aVar.e(this) == f10) {
                        return f10;
                    }
                } else {
                    fa.a aVar2 = i.this.f48986h;
                    this.f49002p = 2;
                    if (aVar2.C(this) == f10) {
                        return f10;
                    }
                }
            } else {
                if (i10 != 1 && i10 != 2) {
                    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 ((a) create(m0Var, dVar)).invokeSuspend(n0.f34904a);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class b extends kotlin.coroutines.jvm.internal.d {

        /* renamed from: p, reason: collision with root package name */
        Object f49004p;

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

        /* renamed from: s, reason: collision with root package name */
        int f49007s;

        b(vm.d dVar) {
            super(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f49005q = obj;
            this.f49007s |= Integer.MIN_VALUE;
            return i.this.f0(this);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class c extends kotlin.coroutines.jvm.internal.d {

        /* renamed from: p, reason: collision with root package name */
        Object f49008p;

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

        /* renamed from: s, reason: collision with root package name */
        int f49011s;

        c(vm.d dVar) {
            super(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f49009q = obj;
            this.f49011s |= Integer.MIN_VALUE;
            return i.this.g0(this);
        }
    }

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

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

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m469invoke() {
            if (i.this.h0()) {
                return;
            }
            f.a.a(i.this.f48981c, "update_pushnotificationsclick_Adobe", null, 2, null);
            i.this.f49000v.s();
        }
    }

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

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

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m470invoke() {
            if (i.this.h0()) {
                return;
            }
            i.this.f48981c.b("update_emailnotificationsclick_Adobe", d9.e.f15943f.a("Notifications"));
            i.this.f48998t.q(i.this.f48997s);
        }
    }

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

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

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m471invoke() {
            if (i.this.h0()) {
                return;
            }
            if (i.this.f48984f.h()) {
                i.this.f48993o.s();
            } else {
                i.this.f48995q.s();
            }
        }
    }

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

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

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

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

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

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

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

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

            @Override // kotlin.coroutines.jvm.internal.a
            public final Object invokeSuspend(Object obj) {
                Object f10;
                f10 = wm.d.f();
                int i10 = this.f49018p;
                if (i10 == 0) {
                    y.b(obj);
                    if (this.f49019q.p0()) {
                        i iVar = this.f49019q;
                        this.f49018p = 1;
                        if (iVar.g0(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 ((a) create(m0Var, dVar)).invokeSuspend(n0.f34904a);
            }
        }

        /* JADX INFO: Access modifiers changed from: package-private */
        /* loaded from: classes4.dex */
        public static final class b extends kotlin.coroutines.jvm.internal.l implements dn.p {

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

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

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

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

            @Override // kotlin.coroutines.jvm.internal.a
            public final Object invokeSuspend(Object obj) {
                Object f10;
                f10 = wm.d.f();
                int i10 = this.f49020p;
                if (i10 == 0) {
                    y.b(obj);
                    i iVar = this.f49021q;
                    this.f49020p = 1;
                    obj = iVar.f0(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 ((b) create(m0Var, dVar)).invokeSuspend(n0.f34904a);
            }
        }

        g(vm.d dVar) {
            super(2, dVar);
        }

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            t0 b10;
            t0 b11;
            f10 = wm.d.f();
            int i10 = this.f49015p;
            if (i10 == 0) {
                y.b(obj);
                m0 m0Var = (m0) this.f49016q;
                if (i.this.f48984f.h()) {
                    b10 = tp.k.b(m0Var, null, null, new a(i.this, null), 3, null);
                    b11 = tp.k.b(m0Var, null, null, new b(i.this, null), 3, null);
                    t0[] t0VarArr = {b10, b11};
                    this.f49015p = 1;
                    if (tp.f.a(t0VarArr, this) == f10) {
                        return f10;
                    }
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            i.this.q0();
            return n0.f34904a;
        }

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

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public i(d9.f analyticsService, t7.c contextService, ka.b repository, g9.d sessionRepository, p8.a notificationSettings, fa.a myMailRepository, p9.h featureFlagRepository) {
        super((Application) r0);
        kotlin.jvm.internal.t.g(analyticsService, "analyticsService");
        kotlin.jvm.internal.t.g(contextService, "contextService");
        kotlin.jvm.internal.t.g(repository, "repository");
        kotlin.jvm.internal.t.g(sessionRepository, "sessionRepository");
        kotlin.jvm.internal.t.g(notificationSettings, "notificationSettings");
        kotlin.jvm.internal.t.g(myMailRepository, "myMailRepository");
        kotlin.jvm.internal.t.g(featureFlagRepository, "featureFlagRepository");
        Context a10 = contextService.a();
        kotlin.jvm.internal.t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f48981c = analyticsService;
        this.f48982d = contextService;
        this.f48983e = repository;
        this.f48984f = sessionRepository;
        this.f48985g = notificationSettings;
        this.f48986h = myMailRepository;
        this.f48987i = featureFlagRepository;
        this.f48988j = new l8.i(contextService);
        this.f48989k = new l8.d();
        this.f48990l = new l8.e(false, 0L, 3, null);
        f0 f0Var = new f0();
        this.f48991m = f0Var;
        this.f48992n = f0Var;
        l8.g gVar = new l8.g();
        this.f48993o = gVar;
        this.f48994p = gVar;
        l8.g gVar2 = new l8.g();
        this.f48995q = gVar2;
        this.f48996r = gVar2;
        this.f48997s = new EmailNotificationPreferenceItems(false, null, false, null, 15, null);
        l8.g gVar3 = new l8.g();
        this.f48998t = gVar3;
        this.f48999u = gVar3;
        l8.g gVar4 = new l8.g();
        this.f49000v = gVar4;
        this.f49001w = gVar4;
        f.a.c(analyticsService, "Notifications", null, 2, null);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:12:0x004d  */
    /* JADX WARN: Removed duplicated region for block: B:28:0x008c  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x0036  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0024  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object f0(vm.d dVar) {
        b bVar;
        Object f10;
        int i10;
        ResultWrapper resultWrapper;
        Boolean status;
        if (dVar instanceof b) {
            bVar = (b) dVar;
            int i11 = bVar.f49007s;
            if ((i11 & Integer.MIN_VALUE) != 0) {
                bVar.f49007s = i11 - Integer.MIN_VALUE;
                Object obj = bVar.f49005q;
                f10 = wm.d.f();
                i10 = bVar.f49007s;
                if (i10 != 0) {
                    y.b(obj);
                    ka.b bVar2 = this.f48983e;
                    bVar.f49004p = this;
                    bVar.f49007s = 1;
                    obj = bVar2.m(false, bVar);
                    if (obj == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    this = (i) bVar.f49004p;
                    y.b(obj);
                }
                resultWrapper = (ResultWrapper) obj;
                if (!(resultWrapper instanceof ResultWrapper.Success)) {
                    AMSPrerequisitesResponse aMSPrerequisitesResponse = (AMSPrerequisitesResponse) ((ResultWrapper.Success) resultWrapper).getData();
                    this.f48997s.setAutoTrackingSubscribed((aMSPrerequisitesResponse == null || (status = aMSPrerequisitesResponse.getStatus()) == null) ? false : status.booleanValue());
                    SetForgetPreferenceResponse setForgetPreferenceResponse = (SetForgetPreferenceResponse) this.f48983e.H().f();
                    Boolean emailPref = setForgetPreferenceResponse != null ? setForgetPreferenceResponse.getEmailPref() : null;
                    f0 isAutoTrackingEmailSubscribed = this.f48997s.isAutoTrackingEmailSubscribed();
                    if (emailPref == null) {
                        emailPref = kotlin.coroutines.jvm.internal.b.a(false);
                    }
                    isAutoTrackingEmailSubscribed.q(emailPref);
                } else if (resultWrapper instanceof ResultWrapper.Error) {
                    this.o0((ResultWrapper.Error) resultWrapper, true);
                }
                return obj;
            }
        }
        bVar = new b(dVar);
        Object obj2 = bVar.f49005q;
        f10 = wm.d.f();
        i10 = bVar.f49007s;
        if (i10 != 0) {
        }
        resultWrapper = (ResultWrapper) obj2;
        if (!(resultWrapper instanceof ResultWrapper.Success)) {
        }
        return obj2;
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:12:0x004b  */
    /* JADX WARN: Removed duplicated region for block: B:24:0x0081  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x0035  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0023  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object g0(vm.d dVar) {
        c cVar;
        Object f10;
        int i10;
        ResultWrapper resultWrapper;
        Boolean a10;
        if (dVar instanceof c) {
            cVar = (c) dVar;
            int i11 = cVar.f49011s;
            if ((i11 & Integer.MIN_VALUE) != 0) {
                cVar.f49011s = i11 - Integer.MIN_VALUE;
                Object obj = cVar.f49009q;
                f10 = wm.d.f();
                i10 = cVar.f49011s;
                if (i10 != 0) {
                    y.b(obj);
                    fa.a aVar = this.f48986h;
                    cVar.f49008p = this;
                    cVar.f49011s = 1;
                    obj = aVar.l(cVar);
                    if (obj == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    this = (i) cVar.f49008p;
                    y.b(obj);
                }
                resultWrapper = (ResultWrapper) obj;
                if (!(resultWrapper instanceof ResultWrapper.Success)) {
                    EmailNotificationPreferenceItems emailNotificationPreferenceItems = this.f48997s;
                    ResultWrapper.Success success = (ResultWrapper.Success) resultWrapper;
                    emailNotificationPreferenceItems.setMyMailSubscribed(((MyMailSubscriptionResponse) success.getData()).getStatus() == MyMailStatus.SUBSCRIBED);
                    f0 isMyMailEmailSubscribed = emailNotificationPreferenceItems.isMyMailEmailSubscribed();
                    Preferences preferences = ((MyMailSubscriptionResponse) success.getData()).getPreferences();
                    if (preferences == null || (a10 = preferences.getSendEmail()) == null) {
                        a10 = kotlin.coroutines.jvm.internal.b.a(false);
                    }
                    isMyMailEmailSubscribed.q(a10);
                } else if (resultWrapper instanceof ResultWrapper.Error) {
                    this.o0((ResultWrapper.Error) resultWrapper, true);
                }
                return n0.f34904a;
            }
        }
        cVar = new c(dVar);
        Object obj2 = cVar.f49009q;
        f10 = wm.d.f();
        i10 = cVar.f49011s;
        if (i10 != 0) {
        }
        resultWrapper = (ResultWrapper) obj2;
        if (!(resultWrapper instanceof ResultWrapper.Success)) {
        }
        return n0.f34904a;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean h0() {
        return this.f48990l.a(this, f48979x[0]).booleanValue();
    }

    private final boolean i0() {
        return this.f48987i.d(p9.a.AT_SMS);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean p0() {
        return this.f48984f.h();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void q0() {
        ArrayList arrayList = new ArrayList();
        String string = this.f48982d.getString(ob.l.E2);
        kotlin.jvm.internal.t.f(string, "getString(...)");
        String string2 = this.f48982d.getString(ob.l.K);
        kotlin.jvm.internal.t.f(string2, "getString(...)");
        arrayList.add(new m(string, string2, false, new d(), 4, null));
        if (this.f48984f.h() && (this.f48997s.isMyMailSubscribed() || this.f48997s.isAutoTrackingSubscribed())) {
            String string3 = this.f48982d.getString(ob.l.f31338t);
            kotlin.jvm.internal.t.f(string3, "getString(...)");
            String string4 = this.f48982d.getString(ob.l.f31333s);
            kotlin.jvm.internal.t.f(string4, "getString(...)");
            arrayList.add(new m(string3, string4, false, new e(), 4, null));
        }
        if (i0()) {
            String string5 = this.f48982d.getString(ob.l.f31252b3);
            kotlin.jvm.internal.t.f(string5, "getString(...)");
            String string6 = this.f48982d.getString(ob.l.Y);
            kotlin.jvm.internal.t.f(string6, "getString(...)");
            arrayList.add(new m(string5, string6, false, new f(), 4, null));
        }
        this.f48991m.q(arrayList);
    }

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

    public final void e0() {
        if (p0()) {
            tp.k.d(a1.a(this), null, null, new a(null), 3, null);
        }
    }

    public final a0 j0() {
        return this.f48992n;
    }

    public final a0 k0() {
        return this.f48996r;
    }

    public final a0 l0() {
        return this.f48999u;
    }

    public final a0 m0() {
        return this.f49001w;
    }

    public final a0 n0() {
        return this.f48994p;
    }

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

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

    public final void r0() {
        h.a.a(this, a1.a(this), null, null, null, new g(null), 7, null);
    }

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

    @Override // l8.h
    public u1 u(m0 m0Var, vm.g context, 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.f48988j.u(m0Var, context, start, str, block);
    }
}
