import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { CircleCheck, CircleXmark, Xmark } from '@gravity-ui/icons';
import { Icon, Spin } from '@gravity-ui/uikit';
import { block } from "../../../utils/cn.js";
import { FileIcon } from "../../atoms/FileIcon/index.js";
import { i18n } from "./i18n/index.js";
import "./FileItem.css";
const b = block('file-item');
function formatSize(bytes) {
    if (bytes < 1024)
        return `${bytes} B`;
    if (bytes < 1024 * 1024)
        return `${(bytes / 1024).toFixed(1)} KB`;
    return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}
/**
 * FileItem displays a single file row with icon, name, optional size, status indicator, and remove button.
 */
export const FileItem = ({ name, size, status, mimeType, previewUrl, disabled, onRemove, className, }) => {
    return (_jsxs("div", { className: b({ status, disabled }, className), children: [_jsx("div", { className: b('icon'), children: previewUrl ? (_jsx("img", { src: previewUrl, alt: name, className: b('preview') })) : (_jsx(FileIcon, { mimeType: mimeType, fileName: name, size: "m" })) }), _jsxs("div", { className: b('info'), children: [_jsx("span", { className: b('name'), title: name, children: name }), size !== undefined && _jsx("span", { className: b('size'), children: formatSize(size) })] }), _jsxs("div", { className: b('status'), children: [status === 'loading' && _jsx(Spin, { size: "xs" }), status === 'success' && (_jsx(Icon, { data: CircleCheck, size: 16, className: b('status-icon', { success: true }) })), status === 'error' && (_jsx(Icon, { data: CircleXmark, size: 16, className: b('status-icon', { error: true }) }))] }), onRemove && (_jsx("button", { type: "button", className: b('remove'), onClick: onRemove, disabled: disabled, "aria-label": i18n('remove-button-label'), children: _jsx(Icon, { data: Xmark, size: 12 }) }))] }));
};
//# sourceMappingURL=FileItem.js.map
