package cc;

import ca.canadapost.core.data.auth.model.ProofingState;
import ca.canadapost.core.data.auth.model.UserProfile;
import ca.canadapost.core.data.model.ResultWrapper;
import d9.f;
import java.util.Locale;

/* loaded from: classes4.dex */
public final class i0 extends r8.a {
    private final androidx.lifecycle.g0 A;
    private final androidx.lifecycle.f0 B;
    private final androidx.lifecycle.a0 C;
    private final androidx.lifecycle.f0 D;
    private final androidx.lifecycle.a0 E;
    private final androidx.lifecycle.f0 F;
    private final androidx.lifecycle.a0 G;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        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.f11527p;
            if (i10 == 0) {
                rm.y.b(obj);
                g9.h hVar = i0.this.f11516p;
                this.f11527p = 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 = i0.this.f11517q;
            this.f11527p = 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 f11529p;

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

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

        @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(dVar);
        }

        /* JADX WARN: Removed duplicated region for block: B:15:0x00cf A[RETURN] */
        /* JADX WARN: Removed duplicated region for block: B:16:0x00d0  */
        /* JADX WARN: Removed duplicated region for block: B:20:0x009c  */
        /* JADX WARN: Removed duplicated region for block: B:23:? A[RETURN, SYNTHETIC] */
        @Override // kotlin.coroutines.jvm.internal.a
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final Object invokeSuspend(Object obj) {
            Object f10;
            String str;
            CharSequence e12;
            CharSequence e13;
            ResultWrapper.Error error;
            g9.h hVar;
            ResultWrapper.Error error2;
            f10 = wm.d.f();
            int i10 = this.f11530q;
            if (i10 == 0) {
                rm.y.b(obj);
                String str2 = null;
                error = null;
                if (i0.this.z0() || i0.this.A0()) {
                    Boolean bool = (Boolean) i0.this.f11518r.f();
                    if (bool == null) {
                        bool = kotlin.coroutines.jvm.internal.b.a(false);
                    }
                    boolean booleanValue = bool.booleanValue();
                    ka.b bVar = i0.this.f11515o;
                    String str3 = (String) i0.this.r0().f();
                    if (str3 != null) {
                        e13 = kotlin.text.z.e1(str3);
                        str = e13.toString();
                    } else {
                        str = null;
                    }
                    String str4 = (String) i0.this.t0().f();
                    if (str4 != null) {
                        e12 = kotlin.text.z.e1(str4);
                        str2 = e12.toString();
                    }
                    this.f11530q = 1;
                    obj = bVar.u(str, str2, booleanValue, this);
                    if (obj == f10) {
                        return f10;
                    }
                }
                if (error == null) {
                    return error;
                }
                i0.this.f11516p.g();
                i0.this.f11517q.g();
                g9.i iVar = i0.this.f11517q;
                this.f11529p = error;
                this.f11530q = 2;
                if (iVar.k(this) == f10) {
                    return f10;
                }
                hVar = i0.this.f11516p;
                this.f11529p = error;
                this.f11530q = 3;
                if (hVar.k(this) != f10) {
                }
            } else {
                if (i10 != 1) {
                    if (i10 != 2) {
                        if (i10 != 3) {
                            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                        }
                        error2 = (ResultWrapper.Error) this.f11529p;
                        rm.y.b(obj);
                        return error2;
                    }
                    error = (ResultWrapper.Error) this.f11529p;
                    rm.y.b(obj);
                    hVar = i0.this.f11516p;
                    this.f11529p = error;
                    this.f11530q = 3;
                    if (hVar.k(this) != f10) {
                        return f10;
                    }
                    error2 = error;
                    return error2;
                }
                rm.y.b(obj);
            }
            error = (ResultWrapper.Error) obj;
            if (error == null) {
            }
        }
    }

    /* 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 firstName;
            UserProfile userProfile = (UserProfile) i0.this.f11515o.a().f();
            return (userProfile == null || (firstName = userProfile.getFirstName()) == null) ? "" : firstName;
        }
    }

    /* 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 lastName;
            UserProfile userProfile = (UserProfile) i0.this.f11515o.a().f();
            return (userProfile == null || (lastName = userProfile.getLastName()) == null) ? "" : lastName;
        }
    }

    /* 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 userName;
            UserProfile userProfile = (UserProfile) i0.this.f11515o.a().f();
            return (userProfile == null || (userName = userProfile.getUserName()) == null) ? "" : userName;
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public i0(d9.f analyticsService, t7.c contextService, ka.b repository, g9.h l1AuthRepository, g9.i l2Repository) {
        super(contextService);
        rm.o a10;
        rm.o a11;
        rm.o a12;
        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(l1AuthRepository, "l1AuthRepository");
        kotlin.jvm.internal.t.g(l2Repository, "l2Repository");
        this.f11514n = contextService;
        this.f11515o = repository;
        this.f11516p = l1AuthRepository;
        this.f11517q = l2Repository;
        this.f11518r = new androidx.lifecycle.f0();
        androidx.lifecycle.g0 g0Var = new androidx.lifecycle.g0() { // from class: cc.f0
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                i0.E0(i0.this, (ProofingState) obj);
            }
        };
        l1AuthRepository.c().k(g0Var);
        this.f11519s = g0Var;
        f.a.c(analyticsService, "Edit_name_accountspage", null, 2, null);
        if (l1AuthRepository.c().f() == null) {
            p0();
        }
        a10 = rm.q.a(new c());
        this.f11520t = a10;
        a11 = rm.q.a(new d());
        this.f11521u = a11;
        a12 = rm.q.a(new e());
        this.f11522v = a12;
        androidx.lifecycle.f0 f0Var = new androidx.lifecycle.f0(v0());
        this.f11523w = f0Var;
        androidx.lifecycle.f0 f0Var2 = new androidx.lifecycle.f0(w0());
        this.f11524x = f0Var2;
        this.f11525y = new androidx.lifecycle.f0(x0());
        androidx.lifecycle.g0 g0Var2 = new androidx.lifecycle.g0() { // from class: cc.g0
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                i0.q0(i0.this, (String) obj);
            }
        };
        f0Var.k(g0Var2);
        this.f11526z = g0Var2;
        androidx.lifecycle.g0 g0Var3 = new androidx.lifecycle.g0() { // from class: cc.h0
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                i0.F0(i0.this, (String) obj);
            }
        };
        f0Var2.k(g0Var3);
        this.A = g0Var3;
        androidx.lifecycle.f0 f0Var3 = new androidx.lifecycle.f0();
        this.B = f0Var3;
        this.C = f0Var3;
        androidx.lifecycle.f0 f0Var4 = new androidx.lifecycle.f0();
        this.D = f0Var4;
        this.E = f0Var4;
        androidx.lifecycle.f0 f0Var5 = new androidx.lifecycle.f0();
        this.F = f0Var5;
        this.G = f0Var5;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean A0() {
        String str;
        CharSequence e12;
        CharSequence e13;
        String str2 = (String) this.f11524x.f();
        if (str2 != null) {
            String lowerCase = str2.toLowerCase(Locale.ROOT);
            kotlin.jvm.internal.t.f(lowerCase, "toLowerCase(...)");
            if (lowerCase != null) {
                e13 = kotlin.text.z.e1(lowerCase);
                str = e13.toString();
                String lowerCase2 = w0().toLowerCase(Locale.ROOT);
                kotlin.jvm.internal.t.f(lowerCase2, "toLowerCase(...)");
                e12 = kotlin.text.z.e1(lowerCase2);
                return !kotlin.jvm.internal.t.b(str, e12.toString());
            }
        }
        str = null;
        String lowerCase22 = w0().toLowerCase(Locale.ROOT);
        kotlin.jvm.internal.t.f(lowerCase22, "toLowerCase(...)");
        e12 = kotlin.text.z.e1(lowerCase22);
        return !kotlin.jvm.internal.t.b(str, e12.toString());
    }

    private final boolean B0() {
        String str;
        CharSequence e12;
        CharSequence e13;
        String str2 = (String) this.f11525y.f();
        if (str2 != null) {
            String lowerCase = str2.toLowerCase(Locale.ROOT);
            kotlin.jvm.internal.t.f(lowerCase, "toLowerCase(...)");
            if (lowerCase != null) {
                e13 = kotlin.text.z.e1(lowerCase);
                str = e13.toString();
                String lowerCase2 = x0().toLowerCase(Locale.ROOT);
                kotlin.jvm.internal.t.f(lowerCase2, "toLowerCase(...)");
                e12 = kotlin.text.z.e1(lowerCase2);
                return !kotlin.jvm.internal.t.b(str, e12.toString());
            }
        }
        str = null;
        String lowerCase22 = x0().toLowerCase(Locale.ROOT);
        kotlin.jvm.internal.t.f(lowerCase22, "toLowerCase(...)");
        e12 = kotlin.text.z.e1(lowerCase22);
        return !kotlin.jvm.internal.t.b(str, e12.toString());
    }

    private final boolean C0() {
        String str = (String) this.f11523w.f();
        if (str == null) {
            str = "";
        }
        t7.c cVar = this.f11514n;
        String string = cVar.getString(ob.l.Z1);
        kotlin.jvm.internal.t.f(string, "getString(...)");
        return r8.c.a(str, cVar, string, this.B);
    }

    private final boolean D0() {
        String str = (String) this.f11524x.f();
        if (str == null) {
            str = "";
        }
        t7.c cVar = this.f11514n;
        String string = cVar.getString(ob.l.f31246a2);
        kotlin.jvm.internal.t.f(string, "getString(...)");
        return r8.c.a(str, cVar, string, this.D);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void E0(i0 this$0, ProofingState proofingState) {
        kotlin.jvm.internal.t.g(this$0, "this$0");
        androidx.lifecycle.f0 f0Var = this$0.f11518r;
        boolean z10 = false;
        if (proofingState != null && proofingState.isL1Authenticated()) {
            z10 = true;
        }
        f0Var.q(Boolean.valueOf(z10));
    }

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

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

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

    private final String v0() {
        return (String) this.f11520t.getValue();
    }

    private final String w0() {
        return (String) this.f11521u.getValue();
    }

    private final String x0() {
        return (String) this.f11522v.getValue();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean z0() {
        String str;
        CharSequence e12;
        CharSequence e13;
        String str2 = (String) this.f11523w.f();
        if (str2 != null) {
            String lowerCase = str2.toLowerCase(Locale.ROOT);
            kotlin.jvm.internal.t.f(lowerCase, "toLowerCase(...)");
            if (lowerCase != null) {
                e13 = kotlin.text.z.e1(lowerCase);
                str = e13.toString();
                String lowerCase2 = v0().toLowerCase(Locale.ROOT);
                kotlin.jvm.internal.t.f(lowerCase2, "toLowerCase(...)");
                e12 = kotlin.text.z.e1(lowerCase2);
                return !kotlin.jvm.internal.t.b(str, e12.toString());
            }
        }
        str = null;
        String lowerCase22 = v0().toLowerCase(Locale.ROOT);
        kotlin.jvm.internal.t.f(lowerCase22, "toLowerCase(...)");
        e12 = kotlin.text.z.e1(lowerCase22);
        return !kotlin.jvm.internal.t.b(str, e12.toString());
    }

    public final void G0() {
        d0(new b(null));
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.lifecycle.z0
    public void O() {
        this.f11516p.c().o(this.f11519s);
        this.f11523w.o(this.f11526z);
        this.f11524x.o(this.A);
        super.O();
    }

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

    @Override // r8.b
    public boolean e() {
        return z0() || A0() || B0();
    }

    @Override // r8.b
    public boolean g() {
        return C0() && D0();
    }

    public final androidx.lifecycle.f0 r0() {
        return this.f11523w;
    }

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

    public final androidx.lifecycle.f0 t0() {
        return this.f11524x;
    }

    public final androidx.lifecycle.a0 u0() {
        return this.E;
    }

    public final androidx.lifecycle.f0 y0() {
        return this.f11525y;
    }
}
