import _defineProperty from '@babel/runtime/helpers/defineProperty';
import 'core-js/modules/es.array.concat.js';
import React__default from 'react';
import PropTypes from 'prop-types';
import { InlineNotification } from '@carbon/react';
import classnames from 'classnames';
import { v4 } from 'uuid';
import { settings } from '../../../constants/Settings.js';
import { childrenPropType } from '../PageWizard.js';
import Button from '../../Button/Button.js';

var iotPrefix = settings.iotPrefix;
var PageWizardStepPropTypes = {
  /** Step identifier for controlling which step is active */
  id: PropTypes.string.isRequired,
  /** Optional callback function for validation */
  onValidate: PropTypes.func,
  /** Children nodes */
  children: childrenPropType,
  /** optional error to show for this step */
  error: PropTypes.node,
  /** optional callback to clear the error */
  onClearError: PropTypes.func,
  /** Internationalized strings */
  i18n: PropTypes.objectOf(PropTypes.string),
  /** Optional sticky footer */
  hasStickyFooter: PropTypes.bool,
  /** Callback function to close the wizard */
  onClose: PropTypes.func,
  /** Determines if Cancel or Previous button is rendered */
  hasPrev: PropTypes.bool,
  /** Determines if Next or Submit button is rendered */
  hasNext: PropTypes.bool,
  /** Callback function when Next button is clicked */
  onNext: PropTypes.func,
  /** Optionally determines if Next button is disabled */
  nextDisabled: PropTypes.bool,
  /** Callback function when Previous button is clicked */
  onBack: PropTypes.func,
  /** Renders a loading icon in the Next button */
  sendingData: PropTypes.bool,
  /** Callback function when Submit button is clicked */
  onSubmit: PropTypes.func,
  /** Content to render before footer buttons (on left side, in LTR) */
  beforeFooterContent: PropTypes.node,
  /** Content to render after footer buttons (on right side, in LTR) */
  afterFooterContent: PropTypes.node
};
var PageWizardStepDefaultProps = {
  children: [],
  error: null,
  onClearError: null,
  onValidate: function onValidate() {
    return true;
  },
  hasStickyFooter: false,
  nextDisabled: false,
  sendingData: false,
  i18n: {
    close: 'Close',
    cancel: 'Cancel',
    back: 'Back',
    next: 'Next',
    submit: 'Submit'
  },
  hasPrev: false,
  hasNext: false,
  onNext: null,
  onBack: null,
  beforeFooterContent: null,
  afterFooterContent: null,
  onSubmit: null,
  onClose: null
};
var PageWizardStep = function PageWizardStep(_ref) {
  var id = _ref.id,
    children = _ref.children,
    onValidate = _ref.onValidate,
    error = _ref.error,
    onClearError = _ref.onClearError,
    i18n = _ref.i18n,
    hasStickyFooter = _ref.hasStickyFooter,
    onClose = _ref.onClose,
    hasPrev = _ref.hasPrev,
    hasNext = _ref.hasNext,
    onNext = _ref.onNext,
    nextDisabled = _ref.nextDisabled,
    onBack = _ref.onBack,
    sendingData = _ref.sendingData,
    onSubmit = _ref.onSubmit,
    beforeFooterContent = _ref.beforeFooterContent,
    afterFooterContent = _ref.afterFooterContent;
  return /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(iotPrefix, "--page-wizard--step"),
    id: id
  }, error ? /*#__PURE__*/React__default.createElement(InlineNotification, {
    key: v4(),
    lowContrast: true,
    title: error,
    subtitle: "",
    kind: "error",
    onCloseButtonClick: onClearError,
    iconDescription: i18n.close,
    className: "".concat(iotPrefix, "--page-wizard--inline-notificaton")
  }) : null, children, /*#__PURE__*/React__default.createElement("div", {
    className: classnames(_defineProperty(_defineProperty(_defineProperty({}, "".concat(iotPrefix, "--page-wizard--content--actions--sticky"), hasStickyFooter), "".concat(iotPrefix, "--page-wizard--content--actions"), !hasStickyFooter), "".concat(iotPrefix, "--page-wizard--content--after-footer"), !!afterFooterContent))
  }, /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(iotPrefix, "--page-wizard--content--footer ").concat(iotPrefix, "--page-wizard--content--footer--before--content")
  }, beforeFooterContent), !hasPrev ? /*#__PURE__*/React__default.createElement(Button, {
    onClick: onClose,
    kind: "secondary"
  }, i18n.cancel) : /*#__PURE__*/React__default.createElement(Button, {
    onClick: onBack,
    kind: "secondary"
  }, i18n.back), hasNext ? /*#__PURE__*/React__default.createElement(Button, {
    onClick: function onClick() {
      if (onValidate()) {
        if (onNext) onNext();
      }
    },
    disabled: nextDisabled,
    loading: sendingData
  }, i18n.next) : /*#__PURE__*/React__default.createElement(Button, {
    onClick: function onClick() {
      return onValidate() && onSubmit();
    },
    disabled: nextDisabled,
    loading: sendingData
  }, i18n.submit), afterFooterContent && /*#__PURE__*/React__default.createElement("div", {
    className: "".concat(iotPrefix, "--page-wizard--content--footer ").concat(iotPrefix, "--page-wizard--content--footer--after--content")
  }, afterFooterContent)));
};
PageWizardStep.propTypes = PageWizardStepPropTypes;
PageWizardStep.defaultProps = PageWizardStepDefaultProps;
PageWizardStep.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "PageWizardStep",
  "props": {
    "children": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "Children nodes",
      "type": {
        "name": "custom",
        "raw": "childrenPropType"
      },
      "required": false
    },
    "error": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "optional error to show for this step",
      "type": {
        "name": "node"
      },
      "required": false
    },
    "onClearError": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "optional callback to clear the error",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "onValidate": {
      "defaultValue": {
        "value": "() => true",
        "computed": false
      },
      "description": "Optional callback function for validation",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "hasStickyFooter": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Optional sticky footer",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "nextDisabled": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Optionally determines if Next button is disabled",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "sendingData": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Renders a loading icon in the Next button",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "i18n": {
      "defaultValue": {
        "value": "{\n  close: 'Close',\n  cancel: 'Cancel',\n  back: 'Back',\n  next: 'Next',\n  submit: 'Submit',\n}",
        "computed": false
      },
      "description": "Internationalized strings",
      "type": {
        "name": "objectOf",
        "value": {
          "name": "string"
        }
      },
      "required": false
    },
    "hasPrev": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Determines if Cancel or Previous button is rendered",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "hasNext": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Determines if Next or Submit button is rendered",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "onNext": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Callback function when Next button is clicked",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "onBack": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Callback function when Previous button is clicked",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "beforeFooterContent": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Content to render before footer buttons (on left side, in LTR)",
      "type": {
        "name": "node"
      },
      "required": false
    },
    "afterFooterContent": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Content to render after footer buttons (on right side, in LTR)",
      "type": {
        "name": "node"
      },
      "required": false
    },
    "onSubmit": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Callback function when Submit button is clicked",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "onClose": {
      "defaultValue": {
        "value": "null",
        "computed": false
      },
      "description": "Callback function to close the wizard",
      "type": {
        "name": "func"
      },
      "required": false
    },
    "id": {
      "description": "Step identifier for controlling which step is active",
      "type": {
        "name": "string"
      },
      "required": true
    }
  }
};
var PageWizardStep$1 = PageWizardStep;

export { PageWizardStep$1 as default };
