"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var CommandBar_1 = require("office-ui-fabric-react/lib-commonjs/CommandBar");
var ContextualMenu_1 = require("office-ui-fabric-react/lib-commonjs/ContextualMenu");
exports.CommandBarLazyExample = function () {
    var _a = React.useState(undefined), menuItems = _a[0], setMenuItems = _a[1];
    var timeoutRef = React.useRef();
    var items = React.useMemo(function () {
        var loadItems = function () {
            var itemCount = Math.floor(Math.random() * 5) + 1;
            var newMenuItems = [];
            for (var i = 0; i < itemCount; i++) {
                newMenuItems.push({
                    key: "sub-item-" + i,
                    name: "Item " + i,
                });
            }
            if (timeoutRef.current) {
                clearTimeout(timeoutRef.current);
            }
            timeoutRef.current = setTimeout(function () {
                setMenuItems(newMenuItems);
            }, 2000);
        };
        return [
            {
                key: 'a',
                name: 'Test',
            },
            {
                key: 'menu',
                name: 'Lazy-loaded menu',
                subMenuProps: {
                    items: menuItems
                        ? tslib_1.__spreadArrays(menuItems, [
                            {
                                key: 'divider',
                                name: '-',
                                itemType: ContextualMenu_1.ContextualMenuItemType.Divider,
                            },
                            {
                                key: 'permanent',
                                name: 'Permanent option',
                            },
                        ]) : [],
                    onMenuOpened: loadItems,
                    onMenuDismissed: function () { return setMenuItems(undefined); },
                },
            },
        ];
    }, [menuItems]);
    return (React.createElement("div", null,
        React.createElement(CommandBar_1.CommandBar, { items: items })));
};
//# sourceMappingURL=CommandBar.Lazy.Example.js.map