"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const styles_1 = require("@mui/material/styles");
const material_1 = require("@mui/material");
const Icon_1 = tslib_1.__importDefault(require("@mui/material/Icon"));
const react_intl_1 = require("react-intl");
const classnames_1 = tslib_1.__importDefault(require("classnames"));
const formatRelativeTime_1 = require("../../utils/formatRelativeTime");
const PREFIX = 'SCDateTimeAgo';
const classes = {
    root: `${PREFIX}-root`
};
const Root = (0, styles_1.styled)(material_1.Box, {
    name: PREFIX,
    slot: 'Root',
    overridesResolver: (props, styles) => [styles.root]
})(() => ({
    width: 'auto',
    display: 'inline-flex',
    alignItems: 'center',
    marginRight: 3,
    '& .MuiIcon-root': {
        fontSize: '18px',
        marginRight: 2
    },
    '& .MuiTypography-root': {
        lineHeight: 1.8
    }
}));
function DateTimeAgo(props) {
    // PROPS
    const { className, date = null, showStartIcon = true } = props, rest = tslib_1.__rest(props, ["className", "date", "showStartIcon"]);
    // INTL
    const intl = (0, react_intl_1.useIntl)();
    /**
     * Renders root object (if date obj)
     */
    if (date) {
        const formattedDate = (0, formatRelativeTime_1.getRelativeTime)(date);
        return ((0, jsx_runtime_1.jsxs)(Root, Object.assign({ component: "span", className: (0, classnames_1.default)(classes.root, className) }, rest, { children: [showStartIcon && (0, jsx_runtime_1.jsx)(Icon_1.default, { children: "access_time" }), (0, jsx_runtime_1.jsx)(material_1.Tooltip, Object.assign({ title: `${intl.formatDate(date, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric' })}`, enterTouchDelay: 0 }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, Object.assign({ variant: 'body2', component: 'span' }, { children: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedRelativeTime, { value: -formattedDate.value, unit: formattedDate.unit, numeric: "auto" }) })) }))] })));
    }
    return null;
}
exports.default = DateTimeAgo;
