"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.STATUS_WARNING = exports.STATUS_RUNNING = exports.STATUS_NOT_STARTED = exports.STATUS_ERROR = exports.STATUS_DONE = exports.STATUS_CANCELED = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _classnames = _interopRequireDefault(require("classnames"));

var _Icon = _interopRequireWildcard(require("../Icon"));

var _Status = _interopRequireDefault(require("../Status"));

var _constants = require("../../constants");

var _ProgressBar = _interopRequireDefault(require("../ProgressBar"));

var _OnDarkContext = _interopRequireDefault(require("../OnDarkContext"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

// Copyright 1999-2021. Plesk International GmbH. All rights reserved.
const STATUS_NOT_STARTED = 'not_started';
exports.STATUS_NOT_STARTED = STATUS_NOT_STARTED;
const STATUS_RUNNING = 'running';
exports.STATUS_RUNNING = STATUS_RUNNING;
const STATUS_DONE = 'done';
exports.STATUS_DONE = STATUS_DONE;
const STATUS_WARNING = 'warning';
exports.STATUS_WARNING = STATUS_WARNING;
const STATUS_ERROR = 'error';
exports.STATUS_ERROR = STATUS_ERROR;
const STATUS_CANCELED = 'canceled';
/**
 * `ProgressStep` is a part of the [Progress](#!/Progress) component.
 * @since 1.10.0
 */

exports.STATUS_CANCELED = STATUS_CANCELED;

const ProgressStep = ({
  baseClassName,
  className,
  children,
  icon,
  title,
  progress,
  status,
  statusText,
  ...props
}) => {
  let intent = null;

  switch (status) {
    case STATUS_NOT_STARTED:
      intent = 'inactive';
      icon = 'dot';
      break;

    case STATUS_RUNNING:
      intent = false;
      icon = 'dot';
      break;

    case STATUS_DONE:
      intent = 'success';
      icon = 'check-mark-circle-filled';
      break;

    case STATUS_WARNING:
      intent = 'warning';
      icon = 'triangle-exclamation-mark-filled';
      break;

    case STATUS_ERROR:
      intent = 'danger';
      icon = 'exclamation-mark-circle-filled';
      break;

    case STATUS_CANCELED:
      progress = 0;
      intent = 'inactive';
      icon = 'cross-mark-circle-filled';
      break;
  }

  icon = _Icon.default.create(icon, {
    className: `${baseClassName}__icon`,
    size: _Icon.ICON_SIZE_16,
    intent
  });

  if (statusText && (! /*#__PURE__*/(0, _react.isValidElement)(statusText) || statusText.type !== _Status.default)) {
    statusText = /*#__PURE__*/_react.default.createElement(_Status.default, null, statusText);
  }

  return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
    className: (0, _classnames.default)(baseClassName, {
      [`${baseClassName}--${intent}`]: intent,
      [`${baseClassName}--content`]: _react.Children.toArray(children).length,
      [`${baseClassName}--on-dark`]: (0, _react.useContext)(_OnDarkContext.default)
    }, className)
  }, props), icon && /*#__PURE__*/_react.default.createElement("div", {
    className: `${baseClassName}__media`
  }, icon), /*#__PURE__*/_react.default.createElement("div", {
    className: `${baseClassName}__body`
  }, (title || statusText || _react.Children.toArray(children).length > 0) && /*#__PURE__*/_react.default.createElement("div", {
    className: `${baseClassName}__labels`
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: `${baseClassName}__labels-body`
  }, title && /*#__PURE__*/_react.default.createElement("div", {
    className: `${baseClassName}__title`
  }, title), _react.Children.toArray(children).length ? /*#__PURE__*/_react.default.createElement("div", {
    className: `${baseClassName}__content`
  }, children) : null), statusText && /*#__PURE__*/_react.default.createElement("div", {
    className: `${baseClassName}__status`
  }, statusText)), STATUS_RUNNING === status && /*#__PURE__*/_react.default.createElement(_ProgressBar.default, {
    className: `${baseClassName}__progress`,
    intent: "info",
    progress: progress
  })));
};

ProgressStep.propTypes = {
  /**
   * Title of the step
   * @since 1.10.0
   */
  title: _propTypes.default.node,

  /**
   * Status for the step
   * @since 1.10.0
   */
  status: _propTypes.default.oneOf([STATUS_NOT_STARTED, STATUS_RUNNING, STATUS_DONE, STATUS_WARNING, STATUS_ERROR, STATUS_CANCELED]),

  /**
   * Text description for the status of the step
   * @since 1.10.0
   */
  statusText: _propTypes.default.node,

  /**
   * Progress indication in numbers
   * @since 1.10.0
   */
  progress: _propTypes.default.number,

  /**
   * Content of the `ProgressStep`.
   * @since 1.10.0
   */
  children: _propTypes.default.node,

  /**
   * Name of icon or [Icon](#!/Icon) component
   * @ignore
   */
  icon: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.object, _propTypes.default.element]),

  /**
   * @ignore
   */
  className: _propTypes.default.string,

  /**
   * @ignore
   */
  baseClassName: _propTypes.default.string
};
ProgressStep.defaultProps = {
  icon: null,
  title: null,
  status: STATUS_NOT_STARTED,
  statusText: null,
  progress: -1,
  children: null,
  className: null,
  baseClassName: `${_constants.CLS_PREFIX}progress-step`
};
var _default = ProgressStep;
exports.default = _default;