var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var __assign = (this && this.__assign) || Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
};
define(["require", "exports", "react", "../../Utilities", "./Facepile.Props", "../../FocusZone", "../../Button", "../../Persona", "./Facepile.scss"], function (require, exports, React, Utilities_1, Facepile_Props_1, FocusZone_1, Button_1, Persona_1, Facepile_scss_1) {
    "use strict";
    var Facepile = (function (_super) {
        __extends(Facepile, _super);
        function Facepile() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        Facepile.prototype.render = function () {
            var _this = this;
            var _a = this.props, chevronButtonProps = _a.chevronButtonProps, maxDisplayablePersonas = _a.maxDisplayablePersonas, overflowButtonProps = _a.overflowButtonProps, overflowButtonType = _a.overflowButtonType, personas = _a.personas, showAddButton = _a.showAddButton;
            var numPersonasToShow = Math.min(personas.length, maxDisplayablePersonas);
            // Added for deprecating chevronButtonProps.  Can remove after v1.0
            if (chevronButtonProps && !overflowButtonProps) {
                overflowButtonProps = chevronButtonProps;
                overflowButtonType = Facepile_Props_1.OverflowButtonType.downArrow;
            }
            return (React.createElement("div", { className: Utilities_1.css('ms-Facepile', Facepile_scss_1.default.root) },
                React.createElement("div", { className: Utilities_1.css('ms-Facepile-members') },
                    showAddButton ? this._getAddNewElement() : null,
                    React.createElement(FocusZone_1.FocusZone, { direction: FocusZone_1.FocusZoneDirection.horizontal },
                        personas.slice(0, numPersonasToShow).map(function (persona, index) {
                            var personaControl = _this._getPersonaControl(persona);
                            return persona.onClick ?
                                _this._getElementWithOnClickEvent(personaControl, persona, index) :
                                _this._getElementWithoutOnClickEvent(personaControl, persona, index);
                        }),
                        overflowButtonProps ? this._getOverflowElement(numPersonasToShow) : null)),
                React.createElement("div", { className: Utilities_1.css('ms-Facepile-clear', Facepile_scss_1.default.clear) })));
        };
        Facepile.prototype._getPersonaControl = function (persona) {
            var _a = this.props, getPersonaProps = _a.getPersonaProps, personaSize = _a.personaSize;
            return React.createElement(Persona_1.Persona, __assign({ imageInitials: persona.imageInitials, imageUrl: persona.imageUrl, initialsColor: persona.initialsColor, primaryText: persona.personaName, size: personaSize, hidePersonaDetails: true }, (getPersonaProps ? getPersonaProps(persona) : null)));
        };
        Facepile.prototype._getElementWithOnClickEvent = function (personaControl, persona, index) {
            return React.createElement(Button_1.BaseButton, __assign({}, Utilities_1.getNativeProps(persona, Utilities_1.buttonProperties), { className: Utilities_1.css('ms-Facepile-itemButton ms-Facepile-person', Facepile_scss_1.default.itemButton), title: persona.personaName, key: (!!persona.imageUrl ? 'i' : '') + index, onClick: this._onPersonaClick.bind(this, persona), onMouseMove: this._onPersonaMouseMove.bind(this, persona), onMouseOut: this._onPersonaMouseOut.bind(this, persona) }), personaControl);
        };
        Facepile.prototype._getElementWithoutOnClickEvent = function (personaControl, persona, index) {
            return React.createElement("div", __assign({}, Utilities_1.getNativeProps(persona, Utilities_1.divProperties), { className: Utilities_1.css('ms-Facepile-itemButton ms-Facepile-person', Facepile_scss_1.default.itemButton), title: persona.personaName, key: (!!persona.imageUrl ? 'i' : '') + index, onMouseMove: this._onPersonaMouseMove.bind(this, persona), onMouseOut: this._onPersonaMouseOut.bind(this, persona) }), personaControl);
        };
        Facepile.prototype._getOverflowElement = function (numPersonasToShow) {
            switch (this.props.overflowButtonType) {
                case Facepile_Props_1.OverflowButtonType.descriptive:
                    return this._getDescriptiveOverflowElement(numPersonasToShow);
                case Facepile_Props_1.OverflowButtonType.downArrow:
                    return this._getIconElement('ChevronDown');
                case Facepile_Props_1.OverflowButtonType.more:
                    return this._getIconElement('More');
                default:
                    return null;
            }
        };
        Facepile.prototype._getDescriptiveOverflowElement = function (numPersonasToShow) {
            var personaSize = this.props.personaSize;
            var numPersonasNotPictured = this.props.personas.length - numPersonasToShow;
            if (!this.props.overflowButtonProps || numPersonasNotPictured < 1) {
                return null;
            }
            var personaNames = this.props.personas.slice(numPersonasToShow).map(function (p) { return p.personaName; }).join(', ');
            return React.createElement(Button_1.BaseButton, __assign({}, Utilities_1.getNativeProps(this.props.overflowButtonProps, Utilities_1.buttonProperties), { className: Utilities_1.css('ms-Facepile-descriptiveOverflowButton', 'ms-Facepile-itemButton', Facepile_scss_1.default.descriptiveOverflowButton, Facepile_scss_1.default.itemButton) }),
                React.createElement(Persona_1.Persona, { title: personaNames, size: personaSize, hidePersonaDetails: true, onRenderInitials: function () {
                        return (React.createElement("span", null, '+' + numPersonasNotPictured));
                    } }));
        };
        Facepile.prototype._getIconElement = function (icon) {
            var personaSize = this.props.personaSize;
            return React.createElement(Button_1.BaseButton, __assign({}, Utilities_1.getNativeProps(this.props.overflowButtonProps, Utilities_1.buttonProperties), { className: Utilities_1.css('ms-Facepile-overflowButton', 'ms-Facepile-itemButton', Facepile_scss_1.default.overflowButton, Facepile_scss_1.default.itemButton) }),
                React.createElement(Persona_1.Persona, { size: personaSize, hidePersonaDetails: true, onRenderInitials: function () { return (React.createElement("i", { className: Utilities_1.css('ms-Icon', 'msIcon', "ms-Icon ms-Icon--" + icon), "aria-hidden": 'true' })); } }));
        };
        Facepile.prototype._getAddNewElement = function () {
            var personaSize = this.props.personaSize;
            return React.createElement(Button_1.BaseButton, __assign({}, Utilities_1.getNativeProps(this.props.addButtonProps, Utilities_1.buttonProperties), { className: Utilities_1.css('ms-Facepile-addButton', 'ms-Facepile-itemButton', Facepile_scss_1.default.itemButton, Facepile_scss_1.default.addButton) }),
                React.createElement(Persona_1.Persona, { size: personaSize, hidePersonaDetails: true, onRenderInitials: function () { return (React.createElement("i", { className: 'ms-Icon msIcon ms-Icon--AddFriend', "aria-hidden": 'true' })); } }));
        };
        Facepile.prototype._onPersonaClick = function (persona, ev) {
            persona.onClick(ev, persona);
            ev.preventDefault();
            ev.stopPropagation();
        };
        Facepile.prototype._onPersonaMouseMove = function (persona, ev) {
            if (!!persona.onMouseMove) {
                persona.onMouseMove(ev, persona);
            }
        };
        Facepile.prototype._onPersonaMouseOut = function (persona, ev) {
            if (!!persona.onMouseOut) {
                persona.onMouseOut(ev, persona);
            }
        };
        return Facepile;
    }(React.Component));
    Facepile.defaultProps = {
        maxDisplayablePersonas: 5,
        personas: [],
        personaSize: Persona_1.PersonaSize.extraSmall
    };
    exports.Facepile = Facepile;
});

//# sourceMappingURL=Facepile.js.map
