"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 __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);
};
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 Popup_1 = require("./popups/Popup");
var Button_1 = require("./Button");
var Block_1 = require("./Block");
var WizardNavbar_1 = require("./WizardNavbar");
var utils_1 = require("../../utils");
var classnames_1 = __importDefault(require("classnames"));
var index_en_US_1 = __importDefault(require("../../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_1.default.createElement(Button_1.Button, { onClick: this.context.wizard.goBack, testAutomationId: "backButton", key: "backButton" }, utils_1.translate(this.props.backText)));
        }
        else {
            left = (react_1.default.createElement(Button_1.Button, { onClick: Popup_1.Popup.close, testAutomationId: "cancelButton", key: "cancelButton" }, utils_1.translate(this.props.cancelText)));
        }
        right = (react_1.default.createElement(Button_1.Button, { onClick: this.context.wizard.goNext, disabled: footerConfig.rightBtnDisabled, bsStyle: "primary", testAutomationId: "nextButton", key: "nextButton" }, utils_1.translate(this.props.nextText)));
        return [left, right];
    };
    WizardStep.prototype.getDefaultNavbar = function () {
        return react_1.default.createElement(WizardNavbar_1.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_1.default.createElement(Block_1.Block, null, title);
        return (react_1.default.createElement(Popup_1.Popup, { className: classnames_1.default(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: prop_types_1.default.object.isRequired
    };
    WizardStep.propTypes = {
        children: prop_types_1.default.node,
        id: prop_types_1.default.string.isRequired,
        title: prop_types_1.default.oneOfType([prop_types_1.default.string, prop_types_1.default.element]).isRequired,
        bsSize: prop_types_1.default.string,
        header: prop_types_1.default.node,
        footer: prop_types_1.default.node,
        backText: prop_types_1.default.string,
        cancelText: prop_types_1.default.string,
        nextText: prop_types_1.default.string,
        tabText: prop_types_1.default.string,
        footerConfig: prop_types_1.default.shape({ rightBtnDisabled: prop_types_1.default.bool }),
        validation: prop_types_1.default.func,
        noPadding: prop_types_1.default.bool,
        noBottomPadding: prop_types_1.default.bool,
        testAutomationId: prop_types_1.default.string,
        className: prop_types_1.default.string,
        noTitlePadding: prop_types_1.default.bool,
        skipNavbarItem: prop_types_1.default.bool,
        onStepLeave: prop_types_1.default.func,
        onClose: prop_types_1.default.func,
        closeButton: prop_types_1.default.bool
    };
    WizardStep.defaultProps = {
        children: null,
        bsSize: 'large',
        testAutomationId: 'wizardstep',
        header: null,
        footer: null,
        footerConfig: null,
        tabText: '',
        get backText() {
            return index_en_US_1.default.BACK;
        },
        get cancelText() {
            return index_en_US_1.default.CANCEL;
        },
        get nextText() {
            return index_en_US_1.default.NEXT;
        },
        className: null,
        noTitlePadding: false,
        skipNavbarItem: false,
        noPadding: false,
        noBottomPadding: false,
        validation: null,
        onStepLeave: null,
        onClose: null,
        closeButton: true
    };
    return WizardStep;
}(react_1.default.Component));
exports.WizardStep = WizardStep;
//# sourceMappingURL=WizardStep.js.map