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 __());
    };
})();
define(["require", "exports", "react", "office-ui-fabric-react/lib/Button", "office-ui-fabric-react/lib/Fabric", "office-ui-fabric-react/lib/DetailsList"], function (require, exports, React, Button_1, Fabric_1, DetailsList_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var _columns = [
        {
            key: 'name',
            name: 'Name',
            fieldName: 'name',
            minWidth: 100,
            maxWidth: 200,
            isResizable: true
        },
        {
            key: 'color',
            name: 'Color',
            fieldName: 'color',
            minWidth: 100,
            maxWidth: 200
        }
    ];
    var _items = [
        {
            key: 'a',
            name: 'a',
            color: 'red'
        },
        {
            key: 'b',
            name: 'b',
            color: 'red'
        },
        {
            key: 'c',
            name: 'c',
            color: 'blue'
        },
        {
            key: 'd',
            name: 'd',
            color: 'blue'
        },
        {
            key: 'e',
            name: 'e',
            color: 'blue'
        }
    ];
    function groupBy(items, fieldName) {
        var groups = items.reduce(function (currentGroups, currentItem, index) {
            var lastGroup = currentGroups[currentGroups.length - 1];
            var fieldValue = currentItem[fieldName];
            if (!lastGroup || lastGroup.value !== fieldValue) {
                currentGroups.push({
                    key: 'group' + fieldValue + index,
                    name: "By \"" + fieldValue + "\"",
                    value: fieldValue,
                    startIndex: index,
                    level: 0,
                    count: 0
                });
            }
            if (lastGroup) {
                lastGroup.count = index - lastGroup.startIndex;
            }
            return currentGroups;
        }, []);
        // Fix last group count
        var lastGroup = groups[groups.length - 1];
        if (lastGroup) {
            lastGroup.count = items.length - lastGroup.startIndex;
        }
        return groups;
    }
    var DetailsListGroupedExample = (function (_super) {
        __extends(DetailsListGroupedExample, _super);
        function DetailsListGroupedExample() {
            var _this = _super.call(this) || this;
            _this.state = {
                items: _items
            };
            return _this;
        }
        DetailsListGroupedExample.prototype.render = function () {
            var _this = this;
            var items = this.state.items;
            return (React.createElement(Fabric_1.Fabric, { className: 'foo' },
                React.createElement(Button_1.DefaultButton, { onClick: function () { return _this._addItem(); }, text: 'Add an item' }),
                React.createElement(DetailsList_1.DetailsList, { items: items, groups: groupBy(items, 'color'), columns: _columns, ariaLabelForSelectAllCheckbox: 'Toggle selection for all items', ariaLabelForSelectionColumn: 'Toggle selection' })));
        };
        DetailsListGroupedExample.prototype._addItem = function () {
            var items = this.state.items;
            this.setState({
                items: items.concat([{
                        key: 'item-' + items.length,
                        name: 'New item ' + items.length,
                        color: 'blue'
                    }])
            });
        };
        return DetailsListGroupedExample;
    }(React.Component));
    exports.DetailsListGroupedExample = DetailsListGroupedExample;
});

//# sourceMappingURL=DetailsList.Grouped.Example.js.map
