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.MyMailSubscribeBody;
import ca.canadapost.core.data.mymail.model.Preferences;
import ca.canadapost.core.data.profile.model.EmailNotificationPreferenceItems;
import ca.canadapost.core.data.profile.model.SetForgetEmailPreferenceRequest;
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.u1;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        public final void a(boolean z10) {
            if (e.this.Y()) {
                return;
            }
            e.this.d0(z10);
        }

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

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

        public final void a(boolean z10) {
            if (e.this.Y()) {
                return;
            }
            if (z10) {
                e.this.f48963l.s();
            } else {
                e.this.e0(false);
            }
        }

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

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

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

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

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        c(boolean z10, e eVar, vm.d dVar) {
            super(2, dVar);
            this.f48969q = z10;
            this.f48970r = eVar;
        }

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f48968p;
            if (i10 == 0) {
                y.b(obj);
                SetForgetEmailPreferenceRequest setForgetEmailPreferenceRequest = new SetForgetEmailPreferenceRequest(this.f48969q);
                ka.b bVar = this.f48970r.f48956e;
                this.f48968p = 1;
                obj = bVar.r(setForgetEmailPreferenceRequest, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            ResultWrapper.Error error = (ResultWrapper.Error) obj;
            if (error != null) {
                this.f48970r.b0(error, true);
            } else {
                this.f48970r.f48954c.b("account_notification_emailnotification_automatictracking_turnedon", d9.e.f15943f.a("accountinfo_notification_emailnotification"));
            }
            return n0.f34904a;
        }

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

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

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

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

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

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        d(boolean z10, e eVar, vm.d dVar) {
            super(2, dVar);
            this.f48972q = z10;
            this.f48973r = eVar;
        }

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f48971p;
            if (i10 == 0) {
                y.b(obj);
                MyMailSubscribeBody myMailSubscribeBody = new MyMailSubscribeBody(MyMailStatus.SUBSCRIBED, new Preferences(null, null, kotlin.coroutines.jvm.internal.b.a(this.f48972q), 3, null));
                fa.a aVar = this.f48973r.f48957f;
                this.f48971p = 1;
                obj = aVar.m(myMailSubscribeBody, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            ResultWrapper resultWrapper = (ResultWrapper) obj;
            if (resultWrapper instanceof ResultWrapper.Success) {
                if (this.f48972q) {
                    this.f48973r.f48954c.b("account_notification_emailnotification_mymail_turnedon", d9.e.f15943f.a("accountinfo_notification_emailnotification"));
                }
                this.f48973r.X(this.f48972q);
            } else if (resultWrapper instanceof ResultWrapper.Error) {
                this.f48973r.X(!this.f48972q);
                this.f48973r.b0((ResultWrapper.Error) resultWrapper, true);
            }
            return n0.f34904a;
        }

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

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public e(d9.f analyticsService, t7.c contextService, ka.b repository, fa.a myMailRepository, EmailNotificationPreferenceItems emailNotificationPreferenceItems) {
        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(myMailRepository, "myMailRepository");
        kotlin.jvm.internal.t.g(emailNotificationPreferenceItems, "emailNotificationPreferenceItems");
        Context a10 = contextService.a();
        kotlin.jvm.internal.t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f48954c = analyticsService;
        this.f48955d = contextService;
        this.f48956e = repository;
        this.f48957f = myMailRepository;
        this.f48958g = emailNotificationPreferenceItems;
        this.f48959h = new l8.i(contextService);
        this.f48960i = new l8.d();
        f0 f0Var = new f0();
        this.f48961j = f0Var;
        this.f48962k = f0Var;
        l8.g gVar = new l8.g();
        this.f48963l = gVar;
        this.f48964m = gVar;
        this.f48965n = new l8.e(false, 0L, 3, null);
        f.a.c(analyticsService, "accountinfo_notification_emailnotification", null, 2, null);
        c0();
    }

    private final void W(boolean z10) {
        this.f48958g.isAutoTrackingEmailSubscribed().q(Boolean.valueOf(z10));
    }

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

    private final void c0() {
        ArrayList arrayList = new ArrayList();
        if (this.f48958g.isAutoTrackingSubscribed()) {
            f0 isAutoTrackingEmailSubscribed = this.f48958g.isAutoTrackingEmailSubscribed();
            String string = this.f48955d.getString(ob.l.O0);
            kotlin.jvm.internal.t.f(string, "getString(...)");
            String string2 = this.f48955d.getString(ob.l.P1);
            kotlin.jvm.internal.t.f(string2, "getString(...)");
            arrayList.add(new n(isAutoTrackingEmailSubscribed, string, string2, new a()));
        }
        if (this.f48958g.isMyMailSubscribed()) {
            f0 isMyMailEmailSubscribed = this.f48958g.isMyMailEmailSubscribed();
            String string3 = this.f48955d.getString(ob.l.f31291j2);
            kotlin.jvm.internal.t.f(string3, "getString(...)");
            String string4 = this.f48955d.getString(ob.l.f31286i2);
            kotlin.jvm.internal.t.f(string4, "getString(...)");
            arrayList.add(new n(isMyMailEmailSubscribed, string3, string4, new b()));
        }
        this.f48961j.q(arrayList);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void d0(boolean z10) {
        W(z10);
        h.a.a(this, a1.a(this), null, null, null, new c(z10, this, null), 7, null);
    }

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

    public final void X(boolean z10) {
        this.f48958g.isMyMailEmailSubscribed().q(Boolean.valueOf(z10));
    }

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

    public final a0 a0() {
        return this.f48964m;
    }

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

    public final void e0(boolean z10) {
        h.a.a(this, a1.a(this), null, null, null, new d(z10, this, null), 7, null);
    }

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

    @Override // l8.c
    public a0 t() {
        return this.f48960i.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.f48959h.u(m0Var, context, start, str, block);
    }
}
