package qb;

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.model.ResultWrapper;
import ca.canadapost.core.data.profile.model.AMSPrerequisitesResponse;
import d9.f;
import dn.p;
import java.util.ArrayList;
import kn.l;
import kotlin.jvm.internal.g0;
import kotlin.jvm.internal.p0;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import l8.g;
import l8.h;
import l8.i;
import rm.n0;
import rm.y;
import tp.m0;
import tp.o0;
import tp.u1;

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

    /* renamed from: u, reason: collision with root package name */
    static final /* synthetic */ l[] f33528u = {p0.h(new g0(c.class, "doubleClickGuard", "getDoubleClickGuard()Z", 0))};

    /* renamed from: v, reason: collision with root package name */
    public static final int f33529v = 8;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            this.f33549q = obj;
            this.f33551s |= Integer.MIN_VALUE;
            return c.this.Y(this);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public static final class b extends v implements dn.a {
        b() {
            super(0);
        }

        @Override // dn.a
        public /* bridge */ /* synthetic */ Object invoke() {
            m402invoke();
            return n0.f34904a;
        }

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m402invoke() {
            if (c.this.a0()) {
                return;
            }
            c.this.f33538k.s();
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: qb.c$c, reason: collision with other inner class name */
    /* loaded from: classes4.dex */
    public static final class C0776c extends v implements dn.a {
        C0776c() {
            super(0);
        }

        @Override // dn.a
        public /* bridge */ /* synthetic */ Object invoke() {
            m403invoke();
            return n0.f34904a;
        }

        /* renamed from: invoke, reason: collision with other method in class */
        public final void m403invoke() {
            if (c.this.a0()) {
                return;
            }
            c.this.f33540m.s();
        }
    }

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

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

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

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

        @Override // kotlin.coroutines.jvm.internal.a
        public final Object invokeSuspend(Object obj) {
            Object f10;
            f10 = wm.d.f();
            int i10 = this.f33554p;
            if (i10 == 0) {
                y.b(obj);
                c cVar = c.this;
                this.f33554p = 1;
                if (cVar.Y(this) == f10) {
                    return f10;
                }
            } else {
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                y.b(obj);
            }
            if (t.b(c.this.f33544q.f(), kotlin.coroutines.jvm.internal.b.a(true))) {
                c.this.h0();
            }
            return n0.f34904a;
        }

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

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public c(f analyticsService, t7.c contextService, g9.d sessionRepository, ka.b userProfileRepository) {
        super((Application) r0);
        t.g(analyticsService, "analyticsService");
        t.g(contextService, "contextService");
        t.g(sessionRepository, "sessionRepository");
        t.g(userProfileRepository, "userProfileRepository");
        Context a10 = contextService.a();
        t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f33530c = analyticsService;
        this.f33531d = sessionRepository;
        this.f33532e = userProfileRepository;
        this.f33533f = new l8.d();
        this.f33534g = new i(contextService);
        this.f33535h = new l8.e(false, 0L, 3, null);
        f0 f0Var = new f0();
        this.f33536i = f0Var;
        this.f33537j = f0Var;
        g gVar = new g();
        this.f33538k = gVar;
        this.f33539l = gVar;
        g gVar2 = new g();
        this.f33540m = gVar2;
        this.f33541n = gVar2;
        g gVar3 = new g();
        this.f33542o = gVar3;
        this.f33543p = gVar3;
        this.f33544q = new f0(Boolean.FALSE);
        g gVar4 = new g();
        this.f33545r = gVar4;
        this.f33546s = gVar4;
        androidx.lifecycle.g0 g0Var = new androidx.lifecycle.g0() { // from class: qb.b
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                c.X(c.this, (AMSPrerequisitesResponse) obj);
            }
        };
        userProfileRepository.J().k(g0Var);
        this.f33547t = g0Var;
        f.a.c(analyticsService, "account_automatictracking_screen", null, 2, null);
        Z();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void X(c this$0, AMSPrerequisitesResponse aMSPrerequisitesResponse) {
        Boolean bool;
        t.g(this$0, "this$0");
        g gVar = this$0.f33545r;
        if (aMSPrerequisitesResponse == null || (bool = aMSPrerequisitesResponse.getStatus()) == null) {
            bool = Boolean.FALSE;
        }
        gVar.q(bool);
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Removed duplicated region for block: B:12:0x006c  */
    /* JADX WARN: Removed duplicated region for block: B:16:0x0076  */
    /* JADX WARN: Removed duplicated region for block: B:21:0x0036  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x0024  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object Y(vm.d dVar) {
        a aVar;
        Object f10;
        int i10;
        ResultWrapper resultWrapper;
        if (dVar instanceof a) {
            aVar = (a) dVar;
            int i11 = aVar.f33551s;
            if ((i11 & Integer.MIN_VALUE) != 0) {
                aVar.f33551s = i11 - Integer.MIN_VALUE;
                Object obj = aVar.f33549q;
                f10 = wm.d.f();
                i10 = aVar.f33551s;
                if (i10 != 0) {
                    y.b(obj);
                    if ((this.f33545r.f() == null || t.b(this.f33545r.f(), kotlin.coroutines.jvm.internal.b.a(false))) && this.f33531d.h()) {
                        ka.b bVar = this.f33532e;
                        aVar.f33548p = this;
                        aVar.f33551s = 1;
                        obj = bVar.m(true, aVar);
                        if (obj == f10) {
                            return f10;
                        }
                    }
                    return n0.f34904a;
                }
                if (i10 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                this = (c) aVar.f33548p;
                y.b(obj);
                resultWrapper = (ResultWrapper) obj;
                if (!(resultWrapper instanceof ResultWrapper.Success)) {
                    this.f33544q.q(kotlin.coroutines.jvm.internal.b.a(true));
                } else if (resultWrapper instanceof ResultWrapper.Error) {
                    this.f0((ResultWrapper.Error) resultWrapper, true);
                    this.f33544q.q(kotlin.coroutines.jvm.internal.b.a(false));
                }
                return n0.f34904a;
            }
        }
        aVar = new a(dVar);
        Object obj2 = aVar.f33549q;
        f10 = wm.d.f();
        i10 = aVar.f33551s;
        if (i10 != 0) {
        }
        resultWrapper = (ResultWrapper) obj2;
        if (!(resultWrapper instanceof ResultWrapper.Success)) {
        }
        return n0.f34904a;
    }

    private final void Z() {
        ArrayList arrayList = new ArrayList();
        arrayList.add(new qb.a());
        arrayList.add(new e(ob.l.J0, false, new b()));
        arrayList.add(new e(ob.l.K0, false, new C0776c()));
        this.f33536i.q(arrayList);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final boolean a0() {
        return this.f33535h.a(this, f33528u[0]).booleanValue();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void h0() {
        Boolean bool = (Boolean) this.f33545r.f();
        if (bool != null) {
            if (bool.booleanValue()) {
                k0("accountinfo_automatictracking_unsubscribe");
            } else {
                k0("accountinfo_automatictracking_subscribe");
            }
        }
        this.f33542o.q(this.f33545r.f());
    }

    private final void k0(String str) {
        this.f33530c.b(str, d9.e.f15943f.a("account_automatictracking_screen"));
    }

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

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // androidx.lifecycle.z0
    public void O() {
        this.f33532e.J().o(this.f33547t);
        super.O();
    }

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

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

    public final a0 d0() {
        return this.f33539l;
    }

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

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

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

    public final void i0() {
        h.a.a(this, a1.a(this), null, null, null, new d(null), 7, null);
    }

    public final void j0() {
        h0();
    }

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

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