"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/* @flow */
const react_1 = __importStar(require("react"));
const prop_types_1 = __importDefault(require("prop-types"));
const classnames_1 = __importDefault(require("classnames"));
const get_1 = __importDefault(require("lodash/get"));
const smart_truncate_1 = __importDefault(require("smart-truncate"));
const withStyles_1 = __importDefault(require("components/hoc/withStyles"));
const types_1 = require("components/config/types");
const styles_1 = __importDefault(require("./styles"));
class FileBlock extends react_1.Component {
    render() {
        const { classes, file, showRemoveButton, variant, onRemoveClick, } = this.props;
        const extPos = get_1.default(file, 'name', '').lastIndexOf('.');
        const ext = get_1.default(file, 'name', '').substring(extPos + 1);
        let WrapComponent;
        let extraProps = {};
        if (variant === 'link' && get_1.default(file, 'url')) {
            WrapComponent = 'a';
            extraProps = {
                href: get_1.default(file, 'url'),
                target: '_blank',
            };
        }
        else {
            WrapComponent = 'div';
        }
        return (react_1.default.createElement(WrapComponent, Object.assign({ className: classes.component }, extraProps),
            react_1.default.createElement("div", { className: classes.icon },
                react_1.default.createElement("img", { src: require('images/file-icon.png'), className: classes.iconImage }),
                react_1.default.createElement("div", { className: classes.ext }, ext)),
            react_1.default.createElement("div", { className: classes.filename }, smart_truncate_1.default(file.name || '', 12, { position: 5 })),
            variant === 'interactive' && (react_1.default.createElement("div", { className: classes.hoverIconWrapper },
                get_1.default(file, 'url') && (react_1.default.createElement("a", { href: get_1.default(file, 'url'), target: "_blank", rel: "noopener noreferrer", className: classes.linkIconWrapper, onClick: e => {
                        e.stopPropagation();
                    } },
                    react_1.default.createElement("i", { className: classnames_1.default('fa fa-link', classes.linkIcon) }))),
                showRemoveButton && (react_1.default.createElement("div", { className: classes.closeIconWrapper },
                    react_1.default.createElement("i", { className: classnames_1.default('fa fa-times', classes.closeIcon), onClick: onRemoveClick })))))));
    }
}
FileBlock.propTypes = Object.assign({ file: prop_types_1.default.any, onRemoveClick: prop_types_1.default.func, showRemoveButton: prop_types_1.default.bool, variant: prop_types_1.default.oneOf(['none', 'interactive', 'link']) }, types_1.withStylesProps);
FileBlock.defaultProps = {
    onRemoveClick: () => { },
    showRemoveButton: true,
    variant: 'none',
};
exports.default = withStyles_1.default(styles_1.default)(FileBlock);
//# sourceMappingURL=index.js.map