"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get Utils () {
        return Utils;
    },
    get getCurrMonthData () {
        return getCurrMonthData;
    },
    get getDaysStatus () {
        return getDaysStatus;
    },
    get getPreMonthDates () {
        return getPreMonthDates;
    }
});
var _to_consumable_array = require("@swc/helpers/_/_to_consumable_array");
var Utils = {
    /**
   * 是否为闫年
   * @return {Boolse} true|false
   */ isLeapYear: function isLeapYear(y) {
        return y % 4 === 0 && y % 100 !== 0 || y % 400 === 0;
    },
    /**
   * 返回星期数
   * @return {String}
   */ getWhatDay: function getWhatDay(year, month, day) {
        var date = new Date("".concat(year, "/").concat(month, "/").concat(day));
        var index = date.getDay();
        var dayNames = [
            '星期日',
            '星期一',
            '星期二',
            '星期三',
            '星期四',
            '星期五',
            '星期六'
        ];
        return dayNames[index];
    },
    /**
   * 返回上一个月在当前面板中的天数
   * @return {Number}
   */ getMonthPreDay: function getMonthPreDay(year, month) {
        var date = new Date("".concat(year, "/").concat(month, "/01"));
        var day = date.getDay();
        if (day === 0) {
            day = 7;
        }
        return day;
    },
    /**
   * 返回月份天数
   * @return {Number}
   */ getMonthDays: function getMonthDays(year, month) {
        if (/^0/.test(month)) {
            month = month.split('')[1];
        }
        return [
            0,
            31,
            this.isLeapYear(Number(year)) ? 29 : 28,
            31,
            30,
            31,
            30,
            31,
            31,
            30,
            31,
            30,
            31
        ][month];
    },
    /**
   * 补齐数字位数
   * @return {string}
   */ getNumTwoBit: function getNumTwoBit(n) {
        n = Number(n);
        return (n > 9 ? '' : '0') + n;
    },
    /**
   * 日期对象转成字符串
   * @return {string}
   */ date2Str: function date2Str(date, split) {
        split = split || '-';
        var y = date.getFullYear();
        var m = this.getNumTwoBit(date.getMonth() + 1);
        var d = this.getNumTwoBit(date.getDate());
        return [
            y,
            m,
            d
        ].join(split);
    },
    /**
   * 返回日期格式字符串
   * @param {Number} 0返回今天的日期、1返回明天的日期，2返回后天得日期，依次类推
   * @return {string} '2014-12-31'
   */ getDay: function getDay(i) {
        i = i || 0;
        var date = new Date();
        var diff = i * (1000 * 60 * 60 * 24);
        date = new Date(date.getTime() + diff);
        return this.date2Str(date);
    },
    /**
   * 时间比较
   * @return {Boolean}
   */ compareDate: function compareDate(date1, date2) {
        var startTime = new Date(date1.replace('-', '/').replace('-', '/'));
        var endTime = new Date(date2.replace('-', '/').replace('-', '/'));
        if (startTime >= endTime) {
            return false;
        }
        return true;
    },
    /**
   * 时间是否相等
   * @return {Boolean}
   */ isEqual: function isEqual(date1, date2) {
        var startTime = new Date((date1 || '').replace(/-/g, '/')).getTime();
        var endTime = new Date(date2.replace(/-/g, '/')).getTime();
        if (startTime === endTime) {
            return true;
        }
        return false;
    },
    getMonthWeek: function getMonthWeek(year, month, date) {
        var firstDayOfWeek = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
        var dateNow = new Date(Number(year), parseInt(month) - 1, Number(date));
        var w = dateNow.getDay() // 星期数
        ;
        var d = dateNow.getDate();
        var remainder = 6 - w;
        if (firstDayOfWeek !== 0) {
            w = w === 0 ? 7 : w;
            remainder = 7 - w;
        }
        return Math.ceil((d + remainder) / 7);
    },
    getYearWeek: function getYearWeek(year, month, date) {
        var firstDayOfWeek = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
        var dateNow = new Date(Number(year), parseInt(month) - 1, Number(date));
        var dateFirst = new Date(Number(year), 0, 1);
        var dataNumber = Math.round((dateNow.valueOf() - dateFirst.valueOf()) / 86400000);
        return Math.ceil((dataNumber + (dateFirst.getDay() + 1 - 1)) / 7);
    },
    getWeekDate: function getWeekDate(year, month, date) {
        var firstDayOfWeek = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
        var dateNow = new Date(Number(year), parseInt(month) - 1, Number(date));
        var nowTime = dateNow.getTime();
        var day = dateNow.getDay();
        if (firstDayOfWeek === 0) {
            var oneDayTime = 24 * 60 * 60 * 1000;
            // 显示周日
            var SundayTime = nowTime - day * oneDayTime // 本周的周日
            ;
            // 显示周六
            var SaturdayTime = nowTime + (6 - day) * oneDayTime // 本周的周六
            ;
            var sunday = this.date2Str(new Date(SundayTime));
            var saturday = this.date2Str(new Date(SaturdayTime));
            return [
                sunday,
                saturday
            ];
        }
        day = day === 0 ? 7 : day;
        var oneDayTime1 = 24 * 60 * 60 * 1000;
        // 显示周一
        var MondayTime = nowTime - (day - 1) * oneDayTime1 // 本周的周一
        ;
        // 显示周日
        var SundayTime1 = nowTime + (7 - day) * oneDayTime1 // 本周的周日
        ;
        var monday = this.date2Str(new Date(MondayTime));
        var sunday1 = this.date2Str(new Date(SundayTime1));
        return [
            monday,
            sunday1
        ];
    },
    formatResultDate: function formatResultDate(date) {
        var days = (0, _to_consumable_array._)(date.split('-'));
        days[2] = Utils.getNumTwoBit(Number(days[2]));
        days[3] = "".concat(days[0], "-").concat(days[1], "-").concat(days[2]);
        days[4] = Utils.getWhatDay(+days[0], +days[1], +days[2]);
        return days;
    }
};
var getCurrMonthData = function getCurrMonthData(type, year, month) {
    switch(type){
        case 'prev':
            month === 1 && (year -= 1);
            month = month === 1 ? 12 : --month;
            break;
        case 'next':
            month === 12 && (year += 1);
            month = month === 12 ? 1 : ++month;
            break;
        default:
            break;
    }
    return [
        year,
        Utils.getNumTwoBit(month),
        Utils.getMonthDays(String(year), String(month))
    ];
};
var getDaysStatus = function getDaysStatus(type, year, month) {
    var days = Utils.getMonthDays("".concat(year), "".concat(month));
    // 修复：当某个月的1号是周日时，月份下方会空出来一行
    if (type === 'prev' && days >= 7) {
        days -= 7;
    }
    return Array.from(Array(days), function(v, k) {
        return {
            day: k + 1,
            type: type,
            year: year,
            month: month
        };
    });
};
var getPreMonthDates = function getPreMonthDates(type, year, month, firstDayOfWeek) {
    var preMonth = +month - 1;
    var preYear = year;
    if (preMonth <= 0) {
        preMonth = 12;
        preYear += 1;
    }
    var days = Utils.getMonthPreDay(+year, +month);
    days -= firstDayOfWeek;
    // 修复：当某个月的1号是周日时，月份下方会空出来一行
    if (type === 'prev' && days >= 7) {
        days -= 7;
    }
    var preDates = Utils.getMonthDays("".concat(preYear), "".concat(preMonth));
    var months = Array.from(Array(preDates), function(v, k) {
        return {
            day: k + 1,
            type: type,
            year: preYear,
            month: preMonth
        };
    });
    return months.slice(preDates - days);
};
