class Z { constructor(B, V, q, te, be, de, ve, Se, Oe) { this.mrSitesService = B, this.mrContainersService = V, this.addressesResourceService = q, this.dateUtilsService = te, this.holidayScheduleService = be, this.mrUserService = de, this.translateService = ve, this.utilityService = Se, this.featureFlags = Oe } transformHolidaySchedule(B) { if (!B) return []; const V = B.filter(be=>(0, e.Z)(new Date(be.date), (0, i.Z)(new Date, { days: 5 }))); if (0 === V.length) return []; const q = {} , te = this.getHolidaysAndUpdateHolidaysByDateObject(V, q); return te.sort(), this.holidays = te.map(be=>{ const de = new Date(be); return { date: this.getFormattedDate(de), holidayImpact: { commercial: !!q[be].commercial && q[be].commercial.serviceImpacted, industrial: !!q[be].industrial && q[be].industrial.serviceImpacted, residential: !!q[be].residential && q[be].residential.serviceImpacted }, lobs: { commercial: !!q[be].commercial, industrial: !!q[be].industrial, residential: !!q[be].residential }, label: this.getHolidayLabel(q[be]), serviceImpact: { commercial: q[be].commercial ? q[be].commercial.description : "", industrial: q[be].industrial ? q[be].industrial.description : "", residential: q[be].residential ? q[be].residential.description : "" }, descriptions: { commercial: q[be].commercial ? q[be].commercial.specialNotes : "", industrial: q[be].industrial ? q[be].industrial.specialNotes : "", residential: q[be].residential ? q[be].residential.specialNotes : "" }, serviceImpacted: { commercial: q[be].commercial ? q[be].commercial.serviceImpacted : "", industrial: q[be].industrial ? q[be].industrial.serviceImpacted : "", residential: q[be].residential ? q[be].residential.serviceImpacted : "" } } } ), this.holidays } getHolidayInfo(B) { const V = {}; return B.forEach(q=>{ q.LOB && (V[q.LOB.toLowerCase()] = q) } ), V } getLobHolidays(B, V) { const q = B.filter(de=>de.LOB === V); if (0 === q.length) return []; const te = q[0].division , be = q.filter(de=>de.division === te && de.LOB === V); return this.getUniqueListBy(be, "date") } getUniqueListBy(B, V) { return [...new Map(B.map(q=>[q[V], q])).values()] } getHolidayLabel(B) { return B ? B.commercial ? B.commercial.name : B.residential ? B.residential.name : B.industrial ? B.industrial.name : void 0 : "" } createHolidays(B) { return (B ? Promise.resolve(B) : this.getSites().toPromise().then(q=>q[0])).then(q=>this.addressesResourceService.validateAddress({ ...q.siteAddress, mailability: !1 }).toPromise().then(te=>this.holidayScheduleService.getRecentHolidaySchedules(te.data[0].latitude, te.data[0].longitude).then(be=>be))).catch(()=>(this.holidays = [], this.holidays)) } getSites() { const {account: {accountId: B}} = this.mrUserService.getUser(); return this.mrSitesService.getSites({ accountId: B, pageSize: 1e3 }).pipe((0, D.K)(()=>[]), (0, O.U)(V=>V.filter(this.isOpen).map(q=>this.transformSite(q)))) } isOpen({siteStatus: B}) { return /open/i.test(B) } transformSite(B) { const {siteAddress: {addressLine1: V, city: q, state: te, postalCode: be}, siteName: de} = B; return { ...B, displayAddress: [this.utilityService.capitalizeFirstOfEach(V), this.utilityService.capitalizeFirstOfEach(q), (0, y.Z)(te), be].join(" "), siteName: this.utilityService.capitalizeFirstOfEach(de) } } getContainersV2(B) { const {account: {accountId: V}} = this.mrUserService.getUser() , {siteId: q} = B; return this.mrContainersService.getContainersV2({ accountId: V, includeDetails: !0, siteId: q }) } getLawsonDivisions(B) { const V = []; return typeof B > "u" || 0 === B.length || B.forEach(q=>{ typeof q.lawsonDivisionNumber < "u" && !V.includes(q.lawsonDivisionNumber) && V.push(q.lawsonDivisionNumber) } ), V } getContainers(B) { const {account: {accountId: V}} = this.mrUserService.getUser() , {siteId: q} = B; return this.mrContainersService.getContainers({ accountId: V, includeDetails: !0, siteId: q }).pipe((0, O.U)(te=>(this.profiles = te.map(be=>this.transformContainer(be)), this.profiles))) } getEvents(B) { return this.calcEventDates(this.profiles, B) } getContainersEvents(B) { const V = this.setTypes(B); return { events: this.calcEventDates(B), types: V } } transformContainer(B) { const {description: V} = B; return { ...B, description: this.utilityService.capitalizeFirstOfEach(V) } } setTypes(B) { const V = {}; return B?.forEach(q=>{ V[q.productDescription] = { label: q.productDescription, title: q.productDescription } } ), V } calcEventDates(B=[], V, q) { return [].concat(...B.filter(te=>!te.onCallInd).map(te=>{ const be = { ...te } , de = this.getDaysOfWeek(be); if (0 === de.length) return; be.daysOfTheWeek = de.map(Me=>(0, l.Z)((0, b.Z)(Me, "EEEE", new Date))); const ve = be.nextServiceDays.sort()[0]; be.startDateWeekOfYear = (0, a.Z)(new Date(ve)); const Se = this.dateUtilsService.getDaysOfMonth(V) , Oe = this.calcWeeksDisplayed(Se, be); return this.createDates(Oe, be, q) } )).filter(te=>te) } getDaysOfWeek(B) { const V = {}; return Object.entries(this.getDaysKeys(B)).forEach(([q,te])=>{ te > 0 && (V[q] = te) } ), Object.entries(V).map(([q])=>q) } getDaysKeys(B) { const {mondayPickups: V, tuesdayPickups: q, wednesdayPickups: te, thursdayPickups: be, fridayPickups: de, saturdayPickups: ve, sundayPickups: Se} = B , Me = {}; return Object.entries({ mondayPickups: V, tuesdayPickups: q, wednesdayPickups: te, thursdayPickups: be, fridayPickups: de, saturdayPickups: ve, sundayPickups: Se }).forEach(([Le,je])=>{ Me[Le.replace("Pickups", "")] = je } ), Me } calcWeeksDisplayed(B, V) { return B.filter(q=>{ if (V?.nextServiceDays?.length && !((0, P.Z)(q[V.daysOfTheWeek[0]]?.date) <= (0, P.Z)(new Date(V.serviceStartDate)) && (0, _.Z)(q[V.daysOfTheWeek[0]].date, new Date(V.serviceStartDate))) && (!V.serviceCloseDate || !(0, e.Z)(q[V.daysOfTheWeek[0]]?.date, new Date(V.serviceCloseDate))) && !(Math.abs((0, a.Z)(new Date(q[0].date)) - Number(V.startDateWeekOfYear)) % Number(V.numberOfPickupsPeriodLength))) return !0 } ).filter(q=>q) } createDates(B, V, q) { const te = [].concat(...B.map(be=>[].concat(...V.daysOfTheWeek.map(de=>{ const ve = be[de]?.date; return { category: q?.toLowerCase() || (V?.containerCategory ?? "").toLowerCase() || "residential", date: ve ? (0, m.Z)(ve, "yyyy-MM-dd") : null, type: V.productDescription } } )))); return this.featureFlags.isOn("event-calendar-refresh") ? this.adjustHolidayPickups(te) : this.extractHolidays(te) } makePdfContent(B) { if (0 === B.length) return []; const V = [] , q = []; for (let Oe = 0; Oe < B.length; Oe++) Oe % 2 == 0 ? V.push(B[Oe]) : q.push(B[Oe]); const te = Oe=>{ const Me = []; return Oe.forEach(Le=>{ const je = Le.description , Re = new Date(Le.date) , nt = Re.getUTCDate() , Ze = Re.getUTCMonth() , bt = Re.getUTCFullYear() , $e = (0, m.Z)(new Date(bt,Ze,nt), "PP"); Me.push({ columns: [{ fontSize: 10, color: "#00ADEF", bold: !0, text: Le.name.toUpperCase(), width: "auto" }, { fontSize: 10, color: "#00ADEF", text: ` - ${$e}`, width: "auto" }] }, { margin: [0, 10, 0, 15], text: je }, { margin: [0, 0, 0, 35], text: Le.specialNotes }) } ), Me } , be = { items: te(V) } , de = { items: te(q) }; return [{ columns: [{ stack: [...be.items], margin: [0, 0, 10, 0] }, { stack: [...de.items], margin: [10, 0, 0, 0] }] }, { margin: [0, 0, 0, 40], text: this.translateService.instant("HOLIDAY_PDF_FOOTER") + " " + B[0].phone }] } getFormattedDate(B) { const V = B.getUTCDate() , q = B.getUTCMonth() , te = B.getUTCFullYear(); return (0, m.Z)(new Date(te,q,V), "yyyy-MM-dd") } getFormattedLocalDate(B) { if ("string" == typeof B) return B; const V = new Date(B) , q = V.getDate() , te = V.getMonth() , be = V.getFullYear(); return (0, m.Z)(new Date(be,te,q), "yyyy-MM-dd") } getContainerType(B) { let V; return V = "string" == typeof B ? B : B.type, "holiday" === V ? void 0 : [{ label: "MR_PICKUP_CALENDAR.LEGEND.RECYCLING", name: "recycling", pattern: /recycl/i }, { label: "MR_PICKUP_CALENDAR.LEGEND.BULK", name: "bulk", pattern: /bulk/i }, { label: "MR_PICKUP_CALENDAR.LEGEND.YARD", name: "yard-waste", pattern: /yard/i }, { label: "MR_PICKUP_CALENDAR.LEGEND.ORGANIC", name: "organic", pattern: /organic/i }, { label: "MR_PICKUP_CALENDAR.LEGEND.WASTE", name: "waste", pattern: /.*/ }].find(te=>te.pattern.test(V)) } getContainerTypes(B) { return (0, E.Z)(B.map(this.getContainerType), "name").filter(V=>V) } getHolidaysAndUpdateHolidaysByDateObject(B, V) { const q = [...new Set(B.map(te=>te.date))]; return q.forEach(te=>{ const be = B.filter(Se=>Se.date === te) , de = [...new Set(be.map(Se=>Se.LOB))] , ve = []; de.forEach(Se=>{ const Oe = be.find(Me=>Me.LOB === Se); Oe && ve.push(Oe) } ), ve && (V[te] = this.getHolidayInfo(ve)) } ), q } adjustHolidayPickups(B) { return this.holidays?.forEach(V=>{ B?.forEach(q=>this.adjustHolidayPickup(q, V)) } ), B } adjustHolidayPickup(B, V) { const q = this.getFormattedLocalDate(V.date) , te = (0, d.Z)(B.date) , be = (0, d.Z)(q); if (!(0, x.Z)(be, te) || 0 === (0, l.Z)(be)) return; const de = Oe=>{ 6 === (0, l.Z)(te) && this.getEventCategory(B.category) === f.Cu.residential || (Oe.date = (0, m.Z)((0, T.Z)(te, { days: 1 }), "yyyy-MM-dd")) } , Se = { commercial: [{ compare: this.isSameOrAfterRsx, update: de }], industrial: [{ compare: this.isSameOrAfterRsx, update: de }], residential: [{ compare: this.isSameOrAfterRsx, update: de }] }[B.category].find(()=>V?.holidayImpact?.[B.category]); Se && Se.compare(te, be) && Se.update(B) } isSameOrAfterRsx(B, V) { return (0, I.Z)(B, V) || (0, e.Z)(B, V) } extractHolidays(B) { return B.filter(V=>!this.holidays.find(q=>{ const te = new Date(q.date); return q.date === V.date || (0, M.Z)(q.date) && this.getFormattedDate(te) === V.date } )) } getEventCategory(B) { switch (B.substring(0, 1).toUpperCase()) { case "I": return f.Cu.industrial; case "R": return f.Cu.residential; default: return f.Cu.commercial } } }