"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 _react = require("react");
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"));
var _jsxRuntime = require("react/jsx-runtime");
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-2023. Plesk International GmbH. All rights reserved.

const STATUS_NOT_STARTED = exports.STATUS_NOT_STARTED = 'not_started';
const STATUS_RUNNING = exports.STATUS_RUNNING = 'running';
const STATUS_DONE = exports.STATUS_DONE = 'done';
const STATUS_WARNING = exports.STATUS_WARNING = 'warning';
const STATUS_ERROR = exports.STATUS_ERROR = 'error';
const STATUS_CANCELED = exports.STATUS_CANCELED = 'canceled';
/**
 * `ProgressStep` is a part of the [Progress](#!/Progress) component.
 * @since 1.10.0
 */
const ProgressStep = _ref => {
  let {
    className,
    children,
    icon,
    title,
    statusText,
    progress,
    status,
    baseClassName,
    ...props
  } = _ref;
  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__*/(0, _jsxRuntime.jsx)(_Status.default, {
      children: statusText
    });
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    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,
    children: [icon && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: `${baseClassName}__media`,
      children: icon
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: `${baseClassName}__body`,
      children: [(title || statusText || _react.Children.toArray(children).length > 0) && /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
        className: `${baseClassName}__labels`,
        children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
          className: `${baseClassName}__labels-body`,
          children: [title && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
            className: `${baseClassName}__title`,
            children: title
          }), _react.Children.toArray(children).length ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
            className: `${baseClassName}__content`,
            children: children
          }) : null]
        }), statusText && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: `${baseClassName}__status`,
          children: statusText
        })]
      }), STATUS_RUNNING === status && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ProgressBar.default, {
        className: `${baseClassName}__progress`,
        intent: "info",
        progress: progress
      })]
    })]
  });
};
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 = exports.default = ProgressStep;