package jg;

import android.app.Application;
import android.content.Context;
import ca.canadapost.core.data.db.cupboard.model.OutletAddress;
import ca.canadapost.core.data.db.cupboard.model.OutletDetail;
import ca.canadapost.core.data.db.cupboard.model.OutletHours;
import ca.canadapost.core.data.findpostoffice.GetOutletDetailResponseOutlet;
import ca.canadapost.core.data.model.Event;
import ca.canadapost.core.data.model.ResultWrapper;
import ca.canadapost.module.track.model.DeliveryPickupPass;
import ca.canadapost.module.track.model.PackageDetailsDTO;
import ca.canadapost.module.track.model.PackageItemModel;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/* loaded from: classes4.dex */
public final class n3 extends androidx.lifecycle.b {
    private PackageItemModel A;
    private final String B;
    private final String C;
    private final l8.g D;
    private final androidx.lifecycle.a0 E;

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

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

    /* renamed from: e, reason: collision with root package name */
    private final o9.c f24605e;

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

    /* renamed from: g, reason: collision with root package name */
    private final lg.a f24607g;

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

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

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

    /* renamed from: k, reason: collision with root package name */
    private final androidx.lifecycle.f0 f24611k;

    /* renamed from: l, reason: collision with root package name */
    private final androidx.lifecycle.f0 f24612l;

    /* renamed from: m, reason: collision with root package name */
    private final androidx.lifecycle.f0 f24613m;

    /* renamed from: n, reason: collision with root package name */
    private final androidx.lifecycle.f0 f24614n;

    /* renamed from: o, reason: collision with root package name */
    private final androidx.lifecycle.f0 f24615o;

    /* renamed from: p, reason: collision with root package name */
    private final androidx.lifecycle.f0 f24616p;

    /* renamed from: q, reason: collision with root package name */
    private final androidx.lifecycle.f0 f24617q;

    /* renamed from: r, reason: collision with root package name */
    private OutletAddress f24618r;

    /* renamed from: s, reason: collision with root package name */
    private final androidx.lifecycle.f0 f24619s;

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

    /* renamed from: u, reason: collision with root package name */
    private final androidx.lifecycle.f0 f24621u;

    /* renamed from: v, reason: collision with root package name */
    private final androidx.lifecycle.f0 f24622v;

    /* renamed from: w, reason: collision with root package name */
    private final androidx.lifecycle.a0 f24623w;

    /* renamed from: x, reason: collision with root package name */
    private final androidx.lifecycle.f0 f24624x;

    /* renamed from: y, reason: collision with root package name */
    private final androidx.lifecycle.a0 f24625y;

    /* renamed from: z, reason: collision with root package name */
    private w3 f24626z;

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

        public final void a(ResultWrapper resultWrapper) {
            if (!(resultWrapper instanceof ResultWrapper.Success)) {
                n3.this.f24624x.q(new Event(n3.this.f24604d.getString(yf.h.J1)));
                return;
            }
            Object data = ((ResultWrapper.Success) resultWrapper).getData();
            kotlin.jvm.internal.t.e(data, "null cannot be cast to non-null type kotlin.String");
            n3.this.f24622v.q((String) data);
        }

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

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

        public final void a(ResultWrapper resultWrapper) {
            if (resultWrapper instanceof ResultWrapper.Success) {
                n3.this.j0((OutletDetail) ((ResultWrapper.Success) resultWrapper).getData());
            } else {
                n3.this.e0().n(Boolean.FALSE);
            }
        }

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

    /* JADX WARN: Illegal instructions before constructor call */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public n3(fg.c repository, t7.c contextService, o9.c cpEventBus, ca.a languageService, lg.a trackGooglePassRepository, r9.e postOfficeService, g9.d cpcSessionRepository, ka.b userProfileRepository) {
        super((Application) r0);
        kotlin.jvm.internal.t.g(repository, "repository");
        kotlin.jvm.internal.t.g(contextService, "contextService");
        kotlin.jvm.internal.t.g(cpEventBus, "cpEventBus");
        kotlin.jvm.internal.t.g(languageService, "languageService");
        kotlin.jvm.internal.t.g(trackGooglePassRepository, "trackGooglePassRepository");
        kotlin.jvm.internal.t.g(postOfficeService, "postOfficeService");
        kotlin.jvm.internal.t.g(cpcSessionRepository, "cpcSessionRepository");
        kotlin.jvm.internal.t.g(userProfileRepository, "userProfileRepository");
        Context a10 = contextService.a();
        kotlin.jvm.internal.t.e(a10, "null cannot be cast to non-null type android.app.Application");
        this.f24603c = repository;
        this.f24604d = contextService;
        this.f24605e = cpEventBus;
        this.f24606f = languageService;
        this.f24607g = trackGooglePassRepository;
        this.f24608h = postOfficeService;
        this.f24609i = cpcSessionRepository;
        this.f24610j = userProfileRepository;
        androidx.lifecycle.f0 f0Var = new androidx.lifecycle.f0();
        this.f24611k = f0Var;
        this.f24612l = new androidx.lifecycle.f0();
        this.f24613m = new androidx.lifecycle.f0();
        this.f24614n = new androidx.lifecycle.f0();
        this.f24615o = new androidx.lifecycle.f0();
        this.f24616p = new androidx.lifecycle.f0();
        this.f24617q = new androidx.lifecycle.f0();
        androidx.lifecycle.f0 f0Var2 = new androidx.lifecycle.f0();
        this.f24619s = f0Var2;
        this.f24620t = new androidx.lifecycle.f0();
        this.f24621u = new androidx.lifecycle.f0(Boolean.TRUE);
        androidx.lifecycle.f0 f0Var3 = new androidx.lifecycle.f0();
        this.f24622v = f0Var3;
        this.f24623w = f0Var3;
        androidx.lifecycle.f0 f0Var4 = new androidx.lifecycle.f0();
        this.f24624x = f0Var4;
        this.f24625y = f0Var4;
        this.B = "cacheGetOutletDetailResponse";
        this.C = "cacheRetailLocIDKey";
        l8.g gVar = new l8.g();
        this.D = gVar;
        this.E = gVar;
        f0Var.q(contextService.getString(yf.h.f52568d3));
        f0Var2.q(Boolean.FALSE);
        g0();
    }

    private final void f0() {
        androidx.lifecycle.f0 Z0;
        String str;
        w3 w3Var = this.f24626z;
        if (w3Var == null || (Z0 = w3Var.Z0()) == null || (str = (String) Z0.f()) == null) {
            return;
        }
        this.f24608h.a(str, new b());
    }

    /* JADX INFO: Access modifiers changed from: private */
    public final void j0(OutletDetail outletDetail) {
        GetOutletDetailResponseOutlet getOutletDetailResponseOutlet = new GetOutletDetailResponseOutlet();
        getOutletDetailResponseOutlet.location = outletDetail.location;
        getOutletDetailResponseOutlet.name = outletDetail.name;
        getOutletDetailResponseOutlet.number = outletDetail.number;
        getOutletDetailResponseOutlet.hoursList = outletDetail.getHoursList();
        getOutletDetailResponseOutlet.address = outletDetail.getAddress();
        k0(getOutletDetailResponseOutlet);
    }

    private final void k0(GetOutletDetailResponseOutlet getOutletDetailResponseOutlet) {
        this.f24612l.n(getOutletDetailResponseOutlet.fullAddressDescription());
        this.f24613m.n(getOutletDetailResponseOutlet.nameAndAddressDescription());
        this.f24614n.n(qa.d.b(getOutletDetailResponseOutlet.location));
        androidx.lifecycle.f0 f0Var = this.f24617q;
        List<? extends OutletHours> list = getOutletDetailResponseOutlet.hoursList;
        kotlin.jvm.internal.t.d(list);
        f0Var.n(list);
        List<? extends OutletHours> list2 = getOutletDetailResponseOutlet.hoursList;
        kotlin.jvm.internal.t.d(list2);
        for (OutletHours outletHours : list2) {
            outletHours.contentDescription = i0(outletHours, this.f24606f.b());
        }
        androidx.lifecycle.f0 f0Var2 = this.f24616p;
        String l02 = l0(getOutletDetailResponseOutlet, this.f24604d);
        kotlin.jvm.internal.t.d(l02);
        f0Var2.n(l02);
        OutletAddress outletAddress = getOutletDetailResponseOutlet.address;
        this.f24618r = outletAddress;
        this.f24615o.n(String.valueOf(outletAddress));
        this.f24619s.n(Boolean.TRUE);
    }

    private final String l0(GetOutletDetailResponseOutlet getOutletDetailResponseOutlet, t7.c cVar) {
        boolean z10;
        if (getOutletDetailResponseOutlet == null) {
            return null;
        }
        z10 = kotlin.text.y.z(getOutletDetailResponseOutlet.todayHoursWithAMPMDescription(), "–", true);
        if (!z10) {
            return getOutletDetailResponseOutlet.todayHoursWithAMPMDescription();
        }
        kotlin.jvm.internal.t.d(cVar);
        return cVar.getString(yf.h.f52564d);
    }

    public final void U() {
        PackageDetailsDTO details;
        androidx.lifecycle.f0 m02;
        String str;
        String itemNumber;
        w3 w3Var = this.f24626z;
        Double d10 = null;
        Long S0 = w3Var != null ? w3Var.S0() : null;
        Date date = S0 != null ? new Date(S0.longValue()) : null;
        OutletAddress outletAddress = this.f24618r;
        rm.v vVar = outletAddress != null ? new rm.v(outletAddress.latitude, outletAddress.longitude) : null;
        PackageItemModel packageItemModel = this.A;
        String str2 = (packageItemModel == null || (itemNumber = packageItemModel.getItemNumber()) == null) ? "" : itemNumber;
        w3 w3Var2 = this.f24626z;
        String str3 = (w3Var2 == null || (m02 = w3Var2.m0()) == null || (str = (String) m02.f()) == null) ? "" : str;
        PackageItemModel packageItemModel2 = this.A;
        String userDescription = packageItemModel2 != null ? packageItemModel2.getUserDescription() : null;
        String str4 = (String) this.f24614n.f();
        PackageItemModel packageItemModel3 = this.A;
        if (packageItemModel3 != null && (details = packageItemModel3.getDetails()) != null) {
            d10 = details.getCustomsAmtDue();
        }
        this.f24607g.b(new DeliveryPickupPass(str2, str3, userDescription, str4, vVar, d10, date), new a());
    }

    public final androidx.lifecycle.f0 V() {
        return this.f24613m;
    }

    public final androidx.lifecycle.a0 W() {
        return this.f24623w;
    }

    public final androidx.lifecycle.f0 X() {
        return this.f24617q;
    }

    public final androidx.lifecycle.a0 Y() {
        return this.E;
    }

    public final androidx.lifecycle.f0 Z() {
        return this.f24614n;
    }

    public final androidx.lifecycle.f0 a0() {
        return this.f24620t;
    }

    public final androidx.lifecycle.f0 b0() {
        return this.f24621u;
    }

    public final androidx.lifecycle.f0 c0() {
        return this.f24616p;
    }

    public final w3 d0() {
        return this.f24626z;
    }

    public final androidx.lifecycle.f0 e0() {
        return this.f24619s;
    }

    public final void g0() {
        String string;
        PackageItemModel G0;
        PackageDetailsDTO details;
        String custNm;
        PackageItemModel packageItemModel = (PackageItemModel) this.f24603c.c().f();
        this.A = packageItemModel;
        if (packageItemModel != null) {
            this.f24626z = new w3(packageItemModel, this.f24606f, this.f24604d, this.f24605e, null, this.f24609i, this.f24610j, 16, null);
        }
        f0();
        androidx.lifecycle.f0 f0Var = this.f24620t;
        w3 w3Var = this.f24626z;
        if (w3Var == null || (G0 = w3Var.G0()) == null || (details = G0.getDetails()) == null || (custNm = details.getCustNm()) == null || (string = this.f24604d.d(yf.h.T2, custNm)) == null) {
            string = this.f24604d.getString(yf.h.S2);
        }
        f0Var.q(string);
    }

    public final void h0() {
        this.D.q(this.f24615o.f());
    }

    public final String i0(OutletHours hours, boolean z10) {
        List I0;
        List I02;
        kotlin.jvm.internal.t.g(hours, "hours");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("h:mm aa");
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("HH:mm");
        try {
            String time = hours.amCounter.time;
            kotlin.jvm.internal.t.f(time, "time");
            int length = time.length() - 1;
            int i10 = 0;
            boolean z11 = false;
            while (i10 <= length) {
                boolean z12 = kotlin.jvm.internal.t.i(time.charAt(!z11 ? i10 : length), 32) <= 0;
                if (z11) {
                    if (!z12) {
                        break;
                    }
                    length--;
                } else if (z12) {
                    i10++;
                } else {
                    z11 = true;
                }
            }
            I0 = kotlin.text.z.I0(time.subSequence(i10, length + 1).toString(), new String[]{"-"}, false, 0, 6, null);
            String[] strArr = (String[]) I0.toArray(new String[0]);
            String time2 = hours.pmCounter.time;
            kotlin.jvm.internal.t.f(time2, "time");
            int length2 = time2.length() - 1;
            int i11 = 0;
            boolean z13 = false;
            while (i11 <= length2) {
                boolean z14 = kotlin.jvm.internal.t.i(time2.charAt(!z13 ? i11 : length2), 32) <= 0;
                if (z13) {
                    if (!z14) {
                        break;
                    }
                    length2--;
                } else if (z14) {
                    i11++;
                } else {
                    z13 = true;
                }
            }
            I02 = kotlin.text.z.I0(time2.subSequence(i11, length2 + 1).toString(), new String[]{"-"}, false, 0, 6, null);
            String[] strArr2 = (String[]) I02.toArray(new String[0]);
            StringBuffer stringBuffer = new StringBuffer();
            int i12 = 0;
            for (String str : strArr) {
                if (i12 > 0) {
                    stringBuffer.append(" to ");
                }
                if (z10) {
                    stringBuffer.append(simpleDateFormat.format(simpleDateFormat2.parse(str)));
                } else {
                    stringBuffer.append("de ");
                    String substring = str.substring(0, str.length() - 3);
                    kotlin.jvm.internal.t.f(substring, "substring(...)");
                    stringBuffer.append(substring);
                }
                i12++;
            }
            if (z10) {
                stringBuffer.append(" to ");
            } else {
                stringBuffer.append(" h â ");
            }
            int i13 = 0;
            for (String str2 : strArr2) {
                if (i13 > 0) {
                    stringBuffer.append(" to ");
                }
                if (z10) {
                    stringBuffer.append(simpleDateFormat.format(simpleDateFormat2.parse(str2)));
                } else {
                    String substring2 = str2.substring(0, str2.length() - 3);
                    kotlin.jvm.internal.t.f(substring2, "substring(...)");
                    stringBuffer.append(substring2);
                    stringBuffer.append(" h");
                }
                i13++;
            }
            return stringBuffer.toString();
        } catch (Exception e10) {
            tr.a.f36618a.d(e10, e10.getMessage(), new Object[0]);
            e10.printStackTrace();
            return null;
        }
    }
}
