// Copyright 1999-2023. Plesk International GmbH. All rights reserved.

import { isValidElement, Children, useContext } from 'react';
import classNames from 'classnames';
import Icon, { ICON_SIZE_16 } from '../Icon';
import StatusComponent from '../Status';
import { CLS_PREFIX } from '../../constants';
import ProgressBar from '../ProgressBar';
import OnDarkContext from '../OnDarkContext';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
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 = _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.create(icon, {
    className: `${baseClassName}__icon`,
    size: ICON_SIZE_16,
    intent
  });
  if (statusText && (! /*#__PURE__*/isValidElement(statusText) || statusText.type !== StatusComponent)) {
    statusText = /*#__PURE__*/_jsx(StatusComponent, {
      children: statusText
    });
  }
  return /*#__PURE__*/_jsxs("div", {
    className: classNames(baseClassName, {
      [`${baseClassName}--${intent}`]: intent,
      [`${baseClassName}--content`]: Children.toArray(children).length,
      [`${baseClassName}--on-dark`]: useContext(OnDarkContext)
    }, className),
    ...props,
    children: [icon && /*#__PURE__*/_jsx("div", {
      className: `${baseClassName}__media`,
      children: icon
    }), /*#__PURE__*/_jsxs("div", {
      className: `${baseClassName}__body`,
      children: [(title || statusText || Children.toArray(children).length > 0) && /*#__PURE__*/_jsxs("div", {
        className: `${baseClassName}__labels`,
        children: [/*#__PURE__*/_jsxs("div", {
          className: `${baseClassName}__labels-body`,
          children: [title && /*#__PURE__*/_jsx("div", {
            className: `${baseClassName}__title`,
            children: title
          }), Children.toArray(children).length ? /*#__PURE__*/_jsx("div", {
            className: `${baseClassName}__content`,
            children: children
          }) : null]
        }), statusText && /*#__PURE__*/_jsx("div", {
          className: `${baseClassName}__status`,
          children: statusText
        })]
      }), STATUS_RUNNING === status && /*#__PURE__*/_jsx(ProgressBar, {
        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: `${CLS_PREFIX}progress-step`
};
export default ProgressStep;