import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
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';
export var WizardStep =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(WizardStep, _React$Component);

  function WizardStep(props, context) {
    var _this;

    _this = _React$Component.call(this, props, context) || this;

    _this.context.wizard.addStepOnLeaveHandler(_this.props.id, _this.onStepLeave.bind(_assertThisInitialized(_this)));

    return _this;
  }

  var _proto = WizardStep.prototype;

  _proto.getDefaultButtons = function getDefaultButtons(footerConfig) {
    if (footerConfig === void 0) {
      footerConfig = {};
    }

    var left;
    var right;
    footerConfig = Object.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];
  };

  _proto.getDefaultNavbar = function getDefaultNavbar() {
    return React.createElement(WizardNavbar, null);
  };

  _proto.getFooter = function getFooter() {
    return this.props.footer || this.getDefaultButtons();
  };

  _proto.getHeader = function getHeader() {
    return this.props.header || this.getDefaultNavbar();
  }
  /**
   * @abstract
   * @returns {Promise.<T>}
   */
  ;

  _proto.onStepLeave = function onStepLeave() {
    return this.props.onStepLeave && this.props.onStepLeave() || Promise.resolve();
  };

  _proto.isAnimated = function isAnimated() {
    return this.context.wizard.getMaxVisitedStepIndex() === 0;
  };

  _proto.render = function render() {
    var _this$props = this.props,
        noTitlePadding = _this$props.noTitlePadding,
        title = _this$props.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);
  };

  return WizardStep;
}(React.Component);

_defineProperty(WizardStep, "contextTypes", {
  wizard: PropTypes.object.isRequired
});

_defineProperty(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
});

_defineProperty(WizardStep, "defaultProps", {
  children: null,
  bsSize: 'large',
  testAutomationId: 'wizardstep',
  header: null,
  footer: null,
  footerConfig: null,
  tabText: '',
  backText: 'TRANSLATE:BACK',
  cancelText: 'TRANSLATE:CANCEL',
  nextText: 'TRANSLATE:NEXT',
  className: null,
  noTitlePadding: false,
  skipNavbarItem: false,
  noPadding: false,
  noBottomPadding: false,
  validation: null,
  onStepLeave: null,
  onClose: null,
  closeButton: true
});