var _excluded = ["icon", "value", "min", "max", "step", "readOnly", "disabled", "onChange"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { forwardRef, useRef, useImperativeHandle } from 'react';

// 内库使用-start
import DOMUtil from "./../../../utils/DOMUtil";
// 内库使用-end

/* 测试使用-start
import { DOMUtil } from 'seedsui-react'
测试使用-end */

// 评分组件
var Rate = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var icon = _ref.icon,
    _ref$value = _ref.value,
    value = _ref$value === void 0 ? 0 : _ref$value,
    _ref$min = _ref.min,
    min = _ref$min === void 0 ? 0 : _ref$min,
    _ref$max = _ref.max,
    max = _ref$max === void 0 ? 5 : _ref$max,
    _ref$step = _ref.step,
    step = _ref$step === void 0 ? 0.5 : _ref$step,
    readOnly = _ref.readOnly,
    disabled = _ref.disabled,
    onChange = _ref.onChange,
    props = _objectWithoutProperties(_ref, _excluded);
  var rootRef = useRef(null);
  useImperativeHandle(ref, function () {
    return {
      rootDOM: rootRef.current,
      getRootDOM: function getRootDOM() {
        return rootRef.current;
      }
    };
  });
  function handleChange(e) {
    if (disabled || readOnly) return;
    var newValue = e.currentTarget.value;
    if (newValue) newValue = Number(newValue || 0);
    if (onChange) {
      onChange(newValue);
    }
  }
  function getItemActiveWidth(itemValue) {
    // 当前项位于整数位
    if (itemValue <= value) {
      return '100%';
    }
    // 当前项位于小数位
    if (itemValue === Math.ceil(value)) {
      return "".concat((value - Math.floor(value)) * 100, "%");
    }
    // 当前项超出
    return '0%';
  }
  return /*#__PURE__*/React.createElement("div", _extends({}, props, {
    className: DOMUtil.classNames('input-rate', props.className, readOnly ? 'readOnly' : '', disabled ? ' disabled' : ''),
    ref: rootRef
  }), /*#__PURE__*/React.createElement("input", {
    readOnly: readOnly,
    disabled: disabled,
    type: "range",
    className: "input-rate-input",
    min: min,
    max: max,
    step: step,
    value: value,
    onChange: handleChange
  }), new Array(max).fill(1).map(function (item, index) {
    return /*#__PURE__*/React.createElement("div", {
      className: "input-rate-item",
      key: index
    }, icon ? DOMUtil.getIconNode(icon, {
      className: 'input-rate-item-icon'
    }) : /*#__PURE__*/React.createElement("div", {
      className: 'input-rate-item-icon default'
    }), icon ? DOMUtil.getIconNode(icon, {
      className: 'input-rate-item-icon-active',
      style: {
        width: getItemActiveWidth(index + 1)
      }
    }) : /*#__PURE__*/React.createElement("div", {
      className: 'input-rate-item-icon-active default',
      style: {
        width: getItemActiveWidth(index + 1)
      }
    }));
  }));
});
export default Rate;