"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.styles = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/builtin/defineProperty"));

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

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

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

var _CheckCircle = _interopRequireDefault(require("../internal/svg-icons/CheckCircle"));

var _Warning = _interopRequireDefault(require("../internal/svg-icons/Warning"));

var _withStyles = _interopRequireDefault(require("../styles/withStyles"));

var _SvgIcon = _interopRequireDefault(require("../SvgIcon"));

var styles = function styles(theme) {
  return {
    root: {
      display: 'block',
      color: theme.palette.text.disabled,
      '&$active': {
        color: theme.palette.primary.main
      },
      '&$completed': {
        color: theme.palette.primary.main
      },
      '&$error': {
        color: theme.palette.error.main
      }
    },
    text: {
      fill: theme.palette.primary.contrastText,
      fontSize: theme.typography.caption.fontSize,
      fontFamily: theme.typography.fontFamily
    },
    active: {},
    completed: {},
    error: {}
  };
};

exports.styles = styles;

var _ref = _react.default.createElement("circle", {
  cx: "12",
  cy: "12",
  r: "12"
});

function StepIcon(props) {
  var completed = props.completed,
      icon = props.icon,
      active = props.active,
      error = props.error,
      classes = props.classes;

  if (typeof icon === 'number' || typeof icon === 'string') {
    if (error) {
      return _react.default.createElement(_Warning.default, {
        className: (0, _classnames.default)(classes.root, classes.error)
      });
    }

    if (completed) {
      return _react.default.createElement(_CheckCircle.default, {
        className: (0, _classnames.default)(classes.root, classes.completed)
      });
    }

    return _react.default.createElement(_SvgIcon.default, {
      className: (0, _classnames.default)(classes.root, (0, _defineProperty2.default)({}, classes.active, active))
    }, _ref, _react.default.createElement("text", {
      className: classes.text,
      x: "12",
      y: "16",
      textAnchor: "middle"
    }, icon));
  }

  return icon;
}

StepIcon.propTypes = process.env.NODE_ENV !== "production" ? {
  /**
   * Whether this step is active.
   */
  active: _propTypes.default.bool,

  /**
   * Override or extend the styles applied to the component.
   * See [CSS API](#css-api) below for more details.
   */
  classes: _propTypes.default.object.isRequired,

  /**
   * Mark the step as completed. Is passed to child components.
   */
  completed: _propTypes.default.bool,

  /**
   * Mark the step as failed.
   */
  error: _propTypes.default.bool,

  /**
   * The icon displayed by the step label.
   */
  icon: _propTypes.default.node.isRequired
} : {};
StepIcon.defaultProps = {
  active: false,
  completed: false,
  error: false
};

var _default = (0, _withStyles.default)(styles, {
  name: 'MuiStepIcon'
})(StepIcon);

exports.default = _default;