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;
};
define(["require", "exports", "react", "../../../Utilities", "../../../Button", "../../../Spinner", "./Suggestions.scss"], function (require, exports, React, Utilities_1, Button_1, Spinner_1, stylesImport) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var styles = stylesImport;
    var SuggestionsItem = (function (_super) {
        __extends(SuggestionsItem, _super);
        function SuggestionsItem() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        SuggestionsItem.prototype.render = function () {
            var _a = this.props, suggestionModel = _a.suggestionModel, RenderSuggestion = _a.RenderSuggestion, onClick = _a.onClick, className = _a.className;
            return (React.createElement(Button_1.CommandButton, { onClick: onClick, className: Utilities_1.css('ms-Suggestions-item', styles.suggestionsItem, (_b = {},
                    _b['is-suggested ' + styles.suggestionsItemIsSuggested] = suggestionModel.selected,
                    _b), className) },
                React.createElement(RenderSuggestion, __assign({}, suggestionModel.item))));
            var _b;
        };
        return SuggestionsItem;
    }(Utilities_1.BaseComponent));
    exports.SuggestionsItem = SuggestionsItem;
    var Suggestions = (function (_super) {
        __extends(Suggestions, _super);
        function Suggestions(suggestionsProps) {
            var _this = _super.call(this, suggestionsProps) || this;
            _this.SuggestionsItemOfProperType = SuggestionsItem;
            _this._getMoreResults = _this._getMoreResults.bind(_this);
            return _this;
        }
        Suggestions.prototype.componentDidUpdate = function () {
            this.scrollSelected();
        };
        Suggestions.prototype.render = function () {
            var _a = this.props, suggestionsHeaderText = _a.suggestionsHeaderText, searchForMoreText = _a.searchForMoreText, className = _a.className, moreSuggestionsAvailable = _a.moreSuggestionsAvailable, noResultsFoundText = _a.noResultsFoundText, suggestions = _a.suggestions, isLoading = _a.isLoading, loadingText = _a.loadingText, onRenderNoResultFound = _a.onRenderNoResultFound;
            var noResults = function () {
                return noResultsFoundText ?
                    React.createElement("div", { className: Utilities_1.css('ms-Suggestions-none', styles.suggestionsNone) }, noResultsFoundText) : null;
            };
            return (React.createElement("div", { className: Utilities_1.css('ms-Suggestions', className ? className : '', styles.root) },
                suggestionsHeaderText ?
                    (React.createElement("div", { className: Utilities_1.css('ms-Suggestions-title', styles.suggestionsTitle) }, suggestionsHeaderText)) : (null),
                isLoading && (React.createElement(Spinner_1.Spinner, { className: Utilities_1.css('ms-Suggestions-spinner', styles.suggestionsSpinner), label: loadingText })),
                (!suggestions || !suggestions.length) && !isLoading ?
                    (onRenderNoResultFound ? onRenderNoResultFound(null, noResults) : noResults()) :
                    this._renderSuggestions(),
                searchForMoreText && moreSuggestionsAvailable && (React.createElement(Button_1.CommandButton, { componentRef: this._resolveRef('_searchForMoreButton'), className: Utilities_1.css('ms-SearchMore-button', styles.searchMoreButton), iconProps: { iconName: 'Search' }, onClick: this._getMoreResults.bind(this) }, searchForMoreText))));
        };
        Suggestions.prototype.focusSearchForMoreButton = function () {
            if (this._searchForMoreButton) {
                this._searchForMoreButton.focus();
            }
        };
        // TODO get the element to scroll into view properly regardless of direction.
        Suggestions.prototype.scrollSelected = function () {
            if (this._selectedElement) {
                this._selectedElement.scrollIntoView(false);
            }
        };
        Suggestions.prototype._renderSuggestions = function () {
            var _this = this;
            var _a = this.props, suggestions = _a.suggestions, onRenderSuggestion = _a.onRenderSuggestion, suggestionsItemClassName = _a.suggestionsItemClassName;
            var TypedSuggestionsItem = this.SuggestionsItemOfProperType;
            return (React.createElement("div", { className: Utilities_1.css('ms-Suggestions-container', styles.suggestionsContainer), id: 'suggestion-list', role: 'menu' }, suggestions.map(function (suggestion, index) {
                return React.createElement("div", { ref: _this._resolveRef(suggestion.selected ? '_selectedElement' : ''), key: index, id: 'sug-' + index, role: 'menuitem' },
                    React.createElement(TypedSuggestionsItem, { suggestionModel: suggestion, RenderSuggestion: onRenderSuggestion, onClick: function (ev) { return _this.props.onSuggestionClick(ev, suggestion.item, index); }, className: suggestionsItemClassName }));
            })));
        };
        Suggestions.prototype._getMoreResults = function () {
            if (this.props.onGetMoreResults) {
                this.props.onGetMoreResults();
            }
        };
        return Suggestions;
    }(Utilities_1.BaseComponent));
    exports.Suggestions = Suggestions;
});

//# sourceMappingURL=Suggestions.js.map
