"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileUploadItem = void 0;
const react_1 = __importStar(require("react"));
const typography_1 = require("../../../typography");
const helpers_1 = require("../../../utils/helpers");
const i18n_hooks_1 = require("../../../utils/i18n/i18n.hooks");
const format_file_size_1 = require("../helpers/format-file-size");
const ItemActionField_1 = require("../item-action-field/ItemActionField");
const ItemHeader_1 = require("../item-header/ItemHeader");
const FileUploadRoot_context_1 = require("../root/FileUploadRoot.context");
exports.FileUploadItem = (0, react_1.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 = (0, FileUploadRoot_context_1.useFileUploadTranslation)(false);
    const translate = (0, i18n_hooks_1.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 : (0, format_file_size_1.formatFileSize)(file);
    }
    return (react_1.default.createElement(Component, Object.assign({ ref: ref }, rest, { className: (0, helpers_1.cl)("aksel-file-item", className, {
            "aksel-file-item--error": showError,
        }) }),
        react_1.default.createElement("div", { className: "aksel-file-item__inner" },
            react_1.default.createElement(typography_1.BodyLong, { as: "div", className: "aksel-file-item__file-info" },
                react_1.default.createElement(ItemHeader_1.ItemHeader, { file: file, href: href, onClick: onFileClick }),
                react_1.default.createElement(typography_1.BodyShort, { as: "div", size: "small" }, getStatusText()),
                react_1.default.createElement("div", { className: "aksel-file-item__error", "aria-relevant": "additions removals", "aria-live": "polite" }, showError && (react_1.default.createElement(typography_1.ErrorMessage, { size: "small", showIcon: true }, error)))),
            react_1.default.createElement(ItemActionField_1.ItemActionField, { isLoading: status !== "idle", button: button, translate: translate }))));
});
exports.default = exports.FileUploadItem;
//# sourceMappingURL=FileUploadItem.js.map