"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
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 = __importStar(require("react"));
var styled_components_1 = __importDefault(require("styled-components"));
var styleConstants_1 = require("./styleConstants");
exports.CollapseArea = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  height: ", ";\n  transition: height 1s;\n  overflow: ", ";\n"], ["\n  height: ", ";\n  transition: height 1s;\n  overflow: ", ";\n"])), function (props) { return (props.open ? "" + (props.height ? props.height + "px" : "auto") : "0px"); }, function (props) { return (props.open ? "visible" : "hidden"); });
exports.Arrow = styled_components_1.default.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n  width: 8px;\n  height: 8px;\n  border-left: 3px solid ", ";\n  border-bottom: 3px solid ", ";\n  transform: ", ";\n  transition: transform 1s;\n  position: absolute;\n  right: 0;\n  top: 10px;\n"], ["\n  width: 8px;\n  height: 8px;\n  border-left: 3px solid ", ";\n  border-bottom: 3px solid ", ";\n  transform: ", ";\n  transition: transform 1s;\n  position: absolute;\n  right: 0;\n  top: 10px;\n"])), function (props) { return (props.disabled ? styleConstants_1.colors.accent.CIVIL_GRAY_3 : styleConstants_1.colors.primary.CIVIL_GRAY_1); }, function (props) { return (props.disabled ? styleConstants_1.colors.accent.CIVIL_GRAY_3 : styleConstants_1.colors.primary.CIVIL_GRAY_1); }, function (props) { return (props.open ? "rotate(135deg)" : "rotate(-45deg)"); });
exports.HeaderWrapper = styled_components_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n  position: relative;\n  cursor: pointer;\n"], ["\n  position: relative;\n  cursor: pointer;\n"])));
var Collapsable = /** @class */ (function (_super) {
    __extends(Collapsable, _super);
    function Collapsable(props) {
        var _this = _super.call(this, props) || this;
        _this.open = function () {
            if (!_this.props.disabled) {
                if (_this.state.open) {
                    _this.setState({ height: _this.collapseArea.clientHeight });
                }
                setImmediate(function () {
                    _this.setState({ open: !_this.state.open });
                });
            }
        };
        _this.state = {
            open: props.open,
            height: null,
        };
        _this.collapseArea = null;
        return _this;
    }
    Collapsable.prototype.componentDidMount = function () {
        var _this = this;
        if (this.collapseArea) {
            this.collapseArea.addEventListener("transitionend", function () {
                if (_this.state.open) {
                    _this.setState({ height: null });
                }
            });
        }
    };
    Collapsable.prototype.componentWillReceiveProps = function (nextProps) {
        if (nextProps.open !== this.props.open) {
            this.setState({ open: nextProps.open });
        }
    };
    Collapsable.prototype.render = function () {
        var _this = this;
        var header = this.props.header;
        if (this.state.open && this.props.headerOpen) {
            header = this.props.headerOpen;
        }
        return (React.createElement("div", { className: this.props.className },
            React.createElement(exports.HeaderWrapper, { onClick: this.open },
                header,
                " ",
                this.props.ArrowComponent ? (React.createElement(this.props.ArrowComponent, { disabled: this.props.disabled, open: this.state.open })) : (React.createElement(exports.Arrow, { disabled: this.props.disabled, open: this.state.open }))),
            React.createElement(exports.CollapseArea, { ref: function (el) { return (_this.collapseArea = el); }, height: this.state.height, open: this.state.open }, this.props.children)));
    };
    return Collapsable;
}(React.Component));
exports.Collapsable = Collapsable;
var templateObject_1, templateObject_2, templateObject_3;
//# sourceMappingURL=Collapsable.js.map