"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDateValue = exports.transformerValue = void 0;
var dateFns = __importStar(require("date-fns"));
var services_1 = require("../../services");
function transformerValue(value, options) {
    if (options === void 0) { options = {}; }
    if (!value)
        return null;
    if (typeof value === 'string') {
        var date_1 = services_1.convertStringToDate(value);
        if (!date_1) {
            throw new Error('Data inválida');
        }
        return {
            day: dateFns.getDate(date_1),
            month: dateFns.getMonth(date_1) + 1,
            year: dateFns.getYear(date_1),
            date: date_1,
            dateYYYYMMDD: dateFns.format(date_1, 'yyyyMMdd'),
            dateYYYYMMDDhhiiss: dateFns.format(date_1, 'yyyyMMddHHmm00'),
            allDay: false,
            hour: dateFns.getHours(date_1),
            minutes: dateFns.getMinutes(date_1),
            isToday: dateFns.isToday(date_1),
        };
    }
    if (value instanceof Date) {
        return {
            day: dateFns.getDate(value),
            month: dateFns.getMonth(value) + 1,
            year: dateFns.getYear(value),
            date: value,
            dateYYYYMMDD: dateFns.format(value, 'yyyyMMdd'),
            dateYYYYMMDDhhiiss: (options === null || options === void 0 ? void 0 : options.allDay) ? dateFns.format(value, 'yyyyMMdd000000')
                : dateFns.format(value, 'yyyyMMddHHmm00'),
            allDay: !!(options === null || options === void 0 ? void 0 : options.allDay),
            hour: (options === null || options === void 0 ? void 0 : options.allDay) ? 0 : dateFns.getHours(value),
            minutes: (options === null || options === void 0 ? void 0 : options.allDay) ? 0 : dateFns.getMinutes(value),
            isToday: dateFns.isToday(value),
        };
    }
    if (!value.date || !(value.date instanceof Date)) {
        throw new Error('Data inválida');
    }
    var date = value.date;
    return {
        day: dateFns.getDate(date),
        month: dateFns.getMonth(date) + 1,
        year: dateFns.getYear(date),
        date: date,
        dateYYYYMMDD: dateFns.format(date, 'yyyyMMdd'),
        dateYYYYMMDDhhiiss: (options === null || options === void 0 ? void 0 : options.allDay) ? dateFns.format(date, 'yyyyMMdd000000')
            : dateFns.format(date, 'yyyyMMddHHmm00'),
        allDay: (options === null || options === void 0 ? void 0 : options.allDay) || !!value.allDay,
        hour: (options === null || options === void 0 ? void 0 : options.allDay) ? 0 : dateFns.getHours(date),
        minutes: (options === null || options === void 0 ? void 0 : options.allDay) ? 0 : dateFns.getMinutes(date),
        isToday: dateFns.isToday(date),
    };
}
exports.transformerValue = transformerValue;
function getDateValue(value) {
    if (!value)
        return null;
    if (typeof value === 'string') {
        var date = services_1.convertStringToDate(value);
        return date || null;
    }
    if (value instanceof Date) {
        return value;
    }
    if (!value.date || !(value.date instanceof Date)) {
        throw new Error('Data inválida');
    }
    return value.date;
}
exports.getDateValue = getDateValue;
//# sourceMappingURL=datepicker.interface.js.map