var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { forwardRef } from "react";
import { BodyLong, BodyShort, ErrorMessage } from "../../../typography/index.js";
import { cl } from "../../../utils/helpers/index.js";
import { useI18n } from "../../../utils/i18n/i18n.hooks.js";
import { formatFileSize } from "../helpers/format-file-size.js";
import { ItemActionField } from "../item-action-field/ItemActionField.js";
import { ItemHeader } from "../item-header/ItemHeader.js";
import { useFileUploadTranslation } from "../root/FileUploadRoot.context.js";
export const FileUploadItem = forwardRef((_a, ref) => {
    var { as: Component = "div", file, status = "idle", error, className, href, onFileClick, button, translations, description } = _a, rest = __rest(_a, ["as", "file", "status", "error", "className", "href", "onFileClick", "button", "translations", "description"]);
    const context = useFileUploadTranslation(false);
    const translate = useI18n("FileUpload", { item: translations }, context === null || context === void 0 ? void 0 : context.translations);
    const showError = !!error && status === "idle";
    function getStatusText() {
        if (status === "uploading") {
            return translate("item.uploading");
        }
        if (status === "downloading") {
            return translate("item.downloading");
        }
        return description !== null && description !== void 0 ? description : formatFileSize(file);
    }
    return (React.createElement(Component, Object.assign({ ref: ref }, rest, { className: cl("aksel-file-item", className, {
            "aksel-file-item--error": showError,
        }) }),
        React.createElement("div", { className: "aksel-file-item__inner" },
            React.createElement(BodyLong, { as: "div", className: "aksel-file-item__file-info" },
                React.createElement(ItemHeader, { file: file, href: href, onClick: onFileClick }),
                React.createElement(BodyShort, { as: "div", size: "small" }, getStatusText()),
                React.createElement("div", { className: "aksel-file-item__error", "aria-relevant": "additions removals", "aria-live": "polite" }, showError && (React.createElement(ErrorMessage, { size: "small", showIcon: true }, error)))),
            React.createElement(ItemActionField, { isLoading: status !== "idle", button: button, translate: translate }))));
});
export default FileUploadItem;
//# sourceMappingURL=FileUploadItem.js.map