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.auth.model.UserProfile;
import ca.canadapost.core.data.model.PhoneNumber;
import ca.canadapost.core.data.model.ResultWrapper;
import ca.canadapost.core.data.profile.model.AMSPrerequisitesResponse;
import ca.canadapost.core.data.profile.model.SetForgetPreferenceResponse;
import ca.canadapost.core.data.profile.model.SetForgetSmsPreferenceRequest;
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 s extends androidx.lifecycle.b implements l8.c, l8.h {
    static final /* synthetic */ kn.l[] B = {p0.h(new g0(s.class, "doubleClickGuard", "getDoubleClickGuard()Z", 0))};
    public static final int C = 8;
    private final androidx.lifecycle.g0 A;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /* renamed from: r, reason: collision with root package name */
    private boolean f49073r;

    /* renamed from: s, reason: collision with root package name */
    private boolean f49074s;

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

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

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

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

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

    /* renamed from: y, reason: collision with root package name */
    private final androidx.lifecycle.g0 f49080y;

    /* renamed from: z, reason: collision with root package name */
    private final androidx.lifecycle.g0 f49081z;

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

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

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m472invoke() {
            if (s.this.e0()) {
                return;
            }
            s.this.f49069n.q(Boolean.FALSE);
        }
    }

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

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

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m473invoke() {
            if (s.this.e0()) {
                return;
            }
            s.this.f49069n.q(Boolean.TRUE);
        }
    }

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

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

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m474invoke() {
            s.this.f49062g.b("account_notification_textnotification_setup_automatictracking_Adobe", d9.e.f15943f.a("accountinfo_notification_textnotification_setup"));
            s.this.f49071p.q(Boolean.TRUE);
        }
    }

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

        public final void a(boolean z10) {
            s.this.f49062g.b(z10 ? "account_notification_textnotification_automatictracking_turnedon_Adobe" : "account_notification_textnotification_automatictracking_turnedoff_Adobe", d9.e.f15943f.a("accountinfo_notification_textnotification_setup"));
            s.this.q0(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 e extends kotlin.coroutines.jvm.internal.l implements dn.p {

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

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

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f49086p;
            if (i10 == 0) {
                y.b(obj);
                SetForgetSmsPreferenceRequest setForgetSmsPreferenceRequest = new SetForgetSmsPreferenceRequest(this.f49087q);
                ka.b bVar = this.f49088r.f49059d;
                this.f49086p = 1;
                obj = bVar.A(setForgetSmsPreferenceRequest, 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) {
                if (this.f49087q && this.f49088r.g0()) {
                    this.f49088r.f49078w.s();
                    this.f49088r.f49063h.putBoolean("SMS_AT_FIRST_TIME_SUCCESS", false);
                }
                return n0.f34904a;
            }
            this.f49088r.f49075t.q(kotlin.coroutines.jvm.internal.b.a(!this.f49087q));
            tr.a.f36618a.d(error.getException(), "Received exception when submitting SetForgetSmsPreferenceRequest, error is of type: " + error.getError(), new Object[0]);
            this.f49088r.m0(error, true);
            return n0.f34904a;
        }

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

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public s(t7.c contextService, ka.b userProfileRepository, g9.d cpcSessionRepository, p9.h featureFlagRepository, d9.f analyticsService, ja.d sharedPreferencesService) {
        super((Application) r0);
        kotlin.jvm.internal.t.g(contextService, "contextService");
        kotlin.jvm.internal.t.g(userProfileRepository, "userProfileRepository");
        kotlin.jvm.internal.t.g(cpcSessionRepository, "cpcSessionRepository");
        kotlin.jvm.internal.t.g(featureFlagRepository, "featureFlagRepository");
        kotlin.jvm.internal.t.g(analyticsService, "analyticsService");
        kotlin.jvm.internal.t.g(sharedPreferencesService, "sharedPreferencesService");
        Context a10 = contextService.a();
        kotlin.jvm.internal.t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f49058c = contextService;
        this.f49059d = userProfileRepository;
        this.f49060e = cpcSessionRepository;
        this.f49061f = featureFlagRepository;
        this.f49062g = analyticsService;
        this.f49063h = sharedPreferencesService;
        this.f49064i = new l8.d();
        this.f49065j = new l8.i(contextService);
        f0 f0Var = new f0();
        this.f49066k = f0Var;
        this.f49067l = f0Var;
        this.f49068m = new l8.e(false, 0L, 3, null);
        l8.g gVar = new l8.g();
        this.f49069n = gVar;
        this.f49070o = gVar;
        l8.g gVar2 = new l8.g();
        this.f49071p = gVar2;
        this.f49072q = gVar2;
        Boolean bool = Boolean.FALSE;
        this.f49075t = new f0(bool);
        this.f49076u = new f0(bool);
        this.f49077v = new f0();
        l8.g gVar3 = new l8.g();
        this.f49078w = gVar3;
        this.f49079x = gVar3;
        androidx.lifecycle.g0 g0Var = new androidx.lifecycle.g0() { // from class: wb.p
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                s.d0(s.this, (AMSPrerequisitesResponse) obj);
            }
        };
        userProfileRepository.J().k(g0Var);
        this.f49080y = g0Var;
        androidx.lifecycle.g0 g0Var2 = new androidx.lifecycle.g0() { // from class: wb.q
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                s.p0(s.this, (SetForgetPreferenceResponse) obj);
            }
        };
        userProfileRepository.H().k(g0Var2);
        this.f49081z = g0Var2;
        androidx.lifecycle.g0 g0Var3 = new androidx.lifecycle.g0() { // from class: wb.r
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                s.r0(s.this, (UserProfile) obj);
            }
        };
        userProfileRepository.a().k(g0Var3);
        this.A = g0Var3;
        f.a.c(analyticsService, "accountinfo_notification_textnotification_setup", null, 2, null);
        l0();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void d0(s this$0, AMSPrerequisitesResponse aMSPrerequisitesResponse) {
        Boolean status;
        kotlin.jvm.internal.t.g(this$0, "this$0");
        this$0.f49073r = (aMSPrerequisitesResponse == null || (status = aMSPrerequisitesResponse.getStatus()) == null) ? false : status.booleanValue();
        this$0.l0();
        this$0.o0();
    }

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

    private final boolean f0() {
        return this.f49061f.d(p9.a.AT_SMS);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean g0() {
        return this.f49063h.getBoolean("SMS_AT_FIRST_TIME_SUCCESS", true);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void p0(s this$0, SetForgetPreferenceResponse setForgetPreferenceResponse) {
        Boolean smsPref;
        kotlin.jvm.internal.t.g(this$0, "this$0");
        this$0.f49074s = (setForgetPreferenceResponse == null || (smsPref = setForgetPreferenceResponse.getSmsPref()) == null) ? false : smsPref.booleanValue();
    }

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

    /* JADX INFO: Access modifiers changed from: private */
    public static final void r0(s this$0, UserProfile userProfile) {
        kotlin.jvm.internal.t.g(this$0, "this$0");
        f0 f0Var = this$0.f49077v;
        String mfaPhone = userProfile != null ? userProfile.getMfaPhone() : null;
        f0Var.q(Boolean.valueOf(!(mfaPhone == null || mfaPhone.length() == 0)));
    }

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

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.lifecycle.z0
    public void O() {
        super.O();
        this.f49059d.J().o(this.f49080y);
        this.f49059d.H().o(this.f49081z);
        this.f49059d.a().o(this.A);
    }

    public final a0 h0() {
        return this.f49067l;
    }

    public final a0 i0() {
        return this.f49070o;
    }

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

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

    public final void l0() {
        if (f0() || this.f49060e.h()) {
            Object f10 = this.f49077v.f();
            Boolean bool = Boolean.TRUE;
            if (kotlin.jvm.internal.t.b(f10, bool) && !this.f49073r) {
                this.f49076u.q(bool);
                this.f49075t.q(Boolean.FALSE);
            }
            if (kotlin.jvm.internal.t.b(this.f49077v.f(), bool) && this.f49073r) {
                this.f49076u.q(Boolean.FALSE);
                this.f49075t.q(Boolean.valueOf(this.f49074s));
            }
        }
    }

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

    public final f0 n0() {
        return this.f49077v;
    }

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

    public final void o0() {
        String mfaPhone;
        ArrayList arrayList = new ArrayList();
        if (this.f49060e.h() && kotlin.jvm.internal.t.b(this.f49077v.f(), Boolean.FALSE)) {
            String string = this.f49058c.getString(ob.l.M2);
            kotlin.jvm.internal.t.f(string, "getString(...)");
            arrayList.add(new k(string, new a()));
        }
        if (this.f49060e.h() && kotlin.jvm.internal.t.b(this.f49077v.f(), Boolean.TRUE)) {
            String string2 = this.f49058c.getString(ob.l.f31282h3);
            kotlin.jvm.internal.t.f(string2, "getString(...)");
            UserProfile userProfile = (UserProfile) this.f49059d.a().f();
            if (userProfile != null && (mfaPhone = userProfile.getMfaPhone()) != null) {
                t7.c cVar = this.f49058c;
                int i10 = ob.l.f31337s3;
                Object[] objArr = new Object[1];
                PhoneNumber parsePhoneNumber$default = PhoneNumber.Companion.parsePhoneNumber$default(PhoneNumber.INSTANCE, mfaPhone, null, 2, null);
                objArr[0] = parsePhoneNumber$default != null ? parsePhoneNumber$default.toString() : null;
                r6 = cVar.d(i10, objArr);
            }
            arrayList.add(new l(string2, r6, new b()));
        }
        if (this.f49060e.h() && f0()) {
            f0 f0Var = this.f49075t;
            kotlin.jvm.internal.t.e(f0Var, "null cannot be cast to non-null type androidx.lifecycle.MutableLiveData<kotlin.Boolean>");
            boolean z10 = kotlin.jvm.internal.t.b(this.f49077v.f(), Boolean.TRUE) && this.f49073r;
            String string3 = this.f49058c.getString(ob.l.P0);
            kotlin.jvm.internal.t.f(string3, "getString(...)");
            String string4 = this.f49058c.getString(ob.l.N0);
            kotlin.jvm.internal.t.f(string4, "getString(...)");
            String string5 = this.f49058c.getString(ob.l.M0);
            kotlin.jvm.internal.t.f(string5, "getString(...)");
            f0 f0Var2 = this.f49076u;
            kotlin.jvm.internal.t.e(f0Var2, "null cannot be cast to non-null type androidx.lifecycle.MutableLiveData<kotlin.Boolean>");
            arrayList.add(new o(f0Var, z10, string3, string4, string5, f0Var2, new c(), new d()));
        }
        this.f49066k.q(arrayList);
    }

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