define(["require", "exports", "tslib", "react", "@fluentui/react/lib/Button", "@fluentui/example-data", "@fluentui/react-experiments/lib/SelectedItemsList"], function (require, exports, tslib_1, React, Button_1, example_data_1, SelectedItemsList_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.SelectedPeopleListWithContextMenuExample = void 0;
    var SelectedPeopleListWithContextMenuExample = /** @class */ (function (_super) {
        tslib_1.__extends(SelectedPeopleListWithContextMenuExample, _super);
        function SelectedPeopleListWithContextMenuExample(props) {
            var _this = _super.call(this, props) || this;
            /**
             * Build a custom selected item capable of being edited with a dropdown and
             * capable of editing
             */
            _this.SelectedItem = SelectedItemsList_1.ItemWithContextMenu({
                menuItems: function (item) { return [
                    {
                        key: 'remove',
                        text: 'Remove',
                        onClick: function () {
                            _this._onItemsRemoved([item]);
                        },
                    },
                    {
                        key: 'copy',
                        text: 'Copy',
                        onClick: function () {
                            _this._copyToClipboard(_this._getCopyItemsText([item]));
                        },
                    },
                ]; },
                itemComponent: SelectedItemsList_1.TriggerOnContextMenu(SelectedItemsList_1.SelectedPersona),
            });
            _this._onAddItemButtonClicked = function () {
                var randomPerson = example_data_1.people[Math.floor(Math.random() * (example_data_1.people.length - 1))];
                _this.setState({ currentSelectedItems: tslib_1.__spreadArrays(_this.state.currentSelectedItems, [randomPerson]) });
            };
            _this._onItemsRemoved = function (items) {
                var currentSelectedItemsCopy = tslib_1.__spreadArrays(_this.state.currentSelectedItems);
                items.forEach(function (item) {
                    var indexToRemove = currentSelectedItemsCopy.indexOf(item);
                    currentSelectedItemsCopy.splice(indexToRemove, 1);
                    _this.setState({ currentSelectedItems: tslib_1.__spreadArrays(currentSelectedItemsCopy) });
                });
            };
            _this._copyToClipboard = function (copyString) {
                navigator.clipboard.writeText(copyString).then(function () {
                    /* clipboard successfully set */
                }, function () {
                    /* clipboard write failed */
                    throw new Error();
                });
            };
            _this.state = {
                currentSelectedItems: [example_data_1.people[40]],
            };
            return _this;
        }
        SelectedPeopleListWithContextMenuExample.prototype.render = function () {
            return (React.createElement("div", { className: 'ms-BasePicker-text' },
                "Right click any persona to open the context menu",
                React.createElement("br", null),
                React.createElement(Button_1.PrimaryButton, { text: "Add another item", onClick: this._onAddItemButtonClicked }),
                this._renderExtendedPicker()));
        };
        SelectedPeopleListWithContextMenuExample.prototype._renderExtendedPicker = function () {
            return (React.createElement("div", null,
                React.createElement(SelectedItemsList_1.SelectedPeopleList, { key: 'normal', removeButtonAriaLabel: 'Remove', selectedItems: tslib_1.__spreadArrays(this.state.currentSelectedItems), onRenderItem: this.SelectedItem, onItemsRemoved: this._onItemsRemoved })));
        };
        SelectedPeopleListWithContextMenuExample.prototype._getCopyItemsText = function (items) {
            var copyText = '';
            items.forEach(function (item, index) {
                copyText += item.text;
                if (index < items.length - 1) {
                    copyText += ', ';
                }
            });
            return copyText;
        };
        return SelectedPeopleListWithContextMenuExample;
    }(React.Component));
    exports.SelectedPeopleListWithContextMenuExample = SelectedPeopleListWithContextMenuExample;
});
//# sourceMappingURL=SelectedPeopleList.WithContextMenu.Example.js.map