var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { useMemo } from 'react';
import { DateTime } from 'luxon';
export const useDateLocale = (datetimeFormatOptions = null, locale = null) => {
    const dateTimeOptions = useMemo(() => (datetimeFormatOptions !== null && datetimeFormatOptions !== void 0 ? datetimeFormatOptions : {
        timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
        year: 'numeric',
        month: 'short',
        day: 'numeric',
        hour: 'numeric',
        minute: 'numeric',
        hour12: true,
    }), [datetimeFormatOptions]);
    const localeString = useMemo(() => locale !== null && locale !== void 0 ? locale : navigator.language, [locale]);
    const convertISOStringToLocalDateTime = (date) => {
        const luxonDateTime = DateTime.fromISO(date, { zone: 'utc' });
        luxonDateTime.setZone(dateTimeOptions.timeZone);
        luxonDateTime.setLocale(localeString);
        if (!luxonDateTime.isValid) {
            return null;
        }
        return luxonDateTime.toLocaleString(dateTimeOptions);
    };
    const convertISOStringToLocalDate = (date) => {
        const luxonDateTime = DateTime.fromISO(date);
        luxonDateTime.setZone(dateTimeOptions.timeZone);
        luxonDateTime.setLocale(localeString);
        if (!luxonDateTime.isValid) {
            return null;
        }
        const { hour, minute } = dateTimeOptions, dateOptions = __rest(dateTimeOptions, ["hour", "minute"]);
        return luxonDateTime.toLocaleString(dateOptions);
    };
    const getISODate = () => {
        return DateTime.now().toISO({ includeOffset: true, suppressMilliseconds: true });
    };
    return {
        convertISOStringToLocalDateTime: convertISOStringToLocalDateTime,
        convertISOStringToLocalDate: convertISOStringToLocalDate,
        getISODate: getISODate
    };
};
//# sourceMappingURL=useDateLocale.js.map