var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
import * as React from 'react';
import classnames from 'classnames';
import { scrollElementIntoView } from '../utils/functions';
import { Block } from './Block';
import { Icon } from './Icon';
import lang from '../../lang/common/index-en_US';
var InfoCard = /** @class */ (function (_super) {
    __extends(InfoCard, _super);
    function InfoCard() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.ref = null;
        _this.getNodeRef = function (element) {
            if (_this.ref !== element && element) {
                var shouldScrollIntoView = _this.props.shouldScrollIntoView;
                if (shouldScrollIntoView) {
                    scrollElementIntoView(element);
                }
            }
            _this.ref = element;
        };
        return _this;
    }
    InfoCard.calculateTipPositionWithColumns = function (index, columns) {
        return (100 / columns) * ((index % columns) + 0.5);
    };
    InfoCard.calculateTipPositionByOffset = function (percent) {
        var correction = 0.5;
        return Math.max(correction, Math.min(percent + 0.5, 100 - correction));
    };
    InfoCard.prototype.hasCloseButton = function () {
        var onClose = this.props.onClose;
        return typeof onClose === 'function';
    };
    InfoCard.prototype.hasTip = function () {
        var tipOffset = this.props.tipOffset;
        return typeof tipOffset === 'number' || typeof tipOffset === 'string';
    };
    InfoCard.prototype.renderTip = function () {
        var tipOffset = this.props.tipOffset;
        if (!this.hasTip()) {
            return null;
        }
        if (typeof tipOffset === 'number') {
            return React.createElement("div", { style: { left: tipOffset + "%" }, className: "rc-info-card__tip" });
        }
        if (typeof tipOffset === 'string') {
            return React.createElement("div", { style: { left: tipOffset }, className: "rc-info-card__tip" });
        }
        return null;
    };
    InfoCard.prototype.renderTitle = function () {
        var title = this.props.title;
        if (!title) {
            return null;
        }
        var className = classnames('rc-info-card__title', {
            'rc-info-card__title--with-close': this.hasCloseButton()
        });
        return (React.createElement("div", { className: className, "data-test-automation-id": "title" },
            React.createElement(Block, { addTopOffset: true, addHorizontalOffset: true }, title)));
    };
    InfoCard.prototype.renderCloseButton = function () {
        if (!this.hasCloseButton()) {
            return null;
        }
        var _a = this.props, onClose = _a.onClose, closeLabel = _a.closeLabel;
        return (React.createElement("button", { "data-test-automation-id": "closeButton", className: "rc-info-card__close", onClick: onClose },
            React.createElement(Icon, { name: "close" }),
            React.createElement("span", { className: "sr-only" }, closeLabel)));
    };
    InfoCard.prototype.renderContent = function () {
        var _a = this.props, children = _a.children, title = _a.title;
        var className = classnames('rc-info-card__content', {
            'rc-info-card__content--with-close': !title && this.hasCloseButton()
        });
        return (React.createElement("div", { className: className, "data-test-automation-id": "infoCardChildren" }, children));
    };
    InfoCard.prototype.render = function () {
        var testAutomationId = this.props.testAutomationId;
        var className = classnames('rc-info-card', {
            'rc-info-card--with-tip': this.hasTip()
        });
        return (React.createElement("div", { ref: this.getNodeRef, className: className, "data-test-automation-id": testAutomationId },
            this.renderTip(),
            this.renderTitle(),
            this.renderCloseButton(),
            this.renderContent()));
    };
    InfoCard.defaultProps = {
        testAutomationId: 'infoCard',
        shouldScrollIntoView: false,
        get closeLabel() {
            return lang.CLOSE;
        }
    };
    return InfoCard;
}(React.PureComponent));
export { InfoCard };
//# sourceMappingURL=InfoCard.js.map