import { __assign, __awaiter, __extends, __generator, __spreadArrays } from "tslib";
import * as React from 'react';
import { PrimaryButton } from '@fluentui/react/lib/Button';
import { people, groupOne, groupTwo } from '@fluentui/example-data';
import { SelectedPeopleList, SelectedPersona, } from '@fluentui/react-experiments/lib/SelectedItemsList';
var SelectedPeopleListWithGroupExpandExample = /** @class */ (function (_super) {
    __extends(SelectedPeopleListWithGroupExpandExample, _super);
    function SelectedPeopleListWithGroupExpandExample(props) {
        var _this = _super.call(this, props) || this;
        /**
         * Build a custom selected item capable of being edited with a dropdown and
         * capable of eidting
         */
        // eslint-disable-next-line @typescript-eslint/naming-convention
        _this.SelectedItem = function (props) { return (React.createElement(SelectedPersona, __assign({ canExpand: _this._canExpandItem, getExpandedItems: _this._getExpandedGroupItems }, props))); };
        _this._onAddItemButtonClicked = function () {
            var randomPerson = people[Math.floor(Math.random() * (people.length - 1))];
            _this.setState({ currentSelectedItems: __spreadArrays(_this.state.currentSelectedItems, [randomPerson]) });
        };
        _this._onItemsRemoved = function (items) {
            var currentSelectedItemsCopy = __spreadArrays(_this.state.currentSelectedItems);
            items.forEach(function (item) {
                var indexToRemove = currentSelectedItemsCopy.indexOf(item);
                currentSelectedItemsCopy.splice(indexToRemove, 1);
                _this.setState({ currentSelectedItems: __spreadArrays(currentSelectedItemsCopy) });
            });
        };
        _this.state = {
            currentSelectedItems: [people[40]],
        };
        return _this;
    }
    SelectedPeopleListWithGroupExpandExample.prototype.render = function () {
        return (React.createElement("div", { className: 'ms-BasePicker-text' },
            "Click the '+' icon to the left of the group to expand it into a number of personas",
            React.createElement("br", null),
            React.createElement(PrimaryButton, { text: "Add another item", onClick: this._onAddItemButtonClicked }),
            this._renderExtendedPicker()));
    };
    SelectedPeopleListWithGroupExpandExample.prototype._renderExtendedPicker = function () {
        return (React.createElement("div", null,
            React.createElement(SelectedPeopleList, { key: 'normal', removeButtonAriaLabel: 'Remove', selectedItems: __spreadArrays(this.state.currentSelectedItems), onRenderItem: this.SelectedItem, onItemsRemoved: this._onItemsRemoved })));
    };
    SelectedPeopleListWithGroupExpandExample.prototype._getExpandedGroupItems = function (item) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (item.text) {
                    case 'Group One':
                        return [2 /*return*/, groupOne];
                    case 'Group Two':
                        return [2 /*return*/, groupTwo];
                    default:
                        return [2 /*return*/, []];
                }
                return [2 /*return*/];
            });
        });
    };
    SelectedPeopleListWithGroupExpandExample.prototype._canExpandItem = function (item) {
        return item.text !== undefined && item.text.indexOf('Group') !== -1;
    };
    return SelectedPeopleListWithGroupExpandExample;
}(React.Component));
export { SelectedPeopleListWithGroupExpandExample };
//# sourceMappingURL=SelectedPeopleList.WithGroupExpand.Example.js.map