function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
import { FieldTimeOutlined } from "@ant-design/icons";
import { Tooltip } from "antd";
import React, { useContext } from "react";
import { useAdaptiveTooltipProps } from "../Hooks/useAdaptiveTooltipProps";
import { I18nContext } from "../I18n";
/**
 * 将毫秒转换为可读的时间格式
 *
 * @param {number|undefined} ms - 毫秒数
 * @param {LocalKeys} locale - 本地化配置
 * @returns {string} 格式化后的时间字符串
 *
 * @example
 * msToTimes(1500, locale) // "1.5s"
 * msToTimes(65000, locale) // "1m 5s"
 * msToTimes(3665000, locale) // "1H 1m 5s"
 */ /** 导出供单测覆盖 undefined/null 分支 */ export var msToTimes = function msToTimes(ms, locale) {
    if (ms === undefined || ms === null) {
        return '';
    }
    if (ms === 0) {
        return '0ms';
    }
    if (ms < 1000) {
        return "".concat(ms, "ms");
    }
    var totalSeconds = Math.floor(ms / 1000);
    var secondsUnit = (locale === null || locale === void 0 ? void 0 : locale.seconds) || 's';
    var minutesUnit = (locale === null || locale === void 0 ? void 0 : locale.minutes) || 'm';
    var hoursUnit = (locale === null || locale === void 0 ? void 0 : locale.hours) || 'H';
    var daysUnit = (locale === null || locale === void 0 ? void 0 : locale.days) || 'D';
    // 小于60秒，显示秒（带小数）
    if (totalSeconds < 60) {
        var seconds = ms / 1000;
        return "".concat(seconds.toFixed(1)).concat(secondsUnit);
    }
    // 计算分钟和秒
    var totalMinutes = Math.floor(totalSeconds / 60);
    var remainingSeconds = totalSeconds % 60;
    // 小于60分钟，显示分钟和秒
    if (totalMinutes < 60) {
        return "".concat(totalMinutes).concat(minutesUnit, " ").concat(remainingSeconds).concat(secondsUnit);
    }
    // 计算小时、分钟和秒
    var totalHours = Math.floor(totalMinutes / 60);
    var remainingMinutes = totalMinutes % 60;
    // 小于24小时，显示小时、分钟和秒
    if (totalHours < 24) {
        return "".concat(totalHours).concat(hoursUnit, " ").concat(remainingMinutes).concat(minutesUnit, " ").concat(remainingSeconds).concat(secondsUnit);
    }
    // 大于等于24小时，计算天、小时、分钟和秒
    var totalDays = Math.floor(totalHours / 24);
    var remainingHours = totalHours % 24;
    return "".concat(totalDays).concat(daysUnit, " ").concat(remainingHours).concat(hoursUnit, " ").concat(remainingMinutes).concat(minutesUnit, " ").concat(remainingSeconds).concat(secondsUnit);
};
/**
 * CostMillis 组件 - 耗时显示组件
 *
 * 该组件用于显示操作耗时，支持毫秒到天的时间格式转换，
 * 提供美观的UI展示和工具提示功能。
 *
 * @component
 * @description 耗时显示组件，显示操作耗时信息
 * @param {Object} props - 组件属性
 * @param {number} [props.costMillis] - 耗时（毫秒）
 *
 * @example
 * ```tsx
 * <CostMillis costMillis={1500} />
 * <CostMillis costMillis={65000} />
 * <CostMillis costMillis={3600000} />
 * ```
 *
 * @returns {React.ReactElement|null} 渲染的耗时显示组件，无耗时数据时返回null
 *
 * @remarks
 * - 自动转换时间格式（毫秒、秒、分钟、小时、天）
 * - 提供工具提示显示原始毫秒值
 * - 支持国际化时间单位
 * - 美观的渐变背景设计
 * - 响应式布局适配
 * - 图标和文字组合显示
 */ export var CostMillis = function CostMillis(props) {
    var locale = useContext(I18nContext).locale;
    var adaptiveTooltip = useAdaptiveTooltipProps('informational');
    if (props.costMillis === undefined || props.costMillis === null) {
        return null;
    }
    return /*#__PURE__*/ React.createElement(Tooltip, _object_spread({
        mouseEnterDelay: 0.3,
        title: props.costMillis + 'ms'
    }, adaptiveTooltip), /*#__PURE__*/ React.createElement("span", {
        style: {
            display: 'flex',
            flexDirection: 'row',
            alignItems: 'center',
            padding: '1px 10px',
            gap: '6px',
            borderRadius: '12px',
            height: '2em',
            minHeight: '28px',
            fontSize: '0.9em',
            wordBreak: 'break-all',
            wordWrap: 'break-word',
            maxWidth: '100%',
            background: 'radial-gradient(22% 66% at 96% 113%, rgba(255, 255, 245, 0.52) 0%, rgba(230, 238, 255, 0) 100%), radial-gradient(14% 234% at 100% 50%, rgba(162, 255, 255, 0.28) 0%, rgba(153, 202, 255, 0.1193) 13%, rgba(229, 189, 255, 0.0826) 38%, rgba(235, 255, 245, 0) 100%), #FFFFFF',
            border: '1px solid rgba(227, 230, 234, 0.65)'
        }
    }, /*#__PURE__*/ React.createElement(FieldTimeOutlined, null), msToTimes(props.costMillis, locale)));
};
