package qd;

import androidx.lifecycle.a0;
import androidx.lifecycle.a1;
import androidx.lifecycle.f0;
import androidx.lifecycle.z0;
import ca.canadapost.core.data.model.CoreConstants;
import ca.canadapost.core.data.model.ResultWrapper;
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 a extends z0 implements l8.h, l8.c {

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

    /* renamed from: c, reason: collision with root package name */
    private final g9.l f33570c;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /* renamed from: qd.a$a, reason: collision with other inner class name */
    /* loaded from: classes4.dex */
    static final class C0778a extends kotlin.jvm.internal.v implements dn.a {
        C0778a() {
            super(0);
        }

        @Override // dn.a
        public final String invoke() {
            if (kotlin.jvm.internal.t.b(a.this.f33571d, CoreConstants.VERIFICATION_METHOD_PHONE)) {
                return a.this.f33569b.d(ld.m.f27973b0, a.this.f33572e.Q());
            }
            return a.this.f33569b.d(ld.m.f27975c0, a.this.f33572e.P());
        }
    }

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

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

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f33587p;
            if (i10 == 0) {
                y.b(obj);
                g9.l lVar = a.this.f33570c;
                String str = (String) a.this.f33572e.T().f();
                if (str == null) {
                    str = "";
                }
                String str2 = a.this.f33571d;
                this.f33587p = 1;
                obj = lVar.m(str, str2, 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.f33589r) {
                    a.this.f33583p.s();
                }
            } else if (resultWrapper instanceof ResultWrapper.Error) {
                a.this.e0((ResultWrapper.Error) resultWrapper, true);
            }
            return n0.f34904a;
        }

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

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

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

        c(vm.d dVar) {
            super(2, dVar);
        }

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f33590p;
            if (i10 == 0) {
                y.b(obj);
                g9.l lVar = a.this.f33570c;
                String str = (String) a.this.f33572e.T().f();
                if (str == null) {
                    str = "";
                }
                String str2 = (String) a.this.a0().f();
                if (str2 == null) {
                    str2 = "";
                }
                String str3 = (String) a.this.W().f();
                String str4 = str3 != null ? str3 : "";
                this.f33590p = 1;
                obj = lVar.g(str, str2, str4, 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) {
                a.this.f33581n.s();
            } else if (resultWrapper instanceof ResultWrapper.Error) {
                a.this.e0((ResultWrapper.Error) resultWrapper, true);
            }
            return n0.f34904a;
        }

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

    public a(t7.c contextService, g9.l userAuthenticationRepository, String verificationMethod, ld.n sharedViewModel) {
        rm.o a10;
        kotlin.jvm.internal.t.g(contextService, "contextService");
        kotlin.jvm.internal.t.g(userAuthenticationRepository, "userAuthenticationRepository");
        kotlin.jvm.internal.t.g(verificationMethod, "verificationMethod");
        kotlin.jvm.internal.t.g(sharedViewModel, "sharedViewModel");
        this.f33569b = contextService;
        this.f33570c = userAuthenticationRepository;
        this.f33571d = verificationMethod;
        this.f33572e = sharedViewModel;
        this.f33573f = new l8.i(contextService);
        this.f33574g = new l8.d();
        this.f33575h = new f0();
        this.f33576i = new f0();
        this.f33577j = new f0();
        this.f33578k = new f0();
        f0 f0Var = new f0(Boolean.TRUE);
        this.f33579l = f0Var;
        this.f33580m = f0Var;
        l8.g gVar = new l8.g();
        this.f33581n = gVar;
        this.f33582o = gVar;
        l8.g gVar2 = new l8.g();
        this.f33583p = gVar2;
        this.f33584q = gVar2;
        a10 = rm.q.a(new C0778a());
        this.f33585r = a10;
        V(false);
    }

    private final void V(boolean z10) {
        h.a.a(this, a1.a(this), null, null, null, new b(z10, null), 7, null);
    }

    private final boolean f0() {
        i0();
        CharSequence charSequence = (CharSequence) this.f33575h.f();
        if (!(charSequence == null || charSequence.length() == 0)) {
            String str = (String) this.f33575h.f();
            if ((str != null ? str.length() : 0) >= 6) {
                if (qa.d.j((String) this.f33576i.f())) {
                    return true;
                }
                k0();
                return false;
            }
        }
        j0();
        return false;
    }

    private final void i0() {
        this.f33577j.q(null);
        this.f33578k.q(null);
    }

    private final void j0() {
        this.f33577j.q(this.f33569b.getString(ld.m.f28020z));
    }

    private final void k0() {
        this.f33578k.q(this.f33569b.getString(ld.m.A));
    }

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

    public final f0 W() {
        return this.f33575h;
    }

    public final f0 X() {
        return this.f33577j;
    }

    public final String Y() {
        Object value = this.f33585r.getValue();
        kotlin.jvm.internal.t.f(value, "getValue(...)");
        return (String) value;
    }

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

    public final f0 a0() {
        return this.f33576i;
    }

    public final a0 b0() {
        return this.f33584q;
    }

    public final a0 c0() {
        return this.f33582o;
    }

    public final f0 d0() {
        return this.f33578k;
    }

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

    public final void g0() {
        if (f0()) {
            h.a.a(this, a1.a(this), null, null, null, new c(null), 7, null);
        }
    }

    public final void h0() {
        V(true);
    }

    public final void l0() {
        this.f33579l.q(Boolean.valueOf(!kotlin.jvm.internal.t.b(r2.f(), Boolean.TRUE)));
    }

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

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