import _extends from "@babel/runtime/helpers/extends";
// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
import React, { isValidElement, Children, useContext } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Icon, { ICON_SIZE_12 } from '../Icon';
import Status from '../Status';
import { CLS_PREFIX } from '../../constants';
import ProgressBar from '../ProgressBar';
import OnDarkContext from '../OnDarkContext';
export const STATUS_NOT_STARTED = 'not_started';
export const STATUS_RUNNING = 'running';
export const STATUS_DONE = 'done';
export const STATUS_WARNING = 'warning';
export const STATUS_ERROR = 'error';
export const STATUS_CANCELED = 'canceled';
/**
 * `ProgressStep` is a part of the [Progress](#!/Progress) component.
 * @since 1.10.0
 */

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

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

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

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

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

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

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

  icon = Icon.create(icon, {
    className: "".concat(baseClassName, "__icon"),
    size: ICON_SIZE_12,
    intent
  });

  if (statusText && (! /*#__PURE__*/isValidElement(statusText) || statusText.type !== Status)) {
    statusText = /*#__PURE__*/React.createElement(Status, null, statusText);
  }

  return /*#__PURE__*/React.createElement("div", _extends({
    className: classNames(baseClassName, {
      ["".concat(baseClassName, "--").concat(intent)]: intent,
      ["".concat(baseClassName, "--content")]: Children.toArray(children).length,
      ["".concat(baseClassName, "--on-dark")]: useContext(OnDarkContext)
    }, className)
  }, props), icon && /*#__PURE__*/React.createElement("div", {
    className: "".concat(baseClassName, "__media")
  }, icon), /*#__PURE__*/React.createElement("div", {
    className: "".concat(baseClassName, "__body")
  }, (title || statusText) && /*#__PURE__*/React.createElement("div", {
    className: "".concat(baseClassName, "__labels")
  }, title && /*#__PURE__*/React.createElement("div", {
    className: "".concat(baseClassName, "__title")
  }, title), statusText && /*#__PURE__*/React.createElement("div", {
    className: "".concat(baseClassName, "__status")
  }, statusText)), STATUS_RUNNING === status && /*#__PURE__*/React.createElement(ProgressBar, {
    className: "".concat(baseClassName, "__progress"),
    intent: "info",
    progress: progress
  }), Children.toArray(children).length ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(baseClassName, "__content")
  }, children) : null));
};

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

  /**
   * Status for the step
   * @since 1.10.0
   */
  status: PropTypes.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.node,

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

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

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

  /**
   * @ignore
   */
  className: PropTypes.string,

  /**
   * @ignore
   */
  baseClassName: PropTypes.string
};
ProgressStep.defaultProps = {
  icon: null,
  title: null,
  status: STATUS_NOT_STARTED,
  statusText: null,
  progress: -1,
  children: null,
  className: null,
  baseClassName: "".concat(CLS_PREFIX, "progress-step")
};
export default ProgressStep;