package hd;

import android.app.Application;
import android.content.Context;
import androidx.lifecycle.a0;
import androidx.lifecycle.f0;
import androidx.lifecycle.g0;
import androidx.lifecycle.y0;
import ca.canadapost.core.data.auth.model.BarCode;
import ca.canadapost.core.data.auth.model.ProofingProfile;
import ca.canadapost.core.data.auth.model.ProofingState;
import ca.canadapost.core.data.model.RepositoryError;
import ca.canadapost.core.data.model.ResultWrapper;
import java.time.Month;
import java.time.format.TextStyle;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import kotlin.jvm.internal.t;
import kotlin.jvm.internal.v;
import kotlin.text.z;

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

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

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

    /* renamed from: e, reason: collision with root package name */
    private final ca.a f21536e;

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

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

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

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

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

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

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

    /* loaded from: classes4.dex */
    static final class a extends v implements dn.l {
        a() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final String invoke(ProofingProfile proofingProfile) {
            String proofingExpiryTms;
            int g02;
            CharSequence y02;
            List H0;
            if (proofingProfile == null || (proofingExpiryTms = proofingProfile.getProofingExpiryTms()) == null) {
                return null;
            }
            g gVar = g.this;
            g02 = z.g0(proofingExpiryTms, 'T', 0, false, 6, null);
            y02 = z.y0(proofingExpiryTms, g02, proofingExpiryTms.length());
            H0 = z.H0(y02.toString(), new char[]{'-'}, false, 0, 6, null);
            String str = (String) H0.get(2);
            String str2 = (String) H0.get(1);
            String str3 = (String) H0.get(0);
            if (gVar.f21536e.b()) {
                return gVar.Z(Integer.parseInt(str2)) + " " + str + ", " + str3;
            }
            String lowerCase = gVar.Z(Integer.parseInt(str2)).toLowerCase(Locale.ROOT);
            t.f(lowerCase, "toLowerCase(...)");
            return str + " " + lowerCase + " " + str3;
        }
    }

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

        /* renamed from: p, reason: collision with root package name */
        public static final b f21545p = new b();

        b() {
            super(1);
        }

        @Override // dn.l
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public final ProofingProfile invoke(ProofingState proofingState) {
            if (proofingState == null || proofingState.getProofingProfiles().isEmpty()) {
                return null;
            }
            return proofingState.getProofingProfiles().get(0);
        }
    }

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public g(g9.i l2Repository, ja.d sharedPreferencesService, ca.a languageService, t7.c contextService, d9.f analyticsService) {
        super((Application) r5);
        t.g(l2Repository, "l2Repository");
        t.g(sharedPreferencesService, "sharedPreferencesService");
        t.g(languageService, "languageService");
        t.g(contextService, "contextService");
        t.g(analyticsService, "analyticsService");
        Context a10 = contextService.a();
        t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f21534c = l2Repository;
        this.f21535d = sharedPreferencesService;
        this.f21536e = languageService;
        this.f21537f = analyticsService;
        this.f21538g = new l8.d();
        a0 a11 = y0.a(l2Repository.c(), b.f21545p);
        this.f21539h = a11;
        f0 f0Var = new f0();
        this.f21540i = f0Var;
        this.f21541j = f0Var;
        g0 g0Var = new g0() { // from class: hd.f
            @Override // androidx.lifecycle.g0
            public final void d(Object obj) {
                g.T(g.this, (ProofingProfile) obj);
            }
        };
        this.f21542k = g0Var;
        this.f21543l = y0.a(a11, new a());
        V();
        a0();
        U();
        a11.k(g0Var);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void T(g this$0, ProofingProfile proofingProfile) {
        BarCode barCode;
        t.g(this$0, "this$0");
        this$0.f21540i.q((proofingProfile == null || (barCode = proofingProfile.getBarCode()) == null) ? null : barCode.getBarCodeNbr());
    }

    private final void U() {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("e.Var13", this.f21534c.o());
        this.f21537f.c("Common_Retail_Barcode_L2Auth", linkedHashMap);
    }

    private final void V() {
        ProofingState proofingState = (ProofingState) this.f21534c.c().f();
        if ((proofingState != null ? proofingState.getIncompleteProofingProfile() : null) == null) {
            Y(new ResultWrapper.Error(null, null, RepositoryError.Unknown, null, 8, null), true);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final String Z(int i10) {
        String displayName = Month.of(i10).getDisplayName(TextStyle.SHORT, this.f21536e.d());
        t.f(displayName, "getDisplayName(...)");
        if (!(displayName.length() > 0)) {
            return displayName;
        }
        StringBuilder sb2 = new StringBuilder();
        String valueOf = String.valueOf(displayName.charAt(0));
        t.e(valueOf, "null cannot be cast to non-null type java.lang.String");
        String upperCase = valueOf.toUpperCase(Locale.ROOT);
        t.f(upperCase, "toUpperCase(...)");
        sb2.append((Object) upperCase);
        String substring = displayName.substring(1);
        t.f(substring, "substring(...)");
        sb2.append(substring);
        return sb2.toString();
    }

    private final void a0() {
        ProofingState proofingState = (ProofingState) this.f21534c.c().f();
        if (!(proofingState != null && proofingState.isAccountLocked()) || this.f21535d.getBoolean("L1VERIFY_SHOW_CASE_DISPLAYED_ONCE", false)) {
            return;
        }
        this.f21535d.putBoolean("SHOW_CASE_VIEW_FOR_L1VERIFY", true);
    }

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

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

    public final a0 X() {
        return this.f21541j;
    }

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

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

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