define(["require", "exports", "tslib", "react", "office-ui-fabric-react/lib/Utilities", "../../../utilities/exampleData", "office-ui-fabric-react/lib/index", "../../DetailsList", "./Shimmer.Example.scss"], function (require, exports, tslib_1, React, Utilities_1, exampleData_1, index_1, DetailsList_1, ShimmerExampleStyles) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var fileIcons = [
        { name: 'accdb' },
        { name: 'csv' },
        { name: 'docx' },
        { name: 'dotx' },
        { name: 'mpp' },
        { name: 'mpt' },
        { name: 'odp' },
        { name: 'ods' },
        { name: 'odt' },
        { name: 'one' },
        { name: 'onepkg' },
        { name: 'onetoc' },
        { name: 'potx' },
        { name: 'ppsx' },
        { name: 'pptx' },
        { name: 'pub' },
        { name: 'vsdx' },
        { name: 'vssx' },
        { name: 'vstx' },
        { name: 'xls' },
        { name: 'xlsx' },
        { name: 'xltx' },
        { name: 'xsn' }
    ];
    var ITEMS_COUNT = 500;
    var INTERVAL_DELAY = 2500;
    // tslint:disable-next-line:no-any
    var _items;
    var ShimmerApplicationExample = /** @class */ (function (_super) {
        tslib_1.__extends(ShimmerApplicationExample, _super);
        function ShimmerApplicationExample(props) {
            var _this = _super.call(this, props) || this;
            _this._loadData = function () {
                _this._lastIntervalId = _this._async.setInterval(function () {
                    var randomQuantity = Math.floor(Math.random() * 10) + 1;
                    // tslint:disable-next-line:no-any
                    var itemsCopy = [].concat(_this.state.items);
                    itemsCopy.splice.apply(itemsCopy, [_this._lastIndexWithData, randomQuantity].concat(_items.slice(_this._lastIndexWithData, _this._lastIndexWithData + randomQuantity)));
                    _this._lastIndexWithData += randomQuantity;
                    _this.setState({
                        items: itemsCopy
                    });
                }, INTERVAL_DELAY);
            };
            _this._onLoadData = function (checked) {
                if (!_items) {
                    _items = exampleData_1.createListItems(ITEMS_COUNT);
                    _items.map(function (item) {
                        var randomFileType = _this._randomFileIcon();
                        item.thumbnail = randomFileType.url;
                    });
                }
                var items;
                var randomQuantity = Math.floor(Math.random() * 10) + 1;
                if (checked) {
                    items = _items.slice(0, randomQuantity).concat(new Array(ITEMS_COUNT - randomQuantity));
                    _this._lastIndexWithData = randomQuantity;
                    _this._loadData();
                }
                else {
                    items = new Array();
                    _this._async.clearInterval(_this._lastIntervalId);
                }
                _this.setState({
                    isDataLoaded: checked,
                    items: items
                });
            };
            _this._onChangeModalSelection = function (checked) {
                _this.setState({ isModalSelection: checked });
            };
            _this._onChangeCompactMode = function (checked) {
                _this.setState({ isCompactMode: checked });
            };
            _this._onRenderItemColumn = function (item, index, column) {
                if (column.key === 'thumbnail') {
                    return React.createElement("img", { src: item.thumbnail });
                }
                return item[column.key];
            };
            _this.state = {
                items: new Array(),
                columns: _buildColumns(),
                isDataLoaded: false,
                isModalSelection: false,
                isCompactMode: false
            };
            return _this;
        }
        ShimmerApplicationExample.prototype.componentWillUnmount = function () {
            this._async.dispose();
        };
        ShimmerApplicationExample.prototype.render = function () {
            var _a = this.state, items = _a.items, columns = _a.columns, isDataLoaded = _a.isDataLoaded, isModalSelection = _a.isModalSelection, isCompactMode = _a.isCompactMode;
            return (React.createElement("div", null,
                React.createElement("div", { className: ShimmerExampleStyles.shimmerExampleFlexGroup },
                    React.createElement(index_1.Toggle, { label: "Enable Modal Selection", checked: isModalSelection, onChanged: this._onChangeModalSelection, onText: "Modal", offText: "Normal" }),
                    React.createElement(index_1.Toggle, { label: "Enable Compact Mode", checked: isCompactMode, onChanged: this._onChangeCompactMode, onText: "Compact", offText: "Normal" }),
                    React.createElement(index_1.Toggle, { label: "Enable content loading", checked: isDataLoaded, onChanged: this._onLoadData, onText: "Content", offText: "Shimmer" })),
                React.createElement("div", null,
                    React.createElement(DetailsList_1.ShimmeredDetailsList, { setKey: "items", items: items, columns: columns, compact: isCompactMode, selectionMode: this.state.isModalSelection ? index_1.SelectionMode.multiple : index_1.SelectionMode.none, onRenderItemColumn: this._onRenderItemColumn, enableShimmer: !isDataLoaded, listProps: { renderedWindowsAhead: 0, renderedWindowsBehind: 0 } }))));
        };
        ShimmerApplicationExample.prototype._randomFileIcon = function () {
            var docType = fileIcons[Math.floor(Math.random() * fileIcons.length) + 0].name;
            return {
                docType: docType,
                url: "https://static2.sharepointonline.com/files/fabric/assets/brand-icons/document/svg/" + docType + "_16x1.svg"
            };
        };
        return ShimmerApplicationExample;
    }(Utilities_1.BaseComponent));
    exports.ShimmerApplicationExample = ShimmerApplicationExample;
    function _buildColumns() {
        var _item = exampleData_1.createListItems(1);
        var columns = index_1.buildColumns(_item);
        columns.forEach(function (column) {
            if (column.key === 'thumbnail') {
                column.name = 'FileType';
                column.minWidth = 16;
                column.maxWidth = 16;
                column.isIconOnly = true;
                column.iconName = 'Page';
            }
        });
        return columns;
    }
});
//# sourceMappingURL=Shimmer.Application.Example.js.map