import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Fragment } from 'react';
import { useDateFormatter } from "../../../hooks/index.js";
import { block } from "../../../utils/cn.js";
import { i18n } from "./i18n/index.js";
import "./ChatDate.css";
const b = block('chat-date');
/**
 * ChatDate component displays formatted dates with optional time
 *
 * @param props - Component props
 * @returns React component
 */
export function ChatDate(props) {
    const { date, showTime = false, format, className, qa, relative = false, style } = props;
    const { formattedDate, formattedTime, fullDate, dateObject, isValid, diffDays } = useDateFormatter({
        date,
        format,
    });
    if (!isValid || !dateObject) {
        return i18n('invalid-date');
    }
    return (_jsx("time", { className: b({}, className), dateTime: dateObject.toISOString(), title: fullDate, "data-qa": qa, style: style, children: relative && typeof diffDays === 'number' ? (_jsx("span", { children: i18n('ago', { count: diffDays }) })) : (_jsxs(Fragment, { children: [_jsx("span", { children: formattedDate }), _jsx("span", { children: showTime && formattedTime && ` ${formattedTime}` })] })) }));
}
//# sourceMappingURL=ChatDate.js.map
