package jg;

import android.app.Application;
import android.content.Context;
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.track.model.SMSNotificationUpdateRequest;
import d9.f;
import java.util.Map;
import l8.h;

/* loaded from: classes4.dex */
public final class l4 extends androidx.lifecycle.b implements l8.h, l8.c {
    static final /* synthetic */ kn.l[] E = {kotlin.jvm.internal.p0.h(new kotlin.jvm.internal.g0(l4.class, "doubleClickGuard", "getDoubleClickGuard()Z", 0))};
    private final l8.e A;
    private final l8.g B;
    private final androidx.lifecycle.a0 C;
    private final String D;

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

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

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

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

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

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

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

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

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

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

    /* renamed from: m, reason: collision with root package name */
    private boolean f24522m;

    /* renamed from: n, reason: collision with root package name */
    private boolean f24523n;

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

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

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

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

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

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

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

    /* renamed from: v, reason: collision with root package name */
    private String f24531v;

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

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

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

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

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

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f24536p;
            if (i10 == 0) {
                rm.y.b(obj);
                fg.c f02 = l4.this.f0();
                SMSNotificationUpdateRequest sMSNotificationUpdateRequest = this.f24538r;
                this.f24536p = 1;
                obj = f02.registerSmsNotification(sMSNotificationUpdateRequest, 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.Success) {
                l4.this.n0(this.f24538r);
                l4.this.B.s();
            } else if (resultWrapper instanceof ResultWrapper.Error) {
                l4.this.g0((ResultWrapper.Error) resultWrapper, true);
            }
            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 l4(t7.c contextService, ka.b repository, fg.c trackRepository, d9.f analyticsService, p9.h featureFlagRepository, String str) {
        super((Application) r0);
        String str2;
        kotlin.jvm.internal.t.g(contextService, "contextService");
        kotlin.jvm.internal.t.g(repository, "repository");
        kotlin.jvm.internal.t.g(trackRepository, "trackRepository");
        kotlin.jvm.internal.t.g(analyticsService, "analyticsService");
        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.f24512c = contextService;
        this.f24513d = repository;
        this.f24514e = trackRepository;
        this.f24515f = analyticsService;
        this.f24516g = featureFlagRepository;
        this.f24517h = str;
        this.f24518i = new l8.i(contextService);
        this.f24519j = new l8.d();
        androidx.lifecycle.f0 f0Var = new androidx.lifecycle.f0();
        this.f24520k = f0Var;
        this.f24521l = new androidx.lifecycle.f0();
        this.f24524o = new androidx.lifecycle.f0(Boolean.FALSE);
        l8.g gVar = new l8.g();
        this.f24525p = gVar;
        this.f24526q = gVar;
        l8.g gVar2 = new l8.g();
        this.f24527r = gVar2;
        this.f24528s = gVar2;
        l8.g gVar3 = new l8.g();
        this.f24529t = gVar3;
        this.f24530u = gVar3;
        String string = contextService.getString(yf.h.f52582g2);
        kotlin.jvm.internal.t.f(string, "getString(...)");
        this.f24531v = string;
        l8.g gVar4 = new l8.g();
        this.f24532w = gVar4;
        this.f24533x = gVar4;
        l8.g gVar5 = new l8.g();
        this.f24534y = gVar5;
        this.f24535z = gVar5;
        this.A = new l8.e(false, 0L, 3, null);
        l8.g gVar6 = new l8.g();
        this.B = gVar6;
        this.C = gVar6;
        UserProfile userProfile = (UserProfile) repository.a().f();
        if (userProfile != null) {
            str2 = userProfile.getMfaPhone();
            if (str2 == null && (str2 = userProfile.getMobilePhone()) == null) {
                str2 = userProfile.getPrimaryPhone();
            }
        } else {
            str2 = null;
        }
        this.D = str2;
        f.a.c(analyticsService, "SmsUpdatesRegistration", null, 2, null);
        f0Var.q(str2 == null ? "" : str2);
    }

    private final boolean U() {
        return this.A.a(this, E[0]).booleanValue();
    }

    private final boolean i0() {
        this.f24521l.q(j0((String) this.f24520k.f()) ? null : this.f24512c.getString(yf.h.f52582g2));
        String string = this.f24512c.getString(yf.h.f52582g2);
        kotlin.jvm.internal.t.f(string, "getString(...)");
        this.f24531v = string;
        this.f24524o.q(Boolean.valueOf((this.f24523n || this.f24522m) ? false : true));
        if (this.f24521l.f() == null) {
            String string2 = this.f24512c.getString(yf.h.f52587h2);
            kotlin.jvm.internal.t.f(string2, "getString(...)");
            this.f24531v = string2;
        }
        CharSequence charSequence = (CharSequence) this.f24521l.f();
        return (charSequence == null || charSequence.length() == 0) && !kotlin.jvm.internal.t.b(this.f24524o.f(), Boolean.TRUE);
    }

    /* JADX WARN: Removed duplicated region for block: B:12:? A[RETURN, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:9:0x001b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private final boolean j0(String str) {
        boolean z10;
        boolean P;
        if (!PhoneNumber.INSTANCE.isValidPhoneNumber(str)) {
            return false;
        }
        if (str != null) {
            P = kotlin.text.y.P(str, "1", false, 2, null);
            if (!P) {
                z10 = true;
                return !z10;
            }
        }
        z10 = false;
        if (!z10) {
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void n0(SMSNotificationUpdateRequest sMSNotificationUpdateRequest) {
        boolean A;
        Map l10;
        Boolean delivery = sMSNotificationUpdateRequest.getDelivery();
        Boolean bool = Boolean.TRUE;
        String str = (kotlin.jvm.internal.t.b(delivery, bool) && kotlin.jvm.internal.t.b(sMSNotificationUpdateRequest.getException(), bool)) ? "All updates" : kotlin.jvm.internal.t.b(sMSNotificationUpdateRequest.getDelivery(), bool) ? "Delivery" : "Exception";
        A = kotlin.text.y.A(this.D, sMSNotificationUpdateRequest.getPhoneNumber(), false, 2, null);
        String str2 = "Get Text Update - " + (A ? "Non Edited" : "Edited") + " - " + str;
        d9.f fVar = this.f24515f;
        l10 = sm.q0.l(rm.c0.a("e.Var13", str2), rm.c0.a("e.Var3", "SmsUpdatesRegistration"));
        fVar.b("Successful_SMSnotification_signup_Adobe", l10);
    }

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

    public final void S() {
        if (U()) {
            return;
        }
        this.f24525p.s();
    }

    public final void T() {
        if (U()) {
            return;
        }
        this.f24527r.s();
    }

    public final boolean V() {
        return this.f24516g.d(p9.a.SMS_SECOND_NUMBER);
    }

    public final androidx.lifecycle.a0 W() {
        return this.f24533x;
    }

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

    public final androidx.lifecycle.f0 Y() {
        return this.f24520k;
    }

    public final androidx.lifecycle.f0 Z() {
        return this.f24521l;
    }

    public final String a0() {
        return this.D;
    }

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

    public final androidx.lifecycle.a0 c0() {
        return this.f24526q;
    }

    public final androidx.lifecycle.a0 d0() {
        return this.f24528s;
    }

    public final androidx.lifecycle.f0 e0() {
        return this.f24524o;
    }

    public final fg.c f0() {
        return this.f24514e;
    }

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

    public final androidx.lifecycle.a0 h0() {
        return this.C;
    }

    public final void k0() {
        this.f24532w.s();
    }

    public final void l0() {
        this.f24534y.s();
        this.f24515f.b("Track_Text_Updates_add_mob_phone_num_click", d9.e.f15943f.a("SmsUpdatesRegistration"));
    }

    public final void m0() {
        if (U()) {
            return;
        }
        if (!i0()) {
            this.f24529t.q(this.f24531v);
            return;
        }
        Boolean valueOf = Boolean.valueOf(this.f24523n);
        Boolean valueOf2 = Boolean.valueOf(this.f24522m);
        String str = (String) this.f24520k.f();
        h.a.a(this, androidx.lifecycle.a1.a(this), null, null, null, new a(new SMSNotificationUpdateRequest(valueOf, valueOf2, str != null ? PhoneNumber.INSTANCE.removeSpecChars(str) : null, this.f24517h), null), 7, null);
    }

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

    public final void o0(boolean z10) {
        this.f24523n = z10;
    }

    public final void p0(boolean z10) {
        this.f24522m = z10;
    }

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