// Metro module 8210 (f8211). import UserStore from "../../../stores/UserStore"; import { RecurrenceOptions } from "../CreateGuildScheduledEventConstants"; import { GuildScheduledEventEntityTypes, GuildScheduledEventStatus } from "../GuildScheduledEventsConstants"; import { Weekday, RRule } from "../../../_bundle/Module8212"; import { intl, t } from "../../../intl/index.native"; import Module3771 from "../../../_bundle/Module3771"; import { differenceInCalendarDays, dateFormat } from "../../../utils/DateUtils"; import SnowflakeUtils from "../../../utils/SnowflakeUtils"; import Durations from "../../../utils/Durations"; import { isEqual } from "../../../_bundle/Module12"; let c5218_7, c5218_8, c5218_9, c5218_10, c5218_11, c5218_12, c5218_13, c5218_14, getValidWeekdays, getValidWeekends; const getRRule = function getRRule(a0) { let byweekday = a0.byWeekday != null ? [...a0.byWeekday] : null; const byNWeekday = a0.byNWeekday; const r9 = byNWeekday == null ? void 0 : byNWeekday.map((item) => new Weekday(item.day, item.n)); const date = new Date(a0.start); date.setMilliseconds(0); const until = a0.end != null ? new Date(a0.end) : null; if (byweekday == null) { byweekday = r9; } return new RRule({ dtstart: date, until, freq: a0.frequency, interval: a0.interval, byweekday, bymonth: a0.byMonth != null ? [...a0.byMonth] : null, bymonthday: a0.byMonthDay != null ? [...a0.byMonthDay] : null, byyearday: a0.byYearDay != null ? [...a0.byYearDay] : null, count: a0.count }); }; getValidWeekdays = function getValidWeekdays(a0) { const weekday = new Weekday(c5218_13[a0.toDate().getDay()]); const weekday2 = new Weekday(c5218_13[a0.toDate().getUTCDay()]); return weekday2.weekday - weekday.weekday > 0 ? c5218_9 : weekday2.weekday - weekday.weekday < 0 ? c5218_8 : c5218_7; }; getValidWeekends = function getValidWeekends(a0) { const weekday = new Weekday(c5218_13[a0.toDate().getDay()]); const weekday2 = new Weekday(c5218_13[a0.toDate().getUTCDay()]); return weekday2.weekday - weekday.weekday > 0 ? c5218_12 : weekday2.weekday - weekday.weekday < 0 ? c5218_11 : c5218_10; }; c5218_7 = [RRule.MO.weekday, RRule.TU.weekday, RRule.WE.weekday, RRule.TH.weekday, RRule.FR.weekday]; c5218_8 = [RRule.SU.weekday, RRule.MO.weekday, RRule.TU.weekday, RRule.WE.weekday, RRule.TH.weekday]; c5218_9 = [RRule.TU.weekday, RRule.WE.weekday, RRule.TH.weekday, RRule.FR.weekday, RRule.SA.weekday]; c5218_10 = [RRule.SA.weekday, RRule.SU.weekday]; c5218_11 = [RRule.FR.weekday, RRule.SA.weekday]; c5218_12 = [RRule.SU.weekday, RRule.MO.weekday]; c5218_13 = [RRule.SU.weekday, RRule.MO.weekday, RRule.TU.weekday, RRule.WE.weekday, RRule.TH.weekday, RRule.FR.weekday, RRule.SA.weekday]; c5218_14 = new Set([0, 6]); export const MAX_DAYS_AHEAD_AN_EVENT_CAN_START = 365; export const MAX_DAYS_AHEAD_AN_EVENT_CAN_END = 366; export const MAX_YEARS_AHEAD_RECURRING_EVENT = 4; export function getRecurrenceOptions(a0) { const r11 = a0.toDate(); const nth = Math.ceil(r11.getDate() / 7); const weekday = a0.format("dddd"); const r34 = [{ id: "none", value: RecurrenceOptions.NONE, label: intl.string(t["0bK0B1"]) }, { id: "weekly", value: RecurrenceOptions.WEEKLY, label: intl.formatToPlainString(t["B8/yfp"], { weekday }) }, { id: "biweekly", value: RecurrenceOptions.BIWEEKLY, label: intl.formatToPlainString(t["z+aIuX"], { weekday }) }, { id: "monthly", value: RecurrenceOptions.MONTHLY, label: intl.formatToPlainString(t.mjOEBk, { nth, weekday }) }, { id: "yearly", value: RecurrenceOptions.YEARLY, label: intl.formatToPlainString(t["5DFcVl"], { date: r11.toLocaleString(intl.currentLocale, { month: "short", day: "2-digit" }) }) }, { id: "daily", value: RecurrenceOptions.DAILY, label: intl.string(t.JX8E1E) }]; if (c5218_14.has(r11.getDay())) { const currentUser = UserStore.getCurrentUser(); if (currentUser == null ? void 0 : currentUser.isStaff()) { r34.push({ id: "weekendOnly", value: RecurrenceOptions.WEEKEND_ONLY, label: intl.string(t.hRpynV) }); } } else { r34.push({ id: "weekdayOnly", value: RecurrenceOptions.WEEKDAY_ONLY, label: intl.string(t["jYR/MY"]) }); } return r34; } export function getInitialEventStartDate() { const r12 = Module3771().add(1, "hour"); const r14 = r12.hour(); return r12.hour(r12.minutes() >= 30 ? r14 + 1 : r14).minutes(0).seconds(0); } export function getInitialEventEndDate(a0) { const r20 = (a0 != null ? Module3771(a0) : Module3771()).add(1, "hour"); const r23 = r20.minutes() % 60; return Module3771(r20).add(60 - r23, "minutes").seconds(0); } export function getNextBucketedTime(a0, a1) { const r8 = a1 - a0.minutes() % a1; return Module3771(a0).add(r8, "minutes").seconds(0); } export function getEventTimeData(a0, a1, a2) { const r9 = a2 == null ? Module3771() : a2; const r24 = Module3771(a0); const r14 = a1 != null ? a1 !== "" ? Module3771(a1) : void 0 : void 0; const r28 = a1 != null && r24.isSame(r14, "day"); const r36 = differenceInCalendarDays(r24.toDate(), r9.toDate()); return { startDateTimeString: !(r36 > 1) && !(r36 < 0) ? dateFormat(r24, r24.localeData().calendar(r36 < 1 ? "sameDay" : "nextDay", r24, r9)) : dateFormat(r24, r24.get("years") === r9.get("years") ? "ddd MMM Do · LT" : "ddd MMM Do, YYYY · LT"), endDateTimeString: r14 != null ? r28 ? r14.format("LT") : dateFormat(r14, r14.get("years") === r9.get("years") ? "ddd MMM Do · LT" : "ddd MMM Do, YYYY · LT") : void 0, currentOrPastEvent: r24 <= r9, upcomingEvent: r24 <= Module3771().add(1, "hour"), withinStartWindow: r24 <= Module3771().add(15, "minute"), diffMinutes: r24.diff(r9, "minutes") }; } export function convertJSDayToRRuleDay(a0) { return new Weekday(c5218_13[a0]); } export function getBaseScheduleForRecurrence(a0, { scheduled_start_time, scheduled_end_time }) { const r2 = scheduled_start_time != null; let r11 = void 0; if (r2) { const r5 = { startDate: Module3771(scheduled_start_time), endDate: void 0 }; r11 = r5; if (scheduled_end_time != null) { r5.endDate = Module3771(scheduled_end_time); r11 = r5; } } const startDate = Module3771(SnowflakeUtils.extractTimestamp(a0)); return { startDate, endDate: r11?.endDate != null ? startDate.clone().add(r11.endDate.diff(r11.startDate)) : void 0 }; } export function getScheduleForRecurrenceWithException(a0, a1) { if (a1 == null) { return a0; } let scheduled_end_time = a1.scheduled_end_time; if (scheduled_end_time == null) { scheduled_end_time = a0.endDate; } return { startDate: a1.scheduled_start_time != null ? Module3771(a1.scheduled_start_time) : a0.startDate, endDate: scheduled_end_time != null ? Module3771(scheduled_end_time) : void 0 }; } export function getScheduleFromEventData({ scheduledStartTime, scheduledEndTime }) { const r2 = scheduledStartTime != null; let r10 = void 0; if (r2) { const r4 = { startDate: Module3771(scheduledStartTime), endDate: void 0 }; r10 = r4; if (scheduledEndTime != null) { r4.endDate = Module3771(scheduledEndTime); r10 = r4; } } return r10; } export function getScheduleFromEvent({ scheduled_start_time, scheduled_end_time }) { const r2 = scheduled_start_time != null; let r10 = void 0; if (r2) { const r4 = { startDate: Module3771(scheduled_start_time), endDate: void 0 }; r10 = r4; if (scheduled_end_time != null) { r4.endDate = Module3771(scheduled_end_time); r10 = r4; } } return r10; } export function hasValidSchedule({ startDate, endDate }, a1) { let r2 = startDate != null; if (r2) { let r15 = !(startDate < Module3771()); if (r15) { const r0 = endDate != null && endDate < startDate; r15 = r0 ? !r0 : a1 !== GuildScheduledEventEntityTypes.EXTERNAL || endDate != null; } r2 = r15; } return r2; } export function areDatesIdentical(a0, a1) { return a0 != null && a1 != null ? a0.isSame(a1) : a0 == null && a1 == null; } export function areSchedulesIdentical(a0, a1) { let r9; L20: { if (a0 != null && a1 != null) { const startDate2 = a0.startDate; const startDate = a1.startDate; r9 = startDate2 != null && startDate != null ? startDate2.isSame(startDate) : startDate2 == null && startDate == null; if (!r9) { break L20; } const endDate = a0.endDate; const endDate2 = a1.endDate; r9 = endDate != null && endDate2 != null ? endDate.isSame(endDate2) : endDate == null && endDate2 == null; } else { r9 = a0 == null && a1 == null; } } return r9; } export { getRRule }; export function generateNextRecurrences(a0, a1, a2) { let c16357_0 = a0; let r2 = arguments[3]; if (r2 === void 0) { r2 = false; } const r9 = a2 > new Date() ? a2 : new Date(); const date = new Date(); date.setFullYear(date.getFullYear() + 4); const r34 = a1.between(r9, date, true, (a0, a1) => a1 < c16357_0 + 1); return r2 && (r34.length > 0 && a2.getTime() === r34[0].getTime()) ? r34.slice(1) : r34.slice(0, a0); } export function getNextRecurrenceInEvent(a0) { return a0.recurrence_rule != null ? new Date(a0.scheduled_start_time) : null; } export function getNextRecurrenceIdInEvent(a0) { if (a0 == null) { return null; } const r10 = a0.recurrence_rule == null ? null : new Date(a0.scheduled_start_time); return r10 != null ? SnowflakeUtils.fromTimestamp(Math.floor(r10.getTime() / Durations.Millis.SECOND) * Durations.Millis.SECOND) : null; } export function isValidRecurrence(a0, a1) { if (a1 != null && a0 != null) { const date = new Date(a0.start); const date2 = new Date(SnowflakeUtils.extractTimestamp(a1)); if (date.getUTCHours() === date2.getUTCHours() && date.getUTCMinutes() === date2.getUTCMinutes() && date.getUTCSeconds() === date2.getUTCSeconds()) { const frequency = a0.frequency; if (RRule.WEEKLY === frequency) { return date.getUTCDay() === date2.getUTCDay(); } if (RRule.YEARLY === frequency) { return date.getUTCDate() === date2.getUTCDate(); } return true; } return false; } return false; } export { getValidWeekdays }; export { getValidWeekends }; export function recurrenceOptionToRecurrenceRule(a0, a1) { const validWeekdays = getValidWeekdays(a1); const validWeekends = getValidWeekends(a1); const weekday = new Weekday(c5218_13[a1.toDate().getUTCDay()]); const r33 = Math.ceil(a1.toDate().getUTCDate() / 7); const dtstart2 = a1.toDate(); dtstart2.setMilliseconds(0); const r41 = RecurrenceOptions.NONE !== a0 ? RecurrenceOptions.WEEKLY === a0 ? new RRule({ dtstart: dtstart2, freq: RRule.WEEKLY }) : RecurrenceOptions.BIWEEKLY === a0 ? new RRule({ dtstart: dtstart2, freq: RRule.WEEKLY, interval: 2 }) : RecurrenceOptions.MONTHLY === a0 ? new RRule({ dtstart: dtstart2, freq: RRule.MONTHLY, byweekday: [weekday.nth(r33)] }) : RecurrenceOptions.YEARLY === a0 ? new RRule({ dtstart: dtstart2, freq: RRule.YEARLY }) : RecurrenceOptions.DAILY === a0 ? new RRule({ dtstart: dtstart2, freq: RRule.DAILY }) : RecurrenceOptions.WEEKDAY_ONLY === a0 ? new RRule({ dtstart: dtstart2, freq: RRule.DAILY, byweekday: validWeekdays }) : RecurrenceOptions.WEEKEND_ONLY === a0 ? new RRule({ dtstart: dtstart2, freq: RRule.DAILY, byweekday: validWeekends }) : void 0 : null; if (r41 == null) { return null; } const options = r41.options; const { dtstart, until, freq, interval, byweekday, bynweekday, bymonth, bymonthday, byyearday, count } = options; const byNWeekday = bynweekday == null ? void 0 : bynweekday.map((item) => ({ n: item[1], day: item[0] })); return { start: dtstart.toISOString(), end: until == null ? void 0 : until.toISOString(), frequency: freq, interval, byWeekday: byweekday, byNWeekday, byMonth: bymonth, byMonthDay: bymonthday, byYearDay: byyearday, count }; } export function recurrenceRuleToOption(a0, a1) { let WEEKDAY_ONLY, WEEKLY; if (a1 == null) { return RecurrenceOptions.NONE; } const rRule = getRRule(a1); const freq = rRule.options.freq; if (RRule.WEEKLY === freq) { L26: { if (!(rRule.options.interval < 1) && !(rRule.options.interval > 2)) { if (rRule.options.interval === 1) { WEEKLY = RecurrenceOptions.WEEKLY; break L26; } WEEKLY = RecurrenceOptions.BIWEEKLY; } else { WEEKLY = RecurrenceOptions.NONE; } } return WEEKLY; } if (RRule.YEARLY === freq) { return RecurrenceOptions.YEARLY; } if (RRule.MONTHLY === freq) { return RecurrenceOptions.MONTHLY; } if (RRule.DAILY === freq) { L16: { if (rRule.options.byweekday != null && rRule.options.byweekday.length !== 0) { if (isEqual(rRule.options.byweekday, getValidWeekdays(a0))) { WEEKDAY_ONLY = RecurrenceOptions.WEEKDAY_ONLY; break L16; } if (isEqual(rRule.options.byweekday, getValidWeekends(a0))) { WEEKDAY_ONLY = RecurrenceOptions.WEEKEND_ONLY; break L16; } WEEKDAY_ONLY = RecurrenceOptions.NONE; } else { WEEKDAY_ONLY = RecurrenceOptions.DAILY; } } return WEEKDAY_ONLY; } return RecurrenceOptions.NONE; } export function hasScheduleChanges(a0, a1) { return a0?.scheduled_start_time !== a1.scheduledStartTime || a0.scheduled_end_time !== a1.scheduledEndTime || !isEqual(a0.recurrence_rule, a1.recurrenceRule); } export function getRecurrenceStatus(a0, a1, a2) { return a0?.is_canceled ? GuildScheduledEventStatus.CANCELED : a1 < a2 ? GuildScheduledEventStatus.COMPLETED : a0 != null ? GuildScheduledEventStatus.SCHEDULED : null; }