"use strict";
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 React = require('react');
var index_1 = require('../../../../index');
var data_1 = require('./data');
var CommandBarRandomItemsExample = (function (_super) {
    __extends(CommandBarRandomItemsExample, _super);
    function CommandBarRandomItemsExample() {
        _super.call(this);
        this.state = {
            items: data_1.items,
            farItems: data_1.farItems
        };
    }
    ;
    CommandBarRandomItemsExample.prototype.componentDidMount = function () {
        this._changeTimerId = window.setInterval(this._updateItems.bind(this), 5000);
    };
    CommandBarRandomItemsExample.prototype.componentWillUnmount = function () {
        if (this._changeTimerId) {
            window.clearInterval(this._changeTimerId);
        }
    };
    CommandBarRandomItemsExample.prototype.render = function () {
        return (React.createElement("div", {className: 'ms-ChangedItemsCommandBarExample'}, React.createElement(index_1.CommandBar, {items: this.state.items, farItems: this.state.farItems})));
    };
    CommandBarRandomItemsExample.prototype._updateItems = function () {
        this.setState({
            items: _getRandomizedArray(data_1.items, 2),
            farItems: _getRandomizedArray(data_1.farItems, 1)
        });
    };
    return CommandBarRandomItemsExample;
}(React.Component));
exports.CommandBarRandomItemsExample = CommandBarRandomItemsExample;
function _getRandomizedArray(array, min) {
    var count = min + Math.round(Math.random() * (array.length - min));
    var itemsLeft = [].concat(array);
    var newArray = [];
    for (var i = 0; i < count; i++) {
        newArray = newArray.concat(itemsLeft.splice(Math.floor(Math.random() * itemsLeft.length), 1));
    }
    return newArray;
}

//# sourceMappingURL=CommandBar.RandomItems.Example.js.map
