import _extends from "@babel/runtime/helpers/extends";
// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { CLS_PREFIX } from '../../constants';

const width = value => {
  let result = Math.ceil(value * 20 / 5) * 5;

  if (result % 20 === 5) {
    result += 2;
  } else if (result % 20 === 15) {
    result -= 2;
  }

  return result;
};
/**
 * `Rating` component is used for showing and collecting feedback of users' opinion in 0-5 grade scale.
 * @since 0.0.42
 */


const Rating = ({
  baseClassName,
  className,
  value,
  small,
  ...props
}) => /*#__PURE__*/React.createElement("div", _extends({
  className: classNames({
    [baseClassName]: true,
    [`${baseClassName}--static`]: true,
    [`${baseClassName}--small`]: small,
    [className]: true
  })
}, props), /*#__PURE__*/React.createElement("div", {
  className: `${baseClassName}__rates`,
  style: {
    width: `${width(value)}%`
  }
}));

Rating.propTypes = {
  /**
   * Rating value from 0 to 5.
   * @since 0.0.42
   */
  value: PropTypes.number,

  /**
   * Small variant.
   * @since 0.0.42
   */
  small: PropTypes.bool,

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

  /**
   * @ignore
   */
  baseClassName: PropTypes.string
};
Rating.defaultProps = {
  value: 0,
  small: false,
  className: null,
  baseClassName: `${CLS_PREFIX}rating`
};
export default Rating;