'use strict';
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        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 extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importDefault(require("react"));
var prop_types_1 = __importDefault(require("prop-types"));
var Collapse_1 = __importDefault(require("react-bootstrap/lib/Collapse"));
var lodash_1 = __importDefault(require("lodash"));
var CollapsibleList = /** @class */ (function (_super) {
    __extends(CollapsibleList, _super);
    function CollapsibleList(props, context) {
        var _this = _super.call(this, props, context) || this;
        _this.state = {
            isCollapsed: true
        };
        return _this;
    }
    CollapsibleList.prototype.handleToggleClick = function () {
        this.setState({
            isCollapsed: !this.state.isCollapsed
        });
    };
    CollapsibleList.prototype.render = function () {
        var head = lodash_1.default.take(this.props.children, this.props.visibleItems);
        var tail = lodash_1.default.takeRight(this.props.children, this.props.children.length - this.props.visibleItems);
        var showToggle = tail.length > 0;
        var toggle;
        if (showToggle) {
            toggle = (react_1.default.createElement("span", { className: "toggle-list", onClick: this.handleToggleClick.bind(this) }, "..."));
        }
        return (react_1.default.createElement("div", { className: "collapsible-list", "data-test-automation-id": this.props.testAutomationId },
            react_1.default.createElement("div", { className: "head-wrapper" }, head),
            toggle,
            react_1.default.createElement(Collapse_1.default, { in: !this.state.isCollapsed },
                react_1.default.createElement("div", null, tail))));
    };
    CollapsibleList.propTypes = {
        testAutomationId: prop_types_1.default.string,
        visibleItems: prop_types_1.default.number,
        children: prop_types_1.default.node
    };
    CollapsibleList.defaultProps = {
        testAutomationId: 'collapsibleList',
        visibleItems: 1,
        children: null
    };
    return CollapsibleList;
}(react_1.default.Component));
exports.CollapsibleList = CollapsibleList;
//# sourceMappingURL=CollapsibleList.js.map