package cc;

import ca.canadapost.core.data.auth.model.ProofingState;
import ca.canadapost.core.data.auth.model.UserProfile;
import ca.canadapost.core.data.model.PhoneNumber;
import ca.canadapost.core.data.model.ResultWrapper;
import d9.f;

/* loaded from: classes4.dex */
public final class d0 extends r8.a {
    static final /* synthetic */ kn.l[] V = {kotlin.jvm.internal.p0.h(new kotlin.jvm.internal.g0(d0.class, "doubleClickGuard", "getDoubleClickGuard()Z", 0))};
    public static final int W = 8;
    private final androidx.lifecycle.f0 A;
    private final androidx.lifecycle.a0 B;
    private final androidx.lifecycle.f0 C;
    private final androidx.lifecycle.a0 D;
    private final l8.g E;
    private final androidx.lifecycle.a0 F;
    private final l8.g G;
    private final androidx.lifecycle.a0 H;
    private final androidx.lifecycle.f0 I;
    private final androidx.lifecycle.f0 J;
    private final androidx.lifecycle.f0 K;
    private boolean L;
    private final androidx.lifecycle.g0 M;
    private final l8.e N;
    private final l8.g O;
    private final androidx.lifecycle.a0 P;
    private final l8.g Q;
    private final androidx.lifecycle.a0 R;
    private final androidx.lifecycle.g0 S;
    private final androidx.lifecycle.g0 T;
    private final androidx.lifecycle.g0 U;

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

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

    /* renamed from: p, reason: collision with root package name */
    private final g9.h f11386p;

    /* renamed from: q, reason: collision with root package name */
    private final g9.i f11387q;

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

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

    /* renamed from: t, reason: collision with root package name */
    private final rm.o f11390t;

    /* renamed from: u, reason: collision with root package name */
    private final rm.o f11391u;

    /* renamed from: v, reason: collision with root package name */
    private final rm.o f11392v;

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

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

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

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

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

        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.f11397p;
            if (i10 == 0) {
                rm.y.b(obj);
                g9.h hVar = d0.this.f11386p;
                this.f11397p = 1;
                if (hVar.k(this) == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    if (i10 != 2) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    rm.y.b(obj);
                    return rm.n0.f34904a;
                }
                rm.y.b(obj);
            }
            g9.i iVar = d0.this.f11387q;
            this.f11397p = 2;
            if (iVar.k(this) == f10) {
                return f10;
            }
            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);
        }
    }

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

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

        /* renamed from: q, reason: collision with root package name */
        int f11400q;

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

        /* renamed from: t, reason: collision with root package name */
        final /* synthetic */ String f11403t;

        /* renamed from: u, reason: collision with root package name */
        final /* synthetic */ String f11404u;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        b(String str, String str2, String str3, vm.d dVar) {
            super(1, dVar);
            this.f11402s = str;
            this.f11403t = str2;
            this.f11404u = str3;
        }

        @Override // dn.l
        /* renamed from: b, reason: merged with bridge method [inline-methods] */
        public final Object invoke(vm.d dVar) {
            return ((b) create(dVar)).invokeSuspend(rm.n0.f34904a);
        }

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

        /* JADX WARN: Removed duplicated region for block: B:14:0x0099 A[RETURN] */
        @Override // kotlin.coroutines.jvm.internal.a
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final Object invokeSuspend(Object obj) {
            Object f10;
            ResultWrapper.Error error;
            g9.i iVar;
            f10 = wm.d.f();
            int i10 = this.f11400q;
            if (i10 == 0) {
                rm.y.b(obj);
                if (!d0.this.J0() && !d0.this.I0() && !d0.this.H0()) {
                    return null;
                }
                ka.b bVar = d0.this.f11385o;
                String str = this.f11402s;
                String str2 = this.f11403t;
                String str3 = this.f11404u;
                this.f11400q = 1;
                obj = bVar.g(str, str2, str3, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    if (i10 != 2) {
                        if (i10 != 3) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        ResultWrapper.Error error2 = (ResultWrapper.Error) this.f11399p;
                        rm.y.b(obj);
                        return error2;
                    }
                    ResultWrapper.Error error3 = (ResultWrapper.Error) this.f11399p;
                    rm.y.b(obj);
                    error = error3;
                    iVar = d0.this.f11387q;
                    this.f11399p = error;
                    this.f11400q = 3;
                    if (iVar.k(this) == f10) {
                        return f10;
                    }
                    return error;
                }
                rm.y.b(obj);
            }
            error = (ResultWrapper.Error) obj;
            if (error == null) {
                d0.this.f11386p.g();
                d0.this.f11387q.g();
                g9.h hVar = d0.this.f11386p;
                this.f11399p = error;
                this.f11400q = 2;
                if (hVar.k(this) == f10) {
                    return f10;
                }
                iVar = d0.this.f11387q;
                this.f11399p = error;
                this.f11400q = 3;
                if (iVar.k(this) == f10) {
                }
            }
            return error;
        }
    }

    /* loaded from: classes4.dex */
    static final class c extends kotlin.jvm.internal.v implements dn.a {
        c() {
            super(0);
        }

        @Override // dn.a
        public final String invoke() {
            String phoneNumber;
            PhoneNumber.Companion companion = PhoneNumber.INSTANCE;
            UserProfile userProfile = (UserProfile) d0.this.f11385o.a().f();
            PhoneNumber parsePhoneNumber$default = PhoneNumber.Companion.parsePhoneNumber$default(companion, userProfile != null ? userProfile.getPrimaryPhone() : null, null, 2, null);
            return (parsePhoneNumber$default == null || (phoneNumber = parsePhoneNumber$default.toString()) == null) ? "" : phoneNumber;
        }
    }

    /* loaded from: classes4.dex */
    static final class d extends kotlin.jvm.internal.v implements dn.a {
        d() {
            super(0);
        }

        @Override // dn.a
        public final String invoke() {
            String phoneNumber;
            PhoneNumber.Companion companion = PhoneNumber.INSTANCE;
            UserProfile userProfile = (UserProfile) d0.this.f11385o.a().f();
            PhoneNumber parsePhoneNumber$default = PhoneNumber.Companion.parsePhoneNumber$default(companion, userProfile != null ? userProfile.getMobilePhone() : null, null, 2, null);
            return (parsePhoneNumber$default == null || (phoneNumber = parsePhoneNumber$default.toString()) == null) ? "" : phoneNumber;
        }
    }

    /* loaded from: classes4.dex */
    static final class e extends kotlin.jvm.internal.v implements dn.a {
        e() {
            super(0);
        }

        @Override // dn.a
        public final String invoke() {
            String email;
            UserProfile userProfile = (UserProfile) d0.this.f11385o.a().f();
            return (userProfile == null || (email = userProfile.getEmail()) == null) ? "" : email;
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public d0(d9.f analyticsService, ka.b repository, g9.h l1AuthRepository, g9.i l2Repository, t7.c contextService, p9.h featureFlagRepository) {
        super(contextService);
        rm.o a10;
        rm.o a11;
        rm.o a12;
        kotlin.jvm.internal.t.g(analyticsService, "analyticsService");
        kotlin.jvm.internal.t.g(repository, "repository");
        kotlin.jvm.internal.t.g(l1AuthRepository, "l1AuthRepository");
        kotlin.jvm.internal.t.g(l2Repository, "l2Repository");
        kotlin.jvm.internal.t.g(contextService, "contextService");
        kotlin.jvm.internal.t.g(featureFlagRepository, "featureFlagRepository");
        this.f11384n = analyticsService;
        this.f11385o = repository;
        this.f11386p = l1AuthRepository;
        this.f11387q = l2Repository;
        this.f11388r = contextService;
        this.f11389s = featureFlagRepository;
        a10 = rm.q.a(new e());
        this.f11390t = a10;
        a11 = rm.q.a(new c());
        this.f11391u = a11;
        a12 = rm.q.a(new d());
        this.f11392v = a12;
        l8.g gVar = new l8.g();
        this.f11393w = gVar;
        this.f11394x = gVar;
        androidx.lifecycle.f0 f0Var = new androidx.lifecycle.f0();
        this.f11395y = f0Var;
        this.f11396z = f0Var;
        androidx.lifecycle.f0 f0Var2 = new androidx.lifecycle.f0();
        this.A = f0Var2;
        this.B = f0Var2;
        androidx.lifecycle.f0 f0Var3 = new androidx.lifecycle.f0();
        this.C = f0Var3;
        this.D = f0Var3;
        l8.g gVar2 = new l8.g();
        this.E = gVar2;
        this.F = gVar2;
        l8.g gVar3 = new l8.g();
        this.G = gVar3;
        this.H = gVar3;
        androidx.lifecycle.f0 f0Var4 = new androidx.lifecycle.f0(F0());
        this.I = f0Var4;
        androidx.lifecycle.f0 f0Var5 = new androidx.lifecycle.f0(D0());
        this.J = f0Var5;
        androidx.lifecycle.f0 f0Var6 = new androidx.lifecycle.f0(E0());
        this.K = f0Var6;
        androidx.lifecycle.g0 g0Var = new androidx.lifecycle.g0() { // from class: cc.z
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                d0.P0(d0.this, (ProofingState) obj);
            }
        };
        l1AuthRepository.c().k(g0Var);
        this.M = g0Var;
        this.N = new l8.e(false, 0L, 3, null);
        l8.g gVar4 = new l8.g();
        this.O = gVar4;
        this.P = gVar4;
        l8.g gVar5 = new l8.g();
        this.Q = gVar5;
        this.R = gVar5;
        f.a.c(analyticsService, "Contact_info_accountspage", null, 2, null);
        if (l1AuthRepository.c().f() == null) {
            r0();
        }
        androidx.lifecycle.g0 g0Var2 = new androidx.lifecycle.g0() { // from class: cc.a0
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                d0.M0(d0.this, (String) obj);
            }
        };
        f0Var4.k(g0Var2);
        this.S = g0Var2;
        androidx.lifecycle.g0 g0Var3 = new androidx.lifecycle.g0() { // from class: cc.b0
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                d0.K0(d0.this, (String) obj);
            }
        };
        f0Var5.k(g0Var3);
        this.T = g0Var3;
        androidx.lifecycle.g0 g0Var4 = new androidx.lifecycle.g0() { // from class: cc.c0
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                d0.L0(d0.this, (String) obj);
            }
        };
        f0Var6.k(g0Var4);
        this.U = g0Var4;
    }

    private final String D0() {
        return (String) this.f11391u.getValue();
    }

    private final String E0() {
        return (String) this.f11392v.getValue();
    }

    private final String F0() {
        return (String) this.f11390t.getValue();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean H0() {
        return !kotlin.jvm.internal.t.b(this.J.f(), D0());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean I0() {
        return !kotlin.jvm.internal.t.b(this.K.f(), E0());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean J0() {
        return !kotlin.jvm.internal.t.b(this.I.f(), F0());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void K0(d0 this$0, String it) {
        kotlin.jvm.internal.t.g(this$0, "this$0");
        kotlin.jvm.internal.t.g(it, "it");
        this$0.e0();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void L0(d0 this$0, String it) {
        kotlin.jvm.internal.t.g(this$0, "this$0");
        kotlin.jvm.internal.t.g(it, "it");
        this$0.e0();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void M0(d0 this$0, String it) {
        kotlin.jvm.internal.t.g(this$0, "this$0");
        kotlin.jvm.internal.t.g(it, "it");
        this$0.e0();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void P0(d0 this$0, ProofingState proofingState) {
        kotlin.jvm.internal.t.g(this$0, "this$0");
        boolean z10 = false;
        if (proofingState != null && proofingState.isL1Authenticated()) {
            z10 = true;
        }
        this$0.L = !z10;
    }

    private final void r0() {
        tp.k.d(androidx.lifecycle.a1.a(this), null, null, new a(null), 3, null);
    }

    private final boolean u0() {
        return this.N.a(this, V[0]).booleanValue();
    }

    public final androidx.lifecycle.f0 A0() {
        return this.K;
    }

    public final androidx.lifecycle.f0 B0() {
        return this.I;
    }

    public final androidx.lifecycle.a0 C0() {
        return this.F;
    }

    public final androidx.lifecycle.a0 G0() {
        return this.H;
    }

    public final void N0() {
        d0(new b(J0() ? (String) this.I.f() : null, I0() ? (String) this.K.f() : null, H0() ? (String) this.J.f() : null, null));
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.lifecycle.z0
    public void O() {
        this.I.o(this.S);
        this.J.o(this.T);
        this.K.o(this.U);
        this.f11386p.c().o(this.M);
        super.O();
    }

    public final void O0() {
        f.a.c(this.f11384n, "Edit_update_email_accountspage", null, 2, null);
        this.G.q(this.I.f());
    }

    public final void Q0() {
        this.I.q(F0());
        this.J.q(D0());
        this.K.q(E0());
    }

    public final void R0() {
        this.Q.s();
    }

    public final void S0() {
        if (u0()) {
            return;
        }
        this.O.s();
    }

    @Override // r8.a
    public boolean c0() {
        return g();
    }

    @Override // r8.b
    public boolean e() {
        boolean z10 = J0() || H0() || I0();
        V().q(Boolean.valueOf(z10));
        return z10;
    }

    /* JADX WARN: Removed duplicated region for block: B:38:0x00ae  */
    @Override // r8.b
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public boolean g() {
        boolean z10;
        this.f11395y.q(null);
        this.C.q(null);
        this.A.q(null);
        boolean i10 = qa.d.i((String) this.I.f());
        if (!i10) {
            this.f11395y.q(this.f11388r.getString(ob.l.f31256c2));
        }
        String str = (String) this.K.f();
        if (str == null) {
            str = "";
        }
        boolean z11 = (str.length() == 0) || PhoneNumber.INSTANCE.isValidPhoneNumber(str);
        if (!z11) {
            this.C.q(this.f11388r.getString(ob.l.f31253c));
        }
        String str2 = (String) this.J.f();
        String str3 = str2 != null ? str2 : "";
        boolean z12 = (str3.length() == 0) || PhoneNumber.INSTANCE.isValidPhoneNumber(str3);
        if (!z12) {
            this.A.q(this.f11388r.getString(ob.l.f31253c));
        }
        if (!(str.length() > 0)) {
            if (!(str3.length() > 0)) {
                z10 = false;
                if (!z10) {
                    this.E.s();
                }
                return !i10 && z12 && z11 && z10;
            }
        }
        z10 = true;
        if (!z10) {
        }
        if (i10) {
        }
    }

    public final void q0() {
        if (!this.L) {
            this.f11393w.s();
        }
        this.L = true;
    }

    public final androidx.lifecycle.a0 s0() {
        return this.B;
    }

    public final androidx.lifecycle.a0 t0() {
        return this.R;
    }

    public final androidx.lifecycle.a0 v0() {
        return this.f11396z;
    }

    public final androidx.lifecycle.a0 w0() {
        return this.D;
    }

    public final androidx.lifecycle.a0 x0() {
        return this.P;
    }

    public final androidx.lifecycle.a0 y0() {
        return this.f11394x;
    }

    public final androidx.lifecycle.f0 z0() {
        return this.J;
    }
}
