package hd;

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.VerifyAccessCodeResponse;
import ca.canadapost.core.data.model.PhoneNumber;
import ca.canadapost.core.data.model.ResultWrapper;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import kotlin.jvm.internal.g0;
import kotlin.jvm.internal.p0;
import kotlin.jvm.internal.t;
import l8.h;
import rm.c0;
import rm.n0;
import rm.y;
import sm.q0;
import tp.m0;
import tp.o0;
import tp.u1;
import tp.w0;

/* loaded from: classes4.dex */
public final class a extends androidx.lifecycle.b implements l8.h, l8.c {
    static final /* synthetic */ kn.l[] A = {p0.h(new g0(a.class, "doubleClickGuardResendCode", "getDoubleClickGuardResendCode()Z", 0)), p0.h(new g0(a.class, "doubleClickGuard", "getDoubleClickGuard()Z", 0))};

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /* renamed from: w, reason: collision with root package name */
    private boolean f21509w;

    /* renamed from: x, reason: collision with root package name */
    private int f21510x;

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

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

    /* renamed from: hd.a$a, reason: collision with other inner class name */
    /* loaded from: classes4.dex */
    static final class C0460a extends kotlin.coroutines.jvm.internal.l implements dn.p {

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f21513p;
            if (i10 == 0) {
                y.b(obj);
                this.f21513p = 1;
                if (w0.a(200L, this) == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            a.this.f21501o.q(kotlin.coroutines.jvm.internal.b.a(true));
            a.this.f21503q.s();
            return n0.f34904a;
        }

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

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

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f21515p;
            if (i10 == 0) {
                y.b(obj);
                g9.i iVar = a.this.f21491e;
                this.f21515p = 1;
                obj = iVar.p(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.f21501o.q(kotlin.coroutines.jvm.internal.b.a(true));
                a.this.f21503q.s();
            } else if (resultWrapper instanceof ResultWrapper.Error) {
                a.this.k0((ResultWrapper.Error) resultWrapper, true);
                a.this.f21509w = true;
                a.this.f21501o.q(kotlin.coroutines.jvm.internal.b.a(false));
            }
            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 f21517p;

        /* JADX INFO: Access modifiers changed from: package-private */
        /* renamed from: hd.a$c$a, reason: collision with other inner class name */
        /* loaded from: classes4.dex */
        public static final class C0461a extends kotlin.coroutines.jvm.internal.l implements dn.p {

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

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

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

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

            @Override // kotlin.coroutines.jvm.internal.a
            public final Object invokeSuspend(Object obj) {
                Object f10;
                f10 = wm.d.f();
                int i10 = this.f21519p;
                if (i10 == 0) {
                    y.b(obj);
                    a aVar = this.f21520q;
                    this.f21519p = 1;
                    if (aVar.o0(this) == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    y.b(obj);
                }
                this.f21520q.f21505s.s();
                return n0.f34904a;
            }

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

        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;
            Map p10;
            f10 = wm.d.f();
            int i10 = this.f21517p;
            if (i10 == 0) {
                y.b(obj);
                g9.i iVar = a.this.f21491e;
                String valueOf = String.valueOf(a.this.f21491e.n().f());
                String str = (String) a.this.d0().f();
                if (str == null) {
                    str = "";
                }
                boolean z10 = a.this.f21510x == 10;
                this.f21517p = 1;
                obj = iVar.m(valueOf, str, z10, this);
                if (obj == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    if (i10 != 2) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    y.b(obj);
                    a.this.f21505s.s();
                    return n0.f34904a;
                }
                y.b(obj);
            }
            ResultWrapper resultWrapper = (ResultWrapper) obj;
            if (resultWrapper instanceof ResultWrapper.Success) {
                String status = ((VerifyAccessCodeResponse) ((ResultWrapper.Success) resultWrapper).getData()).getStatus();
                String lowerCase = "SUCCESS".toLowerCase(Locale.ROOT);
                t.f(lowerCase, "toLowerCase(...)");
                if (t.b(status, lowerCase)) {
                    d9.f fVar = a.this.f21492f;
                    p10 = q0.p(d9.e.f15943f.a("L2 - 2SV_Success"), c0.a("e.Var13", a.this.f21491e.o()));
                    fVar.b("L2_2SV_Success_account_verified", p10);
                    a.this.f21497k.s();
                    a.this.f21510x = 1;
                } else if (a.this.f21510x == 10) {
                    a aVar = a.this;
                    h.a.a(aVar, a1.a(aVar), null, null, null, new C0461a(a.this, null), 7, null);
                } else {
                    a.this.n0();
                    a.this.f21510x++;
                }
            } else if (resultWrapper instanceof ResultWrapper.Error) {
                if (a.this.f21510x == 10) {
                    a aVar2 = a.this;
                    this.f21517p = 2;
                    if (aVar2.o0(this) == f10) {
                        return f10;
                    }
                    a.this.f21505s.s();
                } else {
                    a.this.f21510x++;
                    a.this.k0((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);
        }
    }

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

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

        /* renamed from: q, reason: collision with root package name */
        /* synthetic */ Object f21522q;

        /* renamed from: s, reason: collision with root package name */
        int f21524s;

        d(vm.d dVar) {
            super(dVar);
        }

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f21522q = obj;
            this.f21524s |= Integer.MIN_VALUE;
            return a.this.o0(this);
        }
    }

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public a(t7.c contextService, g9.h l1AuthRepository, g9.i l2Repository, d9.f analyticsService, ka.b userProfileRepository) {
        super((Application) r0);
        t.g(contextService, "contextService");
        t.g(l1AuthRepository, "l1AuthRepository");
        t.g(l2Repository, "l2Repository");
        t.g(analyticsService, "analyticsService");
        t.g(userProfileRepository, "userProfileRepository");
        Context a10 = contextService.a();
        t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f21489c = contextService;
        this.f21490d = l1AuthRepository;
        this.f21491e = l2Repository;
        this.f21492f = analyticsService;
        this.f21493g = userProfileRepository;
        this.f21494h = new l8.i(contextService);
        this.f21495i = new l8.d();
        this.f21496j = new f0();
        l8.g gVar = new l8.g();
        this.f21497k = gVar;
        this.f21498l = gVar;
        f0 f0Var = new f0();
        this.f21499m = f0Var;
        this.f21500n = f0Var;
        f0 f0Var2 = new f0();
        this.f21501o = f0Var2;
        this.f21502p = f0Var2;
        l8.g gVar2 = new l8.g();
        this.f21503q = gVar2;
        this.f21504r = gVar2;
        l8.g gVar3 = new l8.g();
        this.f21505s = gVar3;
        this.f21506t = gVar3;
        PhoneNumber phoneNumber = (PhoneNumber) l2Repository.b().f();
        this.f21507u = phoneNumber;
        this.f21508v = phoneNumber != null ? phoneNumber.getSuffix() : null;
        this.f21510x = 1;
        this.f21511y = new l8.e(false, 30000L);
        this.f21512z = new l8.e(false, 0L, 3, null);
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("e.Var13", l2Repository.o());
        analyticsService.c("L2 - 2SV_Login", linkedHashMap);
    }

    private final boolean b0() {
        return this.f21512z.a(this, A[1]).booleanValue();
    }

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

    /* JADX INFO: Access modifiers changed from: private */
    public final void n0() {
        this.f21499m.q(this.f21489c.getString(ed.m.f16965v));
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:20:0x007b A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:24:0x006d A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:25:0x0047  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0025  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object o0(vm.d dVar) {
        d dVar2;
        Object f10;
        int i10;
        g9.h hVar;
        g9.i iVar;
        if (dVar instanceof d) {
            dVar2 = (d) dVar;
            int i11 = dVar2.f21524s;
            if ((i11 & Integer.MIN_VALUE) != 0) {
                dVar2.f21524s = i11 - Integer.MIN_VALUE;
                Object obj = dVar2.f21522q;
                f10 = wm.d.f();
                i10 = dVar2.f21524s;
                if (i10 != 0) {
                    y.b(obj);
                    ka.b bVar = this.f21493g;
                    dVar2.f21521p = this;
                    dVar2.f21524s = 1;
                    if (bVar.m(true, dVar2) == f10) {
                        return f10;
                    }
                } else {
                    if (i10 != 1) {
                        if (i10 != 2) {
                            if (i10 != 3) {
                                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                            }
                            y.b(obj);
                            return n0.f34904a;
                        }
                        this = (a) dVar2.f21521p;
                        y.b(obj);
                        iVar = this.f21491e;
                        dVar2.f21521p = null;
                        dVar2.f21524s = 3;
                        if (iVar.k(dVar2) == f10) {
                            return f10;
                        }
                        return n0.f34904a;
                    }
                    this = (a) dVar2.f21521p;
                    y.b(obj);
                }
                this.f21490d.g();
                this.f21491e.g();
                hVar = this.f21490d;
                dVar2.f21521p = this;
                dVar2.f21524s = 2;
                if (hVar.k(dVar2) == f10) {
                    return f10;
                }
                iVar = this.f21491e;
                dVar2.f21521p = null;
                dVar2.f21524s = 3;
                if (iVar.k(dVar2) == f10) {
                }
                return n0.f34904a;
            }
        }
        dVar2 = new d(dVar);
        Object obj2 = dVar2.f21522q;
        f10 = wm.d.f();
        i10 = dVar2.f21524s;
        if (i10 != 0) {
        }
        this.f21490d.g();
        this.f21491e.g();
        hVar = this.f21490d;
        dVar2.f21521p = this;
        dVar2.f21524s = 2;
        if (hVar.k(dVar2) == f10) {
        }
        iVar = this.f21491e;
        dVar2.f21521p = null;
        dVar2.f21524s = 3;
        if (iVar.k(dVar2) == f10) {
        }
        return n0.f34904a;
    }

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

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

    public final a0 e0() {
        return this.f21500n;
    }

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

    public final a0 g0() {
        return this.f21498l;
    }

    public final String h0() {
        return this.f21508v;
    }

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

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

    public void k0(ResultWrapper.Error error, boolean z10) {
        t.g(error, "error");
        this.f21495i.a(error, z10);
    }

    public final void l0() {
        this.f21501o.q(Boolean.FALSE);
        if (c0() && !this.f21509w) {
            tp.k.d(a1.a(this), null, null, new C0460a(null), 3, null);
            return;
        }
        this.f21509w = false;
        this.f21510x = 1;
        tp.k.d(a1.a(this), null, null, new b(null), 3, null);
    }

    public final void m0() {
        if (b0()) {
            return;
        }
        CharSequence charSequence = (CharSequence) this.f21496j.f();
        if (!(charSequence == null || charSequence.length() == 0)) {
            String str = (String) this.f21496j.f();
            if ((str != null ? str.length() : 0) >= 6) {
                this.f21499m.q(null);
                tp.k.d(a1.a(this), null, null, new c(null), 3, null);
                return;
            }
        }
        n0();
    }

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

    @Override // l8.c
    public a0 t() {
        return this.f21495i.t();
    }

    @Override // l8.h
    public u1 u(m0 m0Var, vm.g context, o0 start, String str, dn.p block) {
        t.g(m0Var, "<this>");
        t.g(context, "context");
        t.g(start, "start");
        t.g(block, "block");
        return this.f21494h.u(m0Var, context, start, str, block);
    }
}
