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 __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import React from 'react';
import PropTypes from 'prop-types';
import { Popup } from './popups/Popup';
import { Button } from './Button';
import { Block } from './Block';
import { WizardNavbar } from './WizardNavbar';
import { translate } from '../../utils';
import classnames from 'classnames';
import lang from '../../lang/common/index-en_US';
var WizardStep = /** @class */ (function (_super) {
    __extends(WizardStep, _super);
    function WizardStep(props, context) {
        var _this = _super.call(this, props, context) || this;
        _this.context.wizard.addStepOnLeaveHandler(_this.props.id, _this.onStepLeave.bind(_this));
        return _this;
    }
    WizardStep.prototype.getDefaultButtons = function (footerConfig) {
        if (footerConfig === void 0) { footerConfig = {}; }
        var left;
        var right;
        footerConfig = __assign({}, this.props.footerConfig, footerConfig);
        if (!this.context.wizard.isFirstStep(this.props.id)) {
            left = (React.createElement(Button, { onClick: this.context.wizard.goBack, testAutomationId: "backButton", key: "backButton" }, translate(this.props.backText)));
        }
        else {
            left = (React.createElement(Button, { onClick: Popup.close, testAutomationId: "cancelButton", key: "cancelButton" }, translate(this.props.cancelText)));
        }
        right = (React.createElement(Button, { onClick: this.context.wizard.goNext, disabled: footerConfig.rightBtnDisabled, bsStyle: "primary", testAutomationId: "nextButton", key: "nextButton" }, translate(this.props.nextText)));
        return [left, right];
    };
    WizardStep.prototype.getDefaultNavbar = function () {
        return React.createElement(WizardNavbar, null);
    };
    WizardStep.prototype.getFooter = function () {
        return this.props.footer || this.getDefaultButtons();
    };
    WizardStep.prototype.getHeader = function () {
        return this.props.header || this.getDefaultNavbar();
    };
    /**
     * @abstract
     * @returns {Promise.<T>}
     */
    WizardStep.prototype.onStepLeave = function () {
        return (this.props.onStepLeave && this.props.onStepLeave()) || Promise.resolve();
    };
    WizardStep.prototype.isAnimated = function () {
        return this.context.wizard.getMaxVisitedStepIndex() === 0;
    };
    WizardStep.prototype.render = function () {
        var _a = this.props, noTitlePadding = _a.noTitlePadding, title = _a.title;
        var popupTitle = noTitlePadding ? title : React.createElement(Block, null, title);
        return (React.createElement(Popup, { className: classnames(this.props.className), animation: this.isAnimated(), noPadding: this.props.noPadding, noBottomPadding: this.props.noBottomPadding, onClose: this.props.onClose, closeButton: this.props.closeButton, bsSize: this.props.bsSize, title: popupTitle, header: this.getHeader(), testAutomationId: this.props.testAutomationId, footer: this.getFooter() }, this.props.children));
    };
    WizardStep.contextTypes = {
        wizard: PropTypes.object.isRequired
    };
    WizardStep.propTypes = {
        children: PropTypes.node,
        id: PropTypes.string.isRequired,
        title: PropTypes.oneOfType([PropTypes.string, PropTypes.element]).isRequired,
        bsSize: PropTypes.string,
        header: PropTypes.node,
        footer: PropTypes.node,
        backText: PropTypes.string,
        cancelText: PropTypes.string,
        nextText: PropTypes.string,
        tabText: PropTypes.string,
        footerConfig: PropTypes.shape({ rightBtnDisabled: PropTypes.bool }),
        validation: PropTypes.func,
        noPadding: PropTypes.bool,
        noBottomPadding: PropTypes.bool,
        testAutomationId: PropTypes.string,
        className: PropTypes.string,
        noTitlePadding: PropTypes.bool,
        skipNavbarItem: PropTypes.bool,
        onStepLeave: PropTypes.func,
        onClose: PropTypes.func,
        closeButton: PropTypes.bool
    };
    WizardStep.defaultProps = {
        children: null,
        bsSize: 'large',
        testAutomationId: 'wizardstep',
        header: null,
        footer: null,
        footerConfig: null,
        tabText: '',
        get backText() {
            return lang.BACK;
        },
        get cancelText() {
            return lang.CANCEL;
        },
        get nextText() {
            return lang.NEXT;
        },
        className: null,
        noTitlePadding: false,
        skipNavbarItem: false,
        noPadding: false,
        noBottomPadding: false,
        validation: null,
        onStepLeave: null,
        onClose: null,
        closeButton: true
    };
    return WizardStep;
}(React.Component));
export { WizardStep };
//# sourceMappingURL=WizardStep.js.map