import _useId from "parsec-hooks/lib/idHooks";
var _excluded = ["name", "color", "size", "className", "style"];

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

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; }

/*
 * @Author: codingfly
 * @Description:
 * @Date: 2021-10-12 11:39:33
 * @LastEditTime: 2021-10-12 14:55:27
 * @FilePath: \ui_model\src\icon\index.tsx
 */
import { View } from 'remax/one';
import React from 'react';
import Icon from './one/index';
import styles from './index.module.less';
import classNames from 'classnames';
import useViewSize from '../use-view-size';
import NeedWrap from '../need-wrap';
import Rotate from '../rotate';
import rpxToPx from '../rpx-to-px';
export default (function (_ref) {
  var name = _ref.name,
      color = _ref.color,
      _ref$size = _ref.size,
      size = _ref$size === void 0 ? '1em' : _ref$size,
      className = _ref.className,
      style = _ref.style,
      props = _objectWithoutProperties(_ref, _excluded);

  var id = _useId();

  var width2 = useViewSize(id).width;
  var isNumber = typeof size === 'number';
  return /*#__PURE__*/React.createElement(View, _objectSpread(_objectSpread({
    className: classNames(styles.wrap, className)
  }, props), {}, {
    id: id,
    style: _objectSpread({
      width: isNumber ? rpxToPx(+size) : (size + '').toUpperCase(),
      height: isNumber ? rpxToPx(+size) : (size + '').toUpperCase()
    }, style)
  }), /*#__PURE__*/React.createElement(NeedWrap, {
    wrap: Rotate,
    need: ['loading', 'loading2'].includes(name)
  }, width2 && /*#__PURE__*/React.createElement(Icon, {
    name: name,
    size: width2,
    color: color,

    /* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
    // @ts-ignore
    className: styles.icon
  })));
});