"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertDateToDisplayString = exports.checkIsInRange = exports.splitDateListByWeek = exports.getDateList = exports.getDateListByWeek = exports.NUMBER_OF_WEEK = exports.NUMBER_OF_WEEK_DAYS = exports.DAY_OF_WEEK_LIST = void 0;
const types_1 = require("../../../../types");
exports.DAY_OF_WEEK_LIST = ['일', '월', '화', '수', '목', '금', '토'];
exports.NUMBER_OF_WEEK_DAYS = exports.DAY_OF_WEEK_LIST.length; // 7
exports.NUMBER_OF_WEEK = 6;
const getDateListByWeek = ({ displayYear, displayMonth }) => {
    return (0, exports.splitDateListByWeek)((0, exports.getDateList)({ displayYear, displayMonth }));
};
exports.getDateListByWeek = getDateListByWeek;
/**
 *
 * @param displayYear 표시연도
 * @param displayMonth 표시달(1~12)
 * @returns ex. 2017-06에 필요한 일자들을 리스트로 반환합니다.
 */
const getDateList = ({ displayYear, displayMonth }) => {
    const result = [];
    const firstDate = new types_1.PurpleDate([displayYear, displayMonth, 1]);
    const firstDateDayOfWeekIndex = firstDate.indexOfDayOfWeek;
    const lastDate = new types_1.PurpleDate([displayYear, displayMonth + 1, 0]); // 직전달 마지막날을 의미함
    const lastDateOfMonth = lastDate.dateOfMonth;
    let cnt = 0;
    // 앞에 칸 채우기
    for (let i = 0; i < firstDateDayOfWeekIndex; i++) {
        result.push(types_1.EMPTY_DATE);
        cnt++;
    }
    // 실제 데이터 채우기
    for (let d = 1; d <= lastDateOfMonth; d++) {
        result.push(new types_1.PurpleDate([displayYear, displayMonth, d]));
        cnt++;
    }
    // 뒤에 칸 채우기
    while (cnt < exports.NUMBER_OF_WEEK_DAYS * exports.NUMBER_OF_WEEK) {
        result.push(types_1.EMPTY_DATE);
        cnt++;
    }
    return result;
};
exports.getDateList = getDateList;
const splitDateListByWeek = (dates) => {
    const result = [];
    let tempWeek = [];
    for (let i = 0; i < dates.length; i++) {
        if (tempWeek.length === exports.NUMBER_OF_WEEK_DAYS) {
            result.push(tempWeek.slice());
            tempWeek = [];
        }
        tempWeek.push(dates[i]);
    }
    result.push(tempWeek.slice());
    return result;
};
exports.splitDateListByWeek = splitDateListByWeek;
const checkIsInRange = ({ from, to, target, }) => {
    if (from === types_1.EMPTY_DATE || to === types_1.EMPTY_DATE) {
        return false;
    }
    else {
        const fDate = from.timestamp;
        const tDate = to.timestamp;
        const targetDate = target.timestamp;
        if (from === types_1.EMPTY_DATE || to === types_1.EMPTY_DATE) {
            return false;
        }
        else {
            if (targetDate <= tDate && targetDate >= fDate) {
                return true;
            }
            return false;
        }
    }
};
exports.checkIsInRange = checkIsInRange;
const convertDateToDisplayString = (val, defaultValue) => {
    if (!val) {
        return defaultValue;
    }
    else {
        return val.toDateString('YY.MM.DD', '.');
    }
};
exports.convertDateToDisplayString = convertDateToDisplayString;
