"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getHeavenlyStemAndEarthlyBranchBySolarDate = exports.getHeavenlyStemAndEarthlyBranchByLunarDate = void 0;
var convertor_1 = require("./convertor");
var lunar_typescript_1 = require("lunar-typescript");
/**
 * 通过农历获取生辰干支
 *
 * @param dateStr 农历日期 YYYY-MM-DD
 * @param timeIndex 时辰索引【0～12】
 * @param isLeap 是否为闰月
 * @returns HeavenlyStemAndEarthlyBranchResult
 */
var getHeavenlyStemAndEarthlyBranchByLunarDate = function (dateStr, timeIndex, isLeap, options) {
    if (options === void 0) { options = { year: "normal" }; }
    var solarDate = (0, convertor_1.lunar2solar)(dateStr, isLeap);
    return (0, exports.getHeavenlyStemAndEarthlyBranchBySolarDate)(solarDate.toString(), timeIndex, options);
};
exports.getHeavenlyStemAndEarthlyBranchByLunarDate = getHeavenlyStemAndEarthlyBranchByLunarDate;
/**
 * 将阳历转化为干支纪年
 *
 * @param dateStr 公历日期 YYYY-MM-DD
 * @param timeIndex 时辰索引【0～12】
 * @returns HeavenlyStemAndEarthlyBranchResult
 */
var getHeavenlyStemAndEarthlyBranchBySolarDate = function (dateStr, timeIndex, options) {
    if (options === void 0) { options = { year: "exact" }; }
    var _a = (0, convertor_1.normalizeDateStr)(dateStr), year = _a[0], month = _a[1], date = _a[2];
    var solar = lunar_typescript_1.Solar.fromYmdHms(year, month, date, Math.max(timeIndex * 2 - 1, 0), 30, 0);
    var lunar = solar.getLunar();
    var yearlyGan = (options === null || options === void 0 ? void 0 : options.year) === "normal"
        ? lunar.getYearGan()
        : lunar.getYearGanByLiChun();
    var yearlyZhi = (options === null || options === void 0 ? void 0 : options.year) === "normal"
        ? lunar.getYearZhi()
        : lunar.getYearZhiByLiChun();
    var yearly = [
        yearlyGan,
        yearlyZhi,
    ];
    var monthly = [
        lunar.getMonthGanExact(),
        lunar.getMonthZhiExact(),
    ];
    var daily = [
        lunar.getDayGanExact(),
        lunar.getDayZhiExact(),
    ];
    var hourly = [
        lunar.getTimeGan(),
        lunar.getTimeZhi(),
    ];
    return {
        yearly: yearly,
        monthly: monthly,
        daily: daily,
        hourly: hourly,
        toString: function () {
            return "".concat(yearly.join(""), " ").concat(monthly.join(""), " ").concat(daily.join(""), " ").concat(hourly.join(""));
        },
    };
};
exports.getHeavenlyStemAndEarthlyBranchBySolarDate = getHeavenlyStemAndEarthlyBranchBySolarDate;
