import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import * as React from 'react';
import { Label } from '@gravity-ui/uikit';
import { LocationContext } from "../../gravity-blocks/context/locationContext/index.js";
import { block, getLinkProps } from "../../utils/index.js";
import './FileLink.css';
const b = block('file-link');
const FIGMA_URL = 'https://www.figma.com';
export var FileExtension;
(function (FileExtension) {
    FileExtension["PDF"] = "pdf";
    FileExtension["DOC"] = "doc";
    FileExtension["XLS"] = "xls";
    FileExtension["PPT"] = "ppt";
    FileExtension["FIG"] = "fig";
    FileExtension["ZIP"] = "zip";
})(FileExtension || (FileExtension = {}));
export 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);
    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 (_jsxs("div", { className: b({ ext: fileExt, type, size: getTextSize(textSize), theme }, className), children: [_jsx(Label, { className: b('file-label'), size: labelSize, theme: labelTheme, children: fileExt }), _jsx("div", { className: b('link'), children: _jsx("a", { href: href, onClick: onClick, tabIndex: tabIndex, title: urlTitle, ...getLinkProps(href, hostname), ...extraProps, children: text }) })] }));
};
export default FileLink;
//# sourceMappingURL=FileLink.js.map
