import * as tslib_1 from "tslib";
import * as React from 'react';
import { BaseComponent, classNamesFunction, createRef } from '../../Utilities';
import { PrimaryButton, DefaultButton, IconButton } from '../../Button';
import { Image, ImageFit } from '../../Image';
var getClassNames = classNamesFunction();
var TeachingBubbleContentBase = /** @class */ (function (_super) {
    tslib_1.__extends(TeachingBubbleContentBase, _super);
    function TeachingBubbleContentBase(props) {
        var _this = _super.call(this, props) || this;
        _this.rootElement = 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, 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(PrimaryButton, tslib_1.__assign({}, primaryButtonProps, { className: classNames.primaryButton })),
                secondaryButtonProps && React.createElement(DefaultButton, tslib_1.__assign({}, secondaryButtonProps, { className: classNames.secondaryButton }))));
        }
        if (hasCloseIcon) {
            closeButton = (React.createElement(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: ImageFit.cover,
            width: 364,
            height: 130
        }
    };
    return TeachingBubbleContentBase;
}(BaseComponent));
export { TeachingBubbleContentBase };
//# sourceMappingURL=TeachingBubbleContent.base.js.map