/**
 * 日历和日期工具函数
 * 从 DatePicker / DateTimePicker / DatePickerPane 中提取的共享逻辑
 */
/** 判断两个日期是否为同一天 */
function isSameDay(date1, date2) {
    return (date1.getFullYear() === date2.getFullYear() &&
        date1.getMonth() === date2.getMonth() &&
        date1.getDate() === date2.getDate());
}
/** 生成 42 天（6 周）的日历网格数据 */
function getCalendarDays(viewDate, selectedDate, today = new Date()) {
    const days = [];
    const year = viewDate.getFullYear();
    const month = viewDate.getMonth();
    const firstDay = new Date(year, month, 1);
    const lastDay = new Date(year, month + 1, 0);
    const firstDayWeek = firstDay.getDay();
    const daysInMonth = lastDay.getDate();
    // 上月填充
    const prevMonth = new Date(year, month - 1, 0);
    for (let i = firstDayWeek - 1; i >= 0; i--) {
        const date = new Date(year, month - 1, prevMonth.getDate() - i);
        days.push({
            date,
            isCurrentMonth: false,
            isToday: isSameDay(date, today),
            isSelected: !!selectedDate && isSameDay(date, selectedDate),
        });
    }
    // 当月日期
    for (let i = 1; i <= daysInMonth; i++) {
        const date = new Date(year, month, i);
        days.push({
            date,
            isCurrentMonth: true,
            isToday: isSameDay(date, today),
            isSelected: !!selectedDate && isSameDay(date, selectedDate),
        });
    }
    // 下月填充（补齐 42 天）
    const remainingDays = 42 - days.length;
    for (let i = 1; i <= remainingDays; i++) {
        const date = new Date(year, month + 1, i);
        days.push({
            date,
            isCurrentMonth: false,
            isToday: isSameDay(date, today),
            isSelected: !!selectedDate && isSameDay(date, selectedDate),
        });
    }
    return days;
}
/**
 * 格式化日期为指定格式字符串
 * 支持：YYYY, MM, DD, HH, mm, ss
 */
function formatDate(date, format) {
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    const seconds = String(date.getSeconds()).padStart(2, '0');
    return format
        .replace('YYYY', String(year))
        .replace('MM', month)
        .replace('DD', day)
        .replace('HH', hours)
        .replace('mm', minutes)
        .replace('ss', seconds);
}
/** 安全解析日期值 */
function parseDate(value) {
    if (!value)
        return undefined;
    const date = value instanceof Date ? value : new Date(value);
    if (isNaN(date.getTime()))
        return undefined;
    return date;
}
/** 月份偏移，返回新日期对象（不可变） */
function addMonths(date, delta) {
    const result = new Date(date);
    result.setMonth(result.getMonth() + delta);
    return result;
}
/** 年份偏移，返回新日期对象（不可变） */
function addYears(date, delta) {
    const result = new Date(date);
    result.setFullYear(result.getFullYear() + delta);
    return result;
}
function getCalendarYears(viewDate, selectedDate, startYearBase) {
    const year = viewDate.getFullYear();
    const rangeStart = startYearBase ?? year - (year % 12);
    const years = [];
    for (let i = 0; i < 12; i++) {
        const y = rangeStart + i;
        years.push({
            year: y,
            isCurrentYearRange: y === year,
            isSelected: !!selectedDate && selectedDate.getFullYear() === y,
        });
    }
    return years;
}
/** 获取 years 视图标题所显示的年份档区间起点 */
function getYearRangeStart(viewDate) {
    const year = viewDate.getFullYear();
    return year - (year % 12);
}
/** 中文月份名称 */
const MONTH_NAMES = [
    '一月', '二月', '三月', '四月', '五月', '六月',
    '七月', '八月', '九月', '十月', '十一月', '十二月',
];
/** 中文星期名称 */
const WEEK_DAY_NAMES = ['日', '一', '二', '三', '四', '五', '六'];

export { MONTH_NAMES as M, WEEK_DAY_NAMES as W, addMonths as a, addYears as b, getYearRangeStart as c, getCalendarYears as d, formatDate as f, getCalendarDays as g, isSameDay as i, parseDate as p };

//# sourceMappingURL=p-cf94cbf6.js.map