"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileItem = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const icons_1 = require("@gravity-ui/icons");
const uikit_1 = require("@gravity-ui/uikit");
const cn_1 = require("../../../utils/cn.js");
const FileIcon_1 = require("../../atoms/FileIcon/index.js");
const i18n_1 = require("./i18n/index.js");
require("./FileItem.css");
const b = (0, cn_1.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.
 */
const FileItem = ({ name, size, status, mimeType, previewUrl, disabled, onRemove, className, }) => {
    return ((0, jsx_runtime_1.jsxs)("div", { className: b({ status, disabled }, className), children: [(0, jsx_runtime_1.jsx)("div", { className: b('icon'), children: previewUrl ? ((0, jsx_runtime_1.jsx)("img", { src: previewUrl, alt: name, className: b('preview') })) : ((0, jsx_runtime_1.jsx)(FileIcon_1.FileIcon, { mimeType: mimeType, fileName: name, size: "m" })) }), (0, jsx_runtime_1.jsxs)("div", { className: b('info'), children: [(0, jsx_runtime_1.jsx)("span", { className: b('name'), title: name, children: name }), size !== undefined && (0, jsx_runtime_1.jsx)("span", { className: b('size'), children: formatSize(size) })] }), (0, jsx_runtime_1.jsxs)("div", { className: b('status'), children: [status === 'loading' && (0, jsx_runtime_1.jsx)(uikit_1.Spin, { size: "xs" }), status === 'success' && ((0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.CircleCheck, size: 16, className: b('status-icon', { success: true }) })), status === 'error' && ((0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.CircleXmark, size: 16, className: b('status-icon', { error: true }) }))] }), onRemove && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: b('remove'), onClick: onRemove, disabled: disabled, "aria-label": (0, i18n_1.i18n)('remove-button-label'), children: (0, jsx_runtime_1.jsx)(uikit_1.Icon, { data: icons_1.Xmark, size: 12 }) }))] }));
};
exports.FileItem = FileItem;
//# sourceMappingURL=FileItem.js.map
