"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var Utilities_1 = require("../../Utilities");
var Button_1 = require("../../Button");
var Image_1 = require("../../Image");
var getClassNames = Utilities_1.classNamesFunction();
var TeachingBubbleContentBase = /** @class */ (function (_super) {
    tslib_1.__extends(TeachingBubbleContentBase, _super);
    function TeachingBubbleContentBase(props) {
        var _this = _super.call(this, props) || this;
        _this.rootElement = Utilities_1.createRef();
        _this._onKeyDown = function (e) {
            if (_this.props.onDismiss) {
                if (e.which === 27 /* escape */) {
                    _this.props.onDismiss();
                }
            }
        };
        _this.state = {};
        return _this;
    }
    TeachingBubbleContentBase.prototype.componentDidMount = function () {
        if (this.props.onDismiss) {
            document.addEventListener('keydown', this._onKeyDown, false);
        }
    };
    TeachingBubbleContentBase.prototype.componentWillUnmount = function () {
        if (this.props.onDismiss) {
            document.removeEventListener('keydown', this._onKeyDown);
        }
    };
    TeachingBubbleContentBase.prototype.focus = function () {
        if (this.rootElement.current) {
            this.rootElement.current.focus();
        }
    };
    TeachingBubbleContentBase.prototype.render = function () {
        var _a = this.props, children = _a.children, illustrationImage = _a.illustrationImage, primaryButtonProps = _a.primaryButtonProps, secondaryButtonProps = _a.secondaryButtonProps, headline = _a.headline, hasCondensedHeadline = _a.hasCondensedHeadline, hasCloseIcon = _a.hasCloseIcon, onDismiss = _a.onDismiss, closeButtonAriaLabel = _a.closeButtonAriaLabel, hasSmallHeadline = _a.hasSmallHeadline, isWide = _a.isWide, styles = _a.styles, theme = _a.theme, ariaDescribedBy = _a.ariaDescribedBy, ariaLabelledBy = _a.ariaLabelledBy;
        var imageContent;
        var headerContent;
        var bodyContent;
        var footerContent;
        var closeButton;
        var classNames = getClassNames(styles, {
            theme: theme,
            hasCondensedHeadline: hasCondensedHeadline,
            hasSmallHeadline: hasSmallHeadline,
            isWide: isWide,
            primaryButtonClassName: primaryButtonProps ? primaryButtonProps.className : undefined,
            secondaryButtonClassName: secondaryButtonProps ? secondaryButtonProps.className : undefined
        });
        if (illustrationImage && illustrationImage.src) {
            imageContent = (React.createElement("div", { className: classNames.imageContent },
                React.createElement(Image_1.Image, tslib_1.__assign({}, illustrationImage))));
        }
        if (headline) {
            headerContent = (React.createElement("div", { className: classNames.header },
                React.createElement("p", { className: classNames.headline, id: ariaLabelledBy }, headline)));
        }
        if (children) {
            bodyContent = (React.createElement("div", { className: classNames.body },
                React.createElement("p", { className: classNames.subText, id: ariaDescribedBy }, children)));
        }
        if (primaryButtonProps || secondaryButtonProps) {
            footerContent = (React.createElement("div", { className: classNames.footer },
                primaryButtonProps && React.createElement(Button_1.PrimaryButton, tslib_1.__assign({}, primaryButtonProps, { className: classNames.primaryButton })),
                secondaryButtonProps && React.createElement(Button_1.DefaultButton, tslib_1.__assign({}, secondaryButtonProps, { className: classNames.secondaryButton }))));
        }
        if (hasCloseIcon) {
            closeButton = (React.createElement(Button_1.IconButton, { className: classNames.closeButton, iconProps: { iconName: 'Cancel' }, title: closeButtonAriaLabel, ariaLabel: closeButtonAriaLabel, onClick: onDismiss }));
        }
        return (React.createElement("div", { className: classNames.content, ref: this.rootElement, role: 'dialog', tabIndex: -1, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "data-is-focusable": true },
            imageContent,
            React.createElement("div", { className: classNames.bodyContent },
                headerContent,
                bodyContent,
                footerContent),
            closeButton));
    };
    // Specify default props values
    TeachingBubbleContentBase.defaultProps = {
        hasCondensedHeadline: false,
        imageProps: {
            imageFit: Image_1.ImageFit.cover,
            width: 364,
            height: 130
        }
    };
    return TeachingBubbleContentBase;
}(Utilities_1.BaseComponent));
exports.TeachingBubbleContentBase = TeachingBubbleContentBase;
//# sourceMappingURL=TeachingBubbleContent.base.js.map