import React from 'react';
import classnames from 'classnames';
;
var Button = function (props) {
    var content = props.content, onClick = props.onClick, rawData = props.rawData, rawIndex = props.rawIndex, visible = props.visible, _a = props.cancelBubble, cancelBubble = _a === void 0 ? false : _a, _b = props.disabled, disabled = _b === void 0 ? false : _b;
    var handler;
    var isVisible = true;
    var Component = content;
    var data = {
        item: rawData,
        index: rawIndex
    };
    if (React.isValidElement(Component)) {
        Component = React.cloneElement(Component, {
            disabled: disabled
        });
    }
    else if (typeof Component === 'function') {
        Component = Component(data, disabled);
    }
    if (typeof visible === 'function') {
        isVisible = visible(data);
    }
    if (typeof visible === 'boolean') {
        isVisible = visible;
    }
    handler = function (e) {
        if (cancelBubble) {
            e.stopPropagation();
        }
        if (!disabled && onClick) {
            onClick(e, rawData, rawIndex);
        }
    };
    if (isVisible) {
        return (React.createElement("span", { className: classnames(disabled && 'lp-datagrid-actions-disabled', 'lp-datagrid-actions'), onClick: handler }, Component));
    }
    return null;
};
export default Button;
