function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

/*
 * @Author: codingfly
 * @Description:
 * @Date: 2021-08-19 16:30:43
 * @LastEditTime: 2021-09-06 09:03:33
 * @FilePath: \young\components\rate\index.tsx
 */
import * as React from 'react';
import { useMemo } from 'react';
import { View } from 'remax/one';
import Icon from '../icon';
import { getPrefixCls } from './../common';
var prefixCls = getPrefixCls('rate');

var Rate = function Rate(props) {
  var _props$count = props.count,
      count = _props$count === void 0 ? 5 : _props$count,
      label = props.label,
      _props$value = props.value,
      value = _props$value === void 0 ? 0 : _props$value,
      onChange = props.onChange,
      readOnly = props.readOnly,
      _props$icon = props.icon,
      icon = _props$icon === void 0 ? 'favor' : _props$icon,
      _props$iconFill = props.iconFill,
      iconFill = _props$iconFill === void 0 ? 'favorfill' : _props$iconFill,
      _props$size = props.size,
      size = _props$size === void 0 ? 28 : _props$size,
      _props$color = props.color,
      color = _props$color === void 0 ? '#FFD700' : _props$color;

  var handleClick = function handleClick(index) {
    if (readOnly) {
      return;
    }

    onChange === null || onChange === void 0 ? void 0 : onChange(index + 1);
  };

  var stars = useMemo(function () {
    if (!count) {
      return [];
    }

    return _toConsumableArray(new Array(count).keys());
  }, [count]);
  return /*#__PURE__*/React.createElement(View, {
    className: prefixCls
  }, label ? /*#__PURE__*/React.createElement(View, {
    className: "".concat(prefixCls, "-label")
  }, label) : null, /*#__PURE__*/React.createElement(View, {
    className: "".concat(prefixCls, "-value")
  }, stars.map(function (item, index) {
    return /*#__PURE__*/React.createElement(View, {
      key: index,
      className: "".concat(prefixCls, "-value-star"),
      onTap: function onTap() {
        handleClick(index);
      }
    }, value >= index + 1 ? /*#__PURE__*/React.createElement(Icon, {
      type: iconFill,
      size: size,
      color: color
    }) : /*#__PURE__*/React.createElement(Icon, {
      type: icon,
      size: size,
      color: "#999"
    }));
  })));
};

export default Rate;