"use strict";
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 __());
    };
})();
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 });
var React = __importStar(require("react"));
var classnames_1 = __importDefault(require("classnames"));
var functions_1 = require("../utils/functions");
var Block_1 = require("./Block");
var Icon_1 = require("./Icon");
var index_en_US_1 = __importDefault(require("../../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) {
                    functions_1.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_1.default('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_1.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_1.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_1.default('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_1.default('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 index_en_US_1.default.CLOSE;
        }
    };
    return InfoCard;
}(React.PureComponent));
exports.InfoCard = InfoCard;
//# sourceMappingURL=InfoCard.js.map