import _extends from "@babel/runtime/helpers/extends";
import * as React from 'react';
import { replaceNode, transformColorStyle } from "../util";
function transformReiszeMode(resizeMode) {
  var mode = resizeMode;
  if (resizeMode == "stretch") {
    mode = "fill";
  } else if (resizeMode == "center") {
    mode = "none";
  }
  return {
    "object-fit": mode
  };
}
var Image = function Image(props, ref) {
  var _props$resizeMode;
  // @ts-ignore
  var customStyle = (props.customStyle || []).reduce(function (obj, item) {
    var _Object$assign;
    return Object.assign(obj, (_Object$assign = {}, _Object$assign[item.name] = item.value, _Object$assign));
  }, {});
  var _props = _extends({}, props);
  var colorStyle = transformColorStyle(customStyle);
  var resizeMode = ((_props$resizeMode = props.resizeMode) === null || _props$resizeMode === void 0 ? void 0 : _props$resizeMode.length) > 0 ? transformReiszeMode(props.resizeMode) : {};
  _props.style = _extends({}, props.style || {}, customStyle, colorStyle, resizeMode);
  if (_props.typeConversion && _props.typeConversion !== 'Image') {
    replaceNode(_props.typeConversion);
  }
  return /*#__PURE__*/React.createElement("img", _extends({}, _props, {
    ref: ref
  }));
};
var RefImage = /*#__PURE__*/React.forwardRef(Image);
RefImage.defaultProps = {
  src: 'https://img.alicdn.com/tps/TB16TQvOXXXXXbiaFXXXXXXXXXX-120-120.svg'
};
export default RefImage;