"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileExtension = void 0;
exports.getFileExt = getFileExt;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const React = tslib_1.__importStar(require("react"));
const uikit_1 = require("@gravity-ui/uikit");
const locationContext_1 = require("../../gravity-blocks/context/locationContext/index.js");
const utils_1 = require("../../utils/index.js");
const b = (0, utils_1.block)('file-link');
const FIGMA_URL = 'https://www.figma.com';
var FileExtension;
(function (FileExtension) {
    FileExtension["PDF"] = "pdf";
    FileExtension["DOC"] = "doc";
    FileExtension["XLS"] = "xls";
    FileExtension["PPT"] = "ppt";
    FileExtension["FIG"] = "fig";
    FileExtension["ZIP"] = "zip";
})(FileExtension || (exports.FileExtension = FileExtension = {}));
function getFileExt(name) {
    if (name?.includes(FIGMA_URL)) {
        return FileExtension.FIG;
    }
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
    return name && name.split('.').pop().toLowerCase();
}
const FileExtensionThemes = {
    [FileExtension.PDF]: 'danger',
    [FileExtension.DOC]: 'info',
    [FileExtension.XLS]: 'success',
    [FileExtension.PPT]: 'warning',
    [FileExtension.FIG]: 'normal',
    [FileExtension.ZIP]: 'unknown',
};
const LabelSizeMap = {
    l: 's',
    m: 's',
    sm: 's',
    s: 'xs',
    xs: 'xs',
};
function getTextSize(size) {
    if (size === 'sm') {
        return 'm';
    }
    return size;
}
const FileLink = (props) => {
    const { hostname } = React.useContext(locationContext_1.LocationContext);
    const { href, text, type = 'vertical', textSize = 'm', className, theme = 'default', onClick, tabIndex, urlTitle, extraProps, } = props;
    const fileExt = getFileExt(href);
    const labelTheme = (FileExtensionThemes[fileExt] || 'unknown');
    const labelSize = LabelSizeMap[textSize];
    return ((0, jsx_runtime_1.jsxs)("div", { className: b({ ext: fileExt, type, size: getTextSize(textSize), theme }, className), children: [(0, jsx_runtime_1.jsx)(uikit_1.Label, { className: b('file-label'), size: labelSize, theme: labelTheme, children: fileExt }), (0, jsx_runtime_1.jsx)("div", { className: b('link'), children: (0, jsx_runtime_1.jsx)("a", { href: href, onClick: onClick, tabIndex: tabIndex, title: urlTitle, ...(0, utils_1.getLinkProps)(href, hostname), ...extraProps, children: text }) })] }));
};
exports.default = FileLink;
//# sourceMappingURL=FileLink.js.map
