"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var DocumentCard_Props_1 = require("./DocumentCard.Props");
var Utilities_1 = require("../../Utilities");
var stylesImport = require("./DocumentCard.scss");
var styles = stylesImport;
var DocumentCard = (function (_super) {
    tslib_1.__extends(DocumentCard, _super);
    function DocumentCard() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    DocumentCard.prototype.render = function () {
        var _a = this.props, onClick = _a.onClick, onClickHref = _a.onClickHref, children = _a.children, className = _a.className, type = _a.type, accentColor = _a.accentColor;
        var actionable = (onClick || onClickHref) ? true : false;
        // Override the border color if an accent color was provided (compact card only)
        var style;
        if (type === DocumentCard_Props_1.DocumentCardType.compact && accentColor) {
            style = {
                borderBottomColor: accentColor
            };
        }
        // if this element is actionable it should have an aria role
        var role = actionable ? (onClick ? 'button' : 'link') : null;
        var tabIndex = actionable ? 0 : null;
        return (React.createElement("div", { tabIndex: tabIndex, role: role, className: Utilities_1.css('ms-DocumentCard', styles.root, (_b = {},
                _b['ms-DocumentCard--actionable ' + styles.rootIsActionable] = actionable,
                _b['ms-DocumentCard--compact ' + styles.rootIsCompact] = type === DocumentCard_Props_1.DocumentCardType.compact ? true : false,
                _b), className), onKeyDown: actionable ? this._onKeyDown : null, onClick: actionable ? this._onClick : null, style: style }, children));
        var _b;
    };
    DocumentCard.prototype._onClick = function (ev) {
        this._onAction(ev);
    };
    DocumentCard.prototype._onKeyDown = function (ev) {
        if (ev.which === Utilities_1.KeyCodes.enter || ev.which === Utilities_1.KeyCodes.space) {
            this._onAction(ev);
        }
    };
    DocumentCard.prototype._onAction = function (ev) {
        var _a = this.props, onClick = _a.onClick, onClickHref = _a.onClickHref;
        if (onClick) {
            onClick(ev);
        }
        else if (!onClick && onClickHref) {
            // If no onClick Function was provided and we do have an onClickHref, redirect to the onClickHref
            window.location.href = onClickHref;
            ev.preventDefault();
            ev.stopPropagation();
        }
    };
    return DocumentCard;
}(Utilities_1.BaseComponent));
DocumentCard.defaultProps = {
    type: DocumentCard_Props_1.DocumentCardType.normal
};
tslib_1.__decorate([
    Utilities_1.autobind
], DocumentCard.prototype, "_onClick", null);
tslib_1.__decorate([
    Utilities_1.autobind
], DocumentCard.prototype, "_onKeyDown", null);
tslib_1.__decorate([
    Utilities_1.autobind
], DocumentCard.prototype, "_onAction", null);
exports.DocumentCard = DocumentCard;

//# sourceMappingURL=DocumentCard.js.map
