"use strict";

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

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

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

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

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

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

var _constants = require("../../constants");

// Copyright 1999-2020. Plesk International GmbH. All rights reserved.
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.default.createElement("div", (0, _extends2.default)({
  className: (0, _classnames.default)({
    [baseClassName]: true,
    [`${baseClassName}--static`]: true,
    [`${baseClassName}--small`]: small,
    [className]: true
  })
}, props), /*#__PURE__*/_react.default.createElement("div", {
  className: `${baseClassName}__rates`,
  style: {
    width: `${width(value)}%`
  }
}));

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

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

  /**
   * @ignore
   */
  className: _propTypes.default.string,

  /**
   * @ignore
   */
  baseClassName: _propTypes.default.string
};
Rating.defaultProps = {
  value: 0,
  small: false,
  className: null,
  baseClassName: `${_constants.CLS_PREFIX}rating`
};
var _default = Rating;
exports.default = _default;