"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 __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importStar(require("react"));
var prop_types_1 = __importDefault(require("prop-types"));
var classnames_1 = __importDefault(require("classnames"));
var lodash_1 = require("lodash");
var react_bootstrap_1 = require("react-bootstrap");
var functions_1 = require("../../utils/functions");
var Block_1 = require("../Block");
var Icon_1 = require("../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 (lodash_1.isFunction(onToggle)) {
                onToggle(name);
            }
        };
        _this.handleKeyDown = functions_1.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_1.default('rc-accordion-item', {
            'rc-accordion-item-expanded': isExpanded
        });
        return (react_1.default.createElement("div", { className: className, "data-test-automation-id": testAutomationId },
            react_1.default.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_1.default.createElement(Block_1.Block, { addHorizontalOffset: true, cancelBottomOffset: true },
                    react_1.default.createElement(Block_1.Block, { inline: true, className: "pull-left" },
                        react_1.default.createElement(Icon_1.Icon, { name: arrow })),
                    react_1.default.createElement("h3", { role: "presentation", "data-test-automation-id": "assignToggleText" },
                        title,
                        react_1.default.createElement("span", { className: "subtitle" }, subtitle)))),
            react_1.default.createElement(react_bootstrap_1.Collapse, { in: isExpanded, "data-test-automation-id": "accordionItemContent" },
                react_1.default.createElement("div", null, this.renderChildren()))));
    };
    AccordionItem.propTypes = {
        title: prop_types_1.default.node.isRequired,
        subtitle: prop_types_1.default.string,
        name: prop_types_1.default.string,
        isExpanded: prop_types_1.default.bool,
        onToggle: prop_types_1.default.func,
        children: prop_types_1.default.node,
        lazy: prop_types_1.default.bool,
        testAutomationId: prop_types_1.default.string
    };
    AccordionItem.defaultProps = {
        name: null,
        onToggle: null,
        isExpanded: false,
        children: null,
        lazy: false,
        testAutomationId: 'accordionItem',
        subtitle: ''
    };
    return AccordionItem;
}(react_1.PureComponent));
exports.AccordionItem = AccordionItem;
//# sourceMappingURL=AccordionItem.js.map