"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ButtonBase = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const rebass_1 = require("rebass");
const join_1 = tslib_1.__importDefault(require("../../../../components/utils/join"));
const Glyphicon = ({ glyph, style }) => {
    return React.createElement("span", { style: style, className: `glyphicon glyphicon-${glyph}` });
};
const baseClassName = 'ab-Button';
class ButtonBase extends React.Component {
    render() {
        let isDisabled;
        isDisabled = this.props.accessLevel == 'Hidden';
        if (this.props.overrideDisableButton || this.props.disabled) {
            isDisabled = true;
        }
        let text = this.props.children || this.props.toolTipAndText;
        if (this.props.overrideText) {
            text = this.props.overrideText;
        }
        let tooltip = this.props.toolTipAndText;
        if (this.props.overrideTooltip) {
            tooltip = this.props.overrideTooltip;
        }
        let hideToolTip = this.props.hideToolTip ? this.props.hideToolTip : false;
        let content;
        if (this.props.displayMode == 'Glyph') {
            if (this.props.transformGlyph) {
                content = React.createElement(Glyphicon, { glyph: this.props.glyph, style: { transform: 'scale(-1, 1)' } });
            }
            else {
                content = React.createElement(Glyphicon, { glyph: this.props.glyph });
            }
        }
        else if (this.props.displayMode == 'Text') {
            content = React.createElement("span", null, text);
        }
        else if (this.props.displayMode == 'Glyph+Text') {
            content = (React.createElement("div", null,
                React.createElement(Glyphicon, { glyph: this.props.glyph }),
                " ",
                text));
        }
        else if (this.props.displayMode == 'Text+Glyph') {
            content = (React.createElement("div", null,
                text,
                " ",
                React.createElement(Glyphicon, { glyph: this.props.glyph })));
        }
        if (this.props.icon) {
            content = (React.createElement(React.Fragment, null,
                this.props.iconPosition === 'end' ? text : null,
                " ",
                React.createElement(Glyphicon, { glyph: this.props.icon }),
                ' ',
                this.props.iconPosition !== 'end' ? text : null));
        }
        let button = (React.createElement(rebass_1.Button, { ...this.props, style: { color: 'currentColor', ...this.props.style }, className: (0, join_1.default)(baseClassName, `${baseClassName}--size-${'normal'}`, `${baseClassName}--style-${'normal'}`, isDisabled ? `${baseClassName}--disabled` : `${baseClassName}--enabled`), disabled: isDisabled, onClick: this.props.onClick, onMouseDown: this.props.onMouseDown || ((e) => e.preventDefault()) }, content));
        let buttonwithtooltip = React.createElement("div", null, button);
        return hideToolTip ? button : buttonwithtooltip;
    }
}
exports.ButtonBase = ButtonBase;
ButtonBase.defaultProps = {
    overrideDisableButton: false,
    toolTipAndText: '',
    glyph: '',
    displayMode: 'Glyph+Text',
    transformGlyph: false,
    accessLevel: 'Full',
    showDefaultStyle: false,
};
