package ca.canadapost.module.l1auth;

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.Name;
import ca.canadapost.core.data.auth.model.VerifyDobFlow;
import ca.canadapost.core.data.model.RepositoryError;
import ca.canadapost.core.data.model.ResultWrapper;
import d9.f;
import dn.p;
import java.util.Date;
import java.util.Map;
import kotlin.coroutines.jvm.internal.l;
import kotlin.jvm.internal.t;
import l8.g;
import l8.h;
import l8.i;
import rm.c0;
import rm.n0;
import rm.y;
import sm.p0;
import tp.m0;
import tp.o0;
import tp.u1;

/* loaded from: classes4.dex */
public final class d extends androidx.lifecycle.b implements h, l8.c {

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

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

    /* renamed from: e, reason: collision with root package name */
    private final VerifyDobFlow f9681e;

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

    /* renamed from: g, reason: collision with root package name */
    private final /* synthetic */ i f9683g;

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

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

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

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

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

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

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

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

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

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

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

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

    /* loaded from: classes4.dex */
    public /* synthetic */ class a {

        /* renamed from: a, reason: collision with root package name */
        public static final /* synthetic */ int[] f9696a;

        static {
            int[] iArr = new int[VerifyDobFlow.values().length];
            try {
                iArr[VerifyDobFlow.INITIAL_FAIL.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[VerifyDobFlow.UPDATE_DOB.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[VerifyDobFlow.DONT_HAVE_MOBILE.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            f9696a = iArr;
        }
    }

    /* loaded from: classes4.dex */
    static final class b extends l implements p {

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

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

        /* renamed from: s, reason: collision with root package name */
        final /* synthetic */ ka.a f9700s;

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f9697p;
            if (i10 == 0) {
                y.b(obj);
                g9.h hVar = d.this.f9680d;
                Name name = this.f9699r;
                ka.a aVar = this.f9700s;
                this.f9697p = 1;
                obj = hVar.j(name, aVar, 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) {
                d.this.f9694r.s();
            } else if (resultWrapper instanceof ResultWrapper.Error) {
                d.this.Y((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);
        }
    }

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public d(t7.c contextService, g9.h l1AuthRepository, VerifyDobFlow verifyDobFlow, f analyticsService) {
        super((Application) r0);
        String string;
        t.g(contextService, "contextService");
        t.g(l1AuthRepository, "l1AuthRepository");
        t.g(verifyDobFlow, "verifyDobFlow");
        t.g(analyticsService, "analyticsService");
        Context a10 = contextService.a();
        t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f9679c = contextService;
        this.f9680d = l1AuthRepository;
        this.f9681e = verifyDobFlow;
        this.f9682f = analyticsService;
        this.f9683g = new i(contextService);
        this.f9684h = new l8.d();
        int i10 = a.f9696a[verifyDobFlow.ordinal()];
        if (i10 == 1) {
            string = contextService.getString(yc.a0.f52082e);
            t.f(string, "getString(...)");
        } else if (i10 == 2) {
            string = contextService.getString(yc.a0.f52081d);
            t.f(string, "getString(...)");
        } else {
            if (i10 != 3) {
                throw new rm.t();
            }
            string = contextService.getString(yc.a0.f52080c);
            t.f(string, "getString(...)");
        }
        this.f9685i = string;
        g gVar = new g();
        this.f9686j = gVar;
        this.f9687k = gVar;
        f0 f0Var = new f0();
        this.f9688l = f0Var;
        this.f9689m = f0Var;
        g gVar2 = new g();
        this.f9690n = gVar2;
        this.f9691o = gVar2;
        Date date = (Date) l1AuthRepository.f().f();
        this.f9692p = date;
        this.f9693q = new f0(date != null ? qa.b.b(date, VerifyDobFragment.INSTANCE.a()) : null);
        g gVar3 = new g();
        this.f9694r = gVar3;
        this.f9695s = gVar3;
        f.a.c(analyticsService, "Date of Birth Page", null, 2, null);
    }

    private final boolean Z() {
        Object f10 = this.f9693q.f();
        return !t.b(f10, this.f9692p != null ? qa.b.b(r2, VerifyDobFragment.INSTANCE.a()) : null);
    }

    private final void d0(String str) {
        Map e10;
        f fVar = this.f9682f;
        e10 = p0.e(c0.a("e.Var3", "Date of Birth Page"));
        fVar.b(str, e10);
    }

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

    public final f0 S() {
        return this.f9693q;
    }

    public final a0 T() {
        return this.f9689m;
    }

    public final a0 U() {
        return this.f9687k;
    }

    public final a0 V() {
        return this.f9695s;
    }

    public final a0 W() {
        return this.f9691o;
    }

    public final String X() {
        return this.f9685i;
    }

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

    public final void a0() {
        d0("Save_button_click_Adobe");
        String str = (String) this.f9693q.f();
        if (str == null || str.length() == 0) {
            this.f9688l.q(this.f9679c.getString(yc.a0.f52079b));
            return;
        }
        if (Z()) {
            this.f9680d.f().q(qa.b.a(str, VerifyDobFragment.INSTANCE.a()));
        }
        this.f9686j.s();
    }

    public final void b0() {
        if (Z()) {
            this.f9690n.s();
        } else {
            this.f9686j.s();
        }
    }

    public final void c0() {
        d0("Verify_at_post_office_link_click_Adobe");
        ka.a aVar = (ka.a) this.f9680d.i().f();
        Name name = (Name) this.f9680d.d().f();
        if (aVar == null || name == null) {
            Y(new ResultWrapper.Error(null, null, RepositoryError.Unknown, null, 8, null), true);
        } else {
            h.a.a(this, a1.a(this), null, null, null, new b(name, aVar, null), 7, null);
        }
    }

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

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

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