define(["require", "exports", "tslib", "react", "../../Utilities", "./Facepile.Props", "../../FocusZone", "../../Button", "../../Icon", "../../PersonaCoin", "./Facepile.scss"], function (require, exports, tslib_1, React, Utilities_1, Facepile_Props_1, FocusZone_1, Button_1, Icon_1, PersonaCoin_1, stylesImport) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var styles = stylesImport;
    var Facepile = /** @class */ (function (_super) {
        tslib_1.__extends(Facepile, _super);
        function Facepile(props) {
            var _this = _super.call(this, props) || this;
            _this._ariaDescriptionId = Utilities_1.getId();
            return _this;
        }
        Facepile.prototype.render = function () {
            var _this = this;
            var _a = this.props, chevronButtonProps = _a.chevronButtonProps, maxDisplayablePersonas = _a.maxDisplayablePersonas, overflowButtonProps = _a.overflowButtonProps, overflowButtonType = _a.overflowButtonType, className = _a.className, 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', styles.root, className) },
                React.createElement("div", { className: Utilities_1.css('ms-Facepile-itemContainer', styles.itemContainer) },
                    showAddButton ? this._getAddNewElement() : null,
                    this.onRenderAriaDescription(),
                    React.createElement(FocusZone_1.FocusZone, { ariaDescribedBy: this._ariaDescriptionId, role: 'listbox', className: Utilities_1.css('ms-Facepile-members', styles.members), 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)));
        };
        Facepile.prototype.onRenderAriaDescription = function () {
            var ariaDescription = this.props.ariaDescription;
            // If ariaDescription is given, descriptionId will be assigned to ariaDescriptionSpan,
            // otherwise it will be assigned to descriptionSpan.
            return ariaDescription && (React.createElement("span", { className: styles.screenReaderOnly, id: this._ariaDescriptionId }, ariaDescription));
        };
        Facepile.prototype._getPersonaControl = function (persona) {
            var _a = this.props, getPersonaProps = _a.getPersonaProps, personaSize = _a.personaSize;
            return (React.createElement(PersonaCoin_1.PersonaCoin, tslib_1.__assign({ imageInitials: persona.imageInitials, imageUrl: persona.imageUrl, initialsColor: persona.initialsColor, primaryText: persona.personaName, size: personaSize }, (getPersonaProps ? getPersonaProps(persona) : null))));
        };
        Facepile.prototype._getElementWithOnClickEvent = function (personaControl, persona, index) {
            return (React.createElement(Button_1.BaseButton, tslib_1.__assign({}, Utilities_1.getNativeProps(persona, Utilities_1.buttonProperties), { key: (!!persona.imageUrl ? 'i' : '') + index, "data-is-focusable": true, role: 'option', className: Utilities_1.css('ms-Facepile-itemButton ms-Facepile-person', styles.itemButton), title: persona.personaName, 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", tslib_1.__assign({}, Utilities_1.getNativeProps(persona, Utilities_1.divProperties), { key: (!!persona.imageUrl ? 'i' : '') + index, "data-is-focusable": true, role: 'option', className: Utilities_1.css('ms-Facepile-itemButton ms-Facepile-person', styles.itemButton), title: persona.personaName, 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 _a = this.props, overflowButtonProps = _a.overflowButtonProps, personas = _a.personas, personaSize = _a.personaSize;
            var numPersonasNotPictured = personas.length - numPersonasToShow;
            if (!overflowButtonProps || numPersonasNotPictured < 1) {
                return null;
            }
            var personaNames = personas.slice(numPersonasToShow).map(function (p) { return p.personaName; }).join(', ');
            return (React.createElement(Button_1.BaseButton, tslib_1.__assign({}, overflowButtonProps, { ariaDescription: personaNames, className: Utilities_1.css('ms-Facepile-descriptiveOverflowButton', 'ms-Facepile-itemButton', styles.descriptiveOverflowButton, styles.itemButton) }),
                React.createElement(PersonaCoin_1.PersonaCoin, { title: personaNames, size: personaSize, onRenderInitials: this._renderInitialsNotPictured(numPersonasNotPictured) })));
        };
        Facepile.prototype._getIconElement = function (icon) {
            var _a = this.props, overflowButtonProps = _a.overflowButtonProps, personaSize = _a.personaSize;
            return (React.createElement(Button_1.BaseButton, tslib_1.__assign({}, overflowButtonProps, { className: Utilities_1.css('ms-Facepile-overflowButton', 'ms-Facepile-itemButton', styles.overflowButton, styles.itemButton) }),
                React.createElement(PersonaCoin_1.PersonaCoin, { size: personaSize, onRenderInitials: this._renderInitials(icon) })));
        };
        Facepile.prototype._getAddNewElement = function () {
            var _a = this.props, addButtonProps = _a.addButtonProps, personaSize = _a.personaSize;
            return (React.createElement(Button_1.BaseButton, tslib_1.__assign({}, addButtonProps, { className: Utilities_1.css('ms-Facepile-addButton', 'ms-Facepile-itemButton', styles.itemButton, styles.addButton) }),
                React.createElement(PersonaCoin_1.PersonaCoin, { size: personaSize, onRenderInitials: this._renderInitials('AddFriend') })));
        };
        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);
            }
        };
        Facepile.prototype._renderInitials = function (iconName) {
            return function () {
                return (React.createElement(Icon_1.Icon, { iconName: iconName }));
            };
        };
        Facepile.prototype._renderInitialsNotPictured = function (numPersonasNotPictured) {
            return function () {
                return (React.createElement("span", null, '+' + numPersonasNotPictured));
            };
        };
        Facepile.defaultProps = {
            maxDisplayablePersonas: 5,
            personas: [],
            personaSize: PersonaCoin_1.PersonaSize.extraSmall
        };
        return Facepile;
    }(Utilities_1.BaseComponent));
    exports.Facepile = Facepile;
});
//# sourceMappingURL=Facepile.js.map