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 __());
    };
})();
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { isFunction } from 'lodash';
import { Collapse } from 'react-bootstrap';
import { filterKeyCodes } from '../../utils/functions';
import { Block } from '../Block';
import { Icon } from '../Icon';
var AccordionItem = /** @class */ (function (_super) {
    __extends(AccordionItem, _super);
    function AccordionItem() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {
            isShown: _this.props.isExpanded
        };
        _this.handleClick = function () {
            var _a = _this.props, onToggle = _a.onToggle, name = _a.name;
            if (isFunction(onToggle)) {
                onToggle(name);
            }
        };
        _this.handleKeyDown = filterKeyCodes(_this.handleClick);
        return _this;
    }
    AccordionItem.getDerivedStateFromProps = function (props, state) {
        var isExpanded = props.isExpanded;
        var isShown = state.isShown;
        if (!isShown && isExpanded) {
            return { isShown: true };
        }
        return state;
    };
    AccordionItem.prototype.renderChildren = function () {
        var _a = this.props, lazy = _a.lazy, children = _a.children;
        var isShown = this.state.isShown;
        if (!isShown && lazy) {
            return null;
        }
        return children;
    };
    AccordionItem.prototype.render = function () {
        var _a = this.props, title = _a.title, isExpanded = _a.isExpanded, testAutomationId = _a.testAutomationId, subtitle = _a.subtitle;
        var arrow = isExpanded ? 'chevron-up-big' : 'chevron-down-big';
        var className = classnames('rc-accordion-item', {
            'rc-accordion-item-expanded': isExpanded
        });
        return (React.createElement("div", { className: className, "data-test-automation-id": testAutomationId },
            React.createElement("div", { className: "rc-accordion-item-header", onClick: this.handleClick, onKeyDown: this.handleKeyDown, tabIndex: 0, role: "button", "aria-expanded": isExpanded, "aria-label": title, "data-test-automation-id": "accordionItemHead" },
                React.createElement(Block, { addHorizontalOffset: true, cancelBottomOffset: true },
                    React.createElement(Block, { inline: true, className: "pull-left" },
                        React.createElement(Icon, { name: arrow })),
                    React.createElement("h3", { role: "presentation", "data-test-automation-id": "assignToggleText" },
                        title,
                        React.createElement("span", { className: "subtitle" }, subtitle)))),
            React.createElement(Collapse, { in: isExpanded, "data-test-automation-id": "accordionItemContent" },
                React.createElement("div", null, this.renderChildren()))));
    };
    AccordionItem.propTypes = {
        title: PropTypes.node.isRequired,
        subtitle: PropTypes.string,
        name: PropTypes.string,
        isExpanded: PropTypes.bool,
        onToggle: PropTypes.func,
        children: PropTypes.node,
        lazy: PropTypes.bool,
        testAutomationId: PropTypes.string
    };
    AccordionItem.defaultProps = {
        name: null,
        onToggle: null,
        isExpanded: false,
        children: null,
        lazy: false,
        testAutomationId: 'accordionItem',
        subtitle: ''
    };
    return AccordionItem;
}(PureComponent));
export { AccordionItem };
//# sourceMappingURL=AccordionItem.js.map