"use strict";

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

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

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

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

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

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

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

var _utils = require("./utils");

var _excluded = ["className", "component", "viewBox", "spin", "rotate", "tabIndex", "onClick", "children"];

var Icon = /*#__PURE__*/_react["default"].forwardRef(function (props, ref) {
  var className = props.className,
      Component = props.component,
      viewBox = props.viewBox,
      spin = props.spin,
      rotate = props.rotate,
      tabIndex = props.tabIndex,
      onClick = props.onClick,
      children = props.children,
      restProps = (0, _objectWithoutProperties2["default"])(props, _excluded);
  var height = restProps.height,
      width = restProps.width;
  (0, _utils.warning)(Boolean(Component || children), 'Should have `component` prop or `children`.');
  (0, _utils.useInsertStyles)();
  var classString = (0, _classnames["default"])('c7nicon', className);
  var svgClassString = (0, _classnames["default"])({
    'c7nicon-spin': !!spin
  });
  var svgStyle = rotate ? {
    msTransform: "rotate(".concat(rotate, "deg)"),
    transform: "rotate(".concat(rotate, "deg)")
  } : undefined;
  var innerSvgProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, _utils.svgBaseProps), {}, {
    className: svgClassString,
    style: svgStyle,
    viewBox: viewBox,
    height: height || _utils.svgBaseProps.height,
    width: width || _utils.svgBaseProps.width
  });

  if (!viewBox) {
    delete innerSvgProps.viewBox;
  } // component > children


  var renderInnerNode = function renderInnerNode() {
    if (Component) {
      return /*#__PURE__*/_react["default"].createElement(Component, (0, _extends2["default"])({}, innerSvgProps), children);
    }

    if (children) {
      (0, _utils.warning)(Boolean(viewBox) || _react["default"].Children.count(children) === 1 && /*#__PURE__*/_react["default"].isValidElement(children) && _react["default"].Children.only(children).type === 'use', 'Make sure that you provide correct `viewBox`' + ' prop (default `0 0 1024 1024`) to the icon.');
      return /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({}, innerSvgProps, {
        viewBox: viewBox
      }), children);
    }

    return null;
  };

  var iconTabIndex = tabIndex;

  if (iconTabIndex === undefined && onClick) {
    iconTabIndex = -1;
  }

  return /*#__PURE__*/_react["default"].createElement("span", (0, _extends2["default"])({
    role: "img"
  }, restProps, {
    ref: ref,
    tabIndex: iconTabIndex,
    onClick: onClick,
    className: classString
  }), renderInnerNode());
});

Icon.displayName = 'SvgIcon';
Icon.__C7N_ICON = true;
var _default = Icon;
exports["default"] = _default;
//# sourceMappingURL=Icon.js.map
