"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        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;
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var Utilities_1 = require("../../Utilities");
var Facepile_Props_1 = require("./Facepile.Props");
var FocusZone_1 = require("../../FocusZone");
var Button_1 = require("../../Button");
var Persona_1 = require("../../Persona");
var stylesImport = require("./Facepile.scss");
var styles = stylesImport;
var Facepile = (function (_super) {
    __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, ariaDescription = _a.ariaDescription, 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(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), { 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", __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, __assign({}, overflowButtonProps, { ariaDescription: personaNames, className: Utilities_1.css('ms-Facepile-descriptiveOverflowButton', 'ms-Facepile-itemButton', styles.descriptiveOverflowButton, styles.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 _a = this.props, overflowButtonProps = _a.overflowButtonProps, personaSize = _a.personaSize;
        return React.createElement(Button_1.BaseButton, __assign({}, overflowButtonProps, { className: Utilities_1.css('ms-Facepile-overflowButton', 'ms-Facepile-itemButton', styles.overflowButton, styles.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 _a = this.props, addButtonProps = _a.addButtonProps, personaSize = _a.personaSize;
        return React.createElement(Button_1.BaseButton, __assign({}, addButtonProps, { className: Utilities_1.css('ms-Facepile-addButton', 'ms-Facepile-itemButton', styles.itemButton, styles.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;
}(Utilities_1.BaseComponent));
Facepile.defaultProps = {
    maxDisplayablePersonas: 5,
    personas: [],
    personaSize: Persona_1.PersonaSize.extraSmall
};
exports.Facepile = Facepile;

//# sourceMappingURL=Facepile.js.map
