export const formatDate = (date) => {
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    return `${day}-${month}-${year}`;
};
export function formatViewResult(startDate, endDate) {
    const today = new Date();
    const yesterday = new Date(today);
    yesterday.setDate(yesterday.getDate() - 1);
    const sevenDaysAgo = new Date(today);
    sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
    const thirtyDaysAgo = new Date(today);
    thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
    const startDateResult = formatDate2(startDate);
    const endDateResult = formatDate2(endDate);
    if (isEqualDates(today, startDate) && isEqualDates(today, endDate)) {
        return 'Ngày hôm nay';
    }
    else if (isEqualDates(yesterday, startDate) && isEqualDates(yesterday, endDate)) {
        return 'Ngày hôm qua';
    }
    else if (isNDaysAgo(startDate, endDate, 7)) {
        return '7 ngày qua';
    }
    else if (isNDaysAgo(startDate, endDate, 30)) {
        return '30 ngày qua';
    }
    else if (isNDaysAgo(startDate, endDate, 90)) {
        return '90 ngày qua';
    }
    else if (isNDaysAgo(startDate, endDate, 365)) {
        return '365 ngày qua';
    }
    else {
        const startYear = startDate.getFullYear();
        const endYear = endDate.getFullYear();
        let viewResult;
        if (startYear === endYear) {
            viewResult = startDateResult.substring(0, 5) + ' - ' + endDateResult;
        }
        else {
            viewResult = startDateResult + ' - ' + endDateResult;
        }
        return viewResult;
    }
}
function isEqualDates(date1, date2) {
    return date1.toDateString() === date2.toDateString();
}
function formatDate2(date) {
    const day = ('0' + date.getDate()).slice(-2);
    const month = ('0' + (date.getMonth() + 1)).slice(-2);
    const year = date.getFullYear();
    return day + '/' + month + '/' + year;
}
function isNDaysAgo(startDate, endDate, daysAgo) {
    const today = new Date();
    const nDaysAgo = new Date(today);
    nDaysAgo.setDate(nDaysAgo.getDate() - (daysAgo - 1));
    return startDate.toDateString() === nDaysAgo.toDateString() && endDate.toDateString() === today.toDateString();
}
export const createMonthCalendarWithAdjacentMonths = (year, month) => {
    const getFirstDayOfMonth = (years, months) => {
        const firstDay = new Date(years, months, 1);
        const dayOfWeek = firstDay.getDay();
        return { date: firstDay, dayOfWeek };
    };
    const getDaysInMonth = (years, months) => new Date(years, months + 1, 0).getDate();
    const firstDayInfo = getFirstDayOfMonth(year, month);
    const daysInMonth = getDaysInMonth(year, month);
    const calendar = [];
    for (let day = 1; day <= daysInMonth; day++) {
        calendar.push({
            date: formatDate(new Date(year, month, day)),
            dayOfWeek: (firstDayInfo.dayOfWeek + day - 1) % 7,
            isCurrentMonth: true,
            isToday: formatDate(new Date(year, month, day)) === formatDate(new Date()),
        });
    }
    return calendar;
};
export const getMonthName = (month) => {
    let currentMonth;
    switch (month) {
        case 0:
            currentMonth = 'Tháng 1';
            break;
        case 1:
            currentMonth = 'Tháng 2';
            break;
        case 2:
            currentMonth = 'Tháng 3';
            break;
        case 3:
            currentMonth = 'Tháng 4';
            break;
        case 4:
            currentMonth = 'Tháng 5';
            break;
        case 5:
            currentMonth = 'Tháng 6';
            break;
        case 6:
            currentMonth = 'Tháng 7';
            break;
        case 7:
            currentMonth = 'Tháng 8';
            break;
        case 8:
            currentMonth = 'Tháng 9';
            break;
        case 9:
            currentMonth = 'Tháng 10';
            break;
        case 10:
            currentMonth = 'Tháng 11';
            break;
        case 11:
            currentMonth = 'Tháng 12';
            break;
        default:
            break;
    }
    return currentMonth;
};
export const dateStrToDate = (date) => {
    const fullDate = date === null || date === void 0 ? void 0 : date.split('-');
    return new Date(parseInt(fullDate[2]), parseInt(fullDate[1]) - 1, parseInt(fullDate[0]));
};
export const getHour = () => {
    const currentHour = new Date().getHours();
    const hourInDay = [];
    for (let i = 0; i < 24; i++) {
        // eslint-disable-next-line no-unused-expressions
        i < 10 ? hourInDay.push(`0${i}`) : hourInDay.push(`${i}`);
    }
    const arrayHour = hourInDay.map((item) => ({
        name: item,
        current: parseInt(item) === currentHour,
    }));
    return arrayHour;
};
export const getMinutes = () => {
    const currentMinute = new Date().getMinutes();
    const minutes = [];
    for (let i = 0; i < 60; i++) {
        // eslint-disable-next-line no-unused-expressions
        i < 10 ? minutes.push(`0${i}`) : minutes.push(`${i}`);
    }
    const arrayMinutes = minutes.map((item) => ({
        name: item,
        current: parseInt(item) === currentMinute,
    }));
    return arrayMinutes;
};
export const checkActive = (select, date) => {
    const dateArr = date.split('-');
    const selectArr = select.split('-');
    return (parseInt(dateArr[0]) === parseInt(selectArr[0]) &&
        parseInt(dateArr[1]) === parseInt(selectArr[1]) &&
        parseInt(dateArr[2]) === parseInt(selectArr[2]));
};
export const checkDisabled = (allDate) => {
    if ((allDate === null || allDate === void 0 ? void 0 : allDate.startDisabled) && (allDate === null || allDate === void 0 ? void 0 : allDate.endDisabled)) {
        return (dateStrToDate(allDate.date) >= dateStrToDate(allDate.startDisabled) &&
            dateStrToDate(allDate.date) <= dateStrToDate(allDate.endDisabled));
    }
    if (allDate === null || allDate === void 0 ? void 0 : allDate.disabledDate) {
        return allDate.disabledDate.includes(allDate.date);
    }
    if (allDate === null || allDate === void 0 ? void 0 : allDate.max) {
        return dateStrToDate(allDate.date) > dateStrToDate(allDate.max);
    }
    if (allDate === null || allDate === void 0 ? void 0 : allDate.min) {
        return dateStrToDate(allDate.date) < dateStrToDate(allDate.min);
    }
};
export function isValidDateFormat(dateString) {
    const regex = /^\d{2}-\d{2}-\d{4}$/;
    if (!regex.test(dateString)) {
        return false;
    }
    const parts = dateString.split('-');
    const day = parseInt(parts[0], 10);
    const month = parseInt(parts[1], 10) - 1;
    const year = parseInt(parts[2], 10);
    const date = new Date(year, month, day);
    return date.getDate() === day && date.getMonth() === month && date.getFullYear() === year;
}
export function classNames(...classes) {
    return classes.filter(Boolean).join(' ');
}
export function caculateTotalDay(startDate, endDate) {
    const start = new Date(startDate);
    const end = new Date(endDate);
    const ONE_DAY = 24 * 60 * 60 * 1000;
    return Math.round((end.getTime() - start.getTime()) / ONE_DAY);
}
//# sourceMappingURL=utils.js.map