import _extends from "@babel/runtime/helpers/extends";
// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
import React, { useContext } from 'react';
import classNames from 'classnames';
import { CLS_PREFIX } from '../../constants';
import { intentIconMap } from '../intentIconMap';
import Action from '../Action';
import Icon from '../Icon';
import OnDarkContext from '../OnDarkContext';

const toIcon = (icon, intent) => {
  if (icon === false) {
    return undefined;
  }

  if ((icon === true || !icon) && intent) {
    icon = intentIconMap[intent];
  }

  return Icon.create(icon, intent ? {
    name: intentIconMap[intent]
  } : undefined);
};
/**
 * `Status` component is used for indicating state of an object or the system.
 * @since 0.0.68
 */


const Status = ({
  baseClassName = `${CLS_PREFIX}status`,
  className,
  children,
  icon,
  intent,
  progress,
  compact,
  flip,
  outerProps = {},
  ...props
}) => {
  if (intent === 'muted') {
    intent = 'inactive';
  }

  return /*#__PURE__*/React.createElement(Action, _extends({
    component: "span",
    icon: compact ? undefined : toIcon(icon, intent),
    className: classNames(baseClassName, {
      [`${baseClassName}--${intent}`]: intent && !progress,
      [`${baseClassName}--on-dark`]: useContext(OnDarkContext)
    }, className),
    outerProps: { ...outerProps,
      className: classNames({
        [`${baseClassName}--compact`]: compact,
        [`${baseClassName}--flip`]: flip
      }, outerProps.className)
    },
    progress: progress
  }, props), children);
};

export default Status;