"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getQueryParamFromHash = exports.getLetterDaysOfWeek = void 0;
const dayjs_1 = __importDefault(require("dayjs"));
const WeekdayStartsOn_types_1 = require("../models/Client/Hotel/WeekdayStartsOn.types");
const getLetterDaysOfWeek = (startsWeekOnDay) => {
    if (startsWeekOnDay === WeekdayStartsOn_types_1.WeekdayStartsOn.Monday) {
        return ['M', 'T', 'W', 'T', 'F', 'S', 'S'];
    }
    else {
        return ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
    }
};
exports.getLetterDaysOfWeek = getLetterDaysOfWeek;
class CalendarHelper {
}
/**
 * Returns an array always divisible by 7,
 *
 * Essentially no matter what what month is given, this function will always return the same number of days;
 * with each MOD 7 index representing the correct date.
 */
CalendarHelper.getWeekPaddedMonthArrayForDate = (startWeekOnDay, date) => {
    const monthStart = date.startOf('month');
    const monthEnd = date.endOf('month');
    let startDayIndex = parseInt(monthStart.format('d'), 10);
    if (startWeekOnDay === 'monday') {
        if (startDayIndex !== 0) {
            startDayIndex--;
        }
        else {
            startDayIndex = 6;
        }
    }
    const endDateNumber = parseInt(monthEnd.format('D'), 10);
    const endDayIndex = parseInt(monthEnd.format('d'), 10);
    const paddingAtEnd = startWeekOnDay === 'monday' ? (7 - endDayIndex) % 7 : (7 - endDayIndex - 1) % 7;
    const dayArray = [];
    for (let i = 0; i < endDateNumber + startDayIndex; i++) {
        if (i >= startDayIndex) {
            dayArray.push(String(i + 1 - startDayIndex));
        }
        else {
            dayArray.push('');
        }
    }
    for (let i = 0; i < paddingAtEnd; i++) {
        dayArray.push('');
    }
    return dayArray;
};
CalendarHelper.getMonthArray = (date) => {
    const monthStart = date.startOf('month');
    const monthEnd = date.endOf('month');
    const diff = monthEnd.diff(monthStart, 'day');
    const days = [];
    for (let i = 0; i < diff; i++) {
        days.push((0, dayjs_1.default)(monthStart.add(i, 'day')));
    }
    return days;
};
CalendarHelper.getWeekFrom = (date) => {
    const days = [];
    for (let i = 1; i <= 7; i++) {
        days.push(date.add(i, 'day'));
    }
    return days;
};
CalendarHelper.getWeekTo = (date) => {
    const days = [];
    for (let i = 1; i <= 7; i++) {
        days.push(date.subtract(i, 'day'));
    }
    return days;
};
CalendarHelper.getDaysBetween = (startDate, endDate) => {
    const days = [];
    const diff = endDate.diff(startDate, 'day');
    for (let i = 0; i <= diff + 7; i++) {
        days.push(startDate.add(i, 'day'));
    }
    return days;
};
exports.default = CalendarHelper;
const getQueryParamFromHash = (param) => {
    const currentUrl = window.location.href;
    const hashIndex = currentUrl.indexOf('#');
    if (hashIndex !== -1) {
        const hashFragment = currentUrl.substring(hashIndex + 1); // Extract the part after '#'
        const simulatedUrl = new URL(`https://example.com/${hashFragment}`); // Add base URL for parsing
        if (simulatedUrl.searchParams.has(param)) {
            const value = simulatedUrl.searchParams.get(param); // Get the query parameter value
            return value === null ? undefined : value;
        }
        return undefined;
    }
    return undefined;
};
exports.getQueryParamFromHash = getQueryParamFromHash;
//# sourceMappingURL=CalendarHelper.js.map