/* index.tsx generated by @compiled/babel-plugin v0.38.1 */
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
require("./index.compiled.css");
var _react = _interopRequireWildcard(require("react"));
var React = _react;
var _runtime = require("@compiled/react/runtime");
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _reactRenderImage = _interopRequireDefault(require("react-render-image"));
var _loadingSkeleton = require("../loading-skeleton");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var styles = {
  roundImg: "_2rko1rr0"
};
var ImageIcon = function ImageIcon(_ref) {
  var defaultIcon = _ref.defaultIcon,
    testId = _ref.testId,
    url = _ref.url,
    width = _ref.width,
    height = _ref.height,
    _ref$appearance = _ref.appearance,
    appearance = _ref$appearance === void 0 ? 'square' : _ref$appearance,
    onError = _ref.onError,
    onLoad = _ref.onLoad,
    _ref$hideLoadingSkele = _ref.hideLoadingSkeleton,
    hideLoadingSkeleton = _ref$hideLoadingSkele === void 0 ? false : _ref$hideLoadingSkele;
  var _useState = (0, _react.useState)(false),
    _useState2 = (0, _slicedToArray2.default)(_useState, 2),
    hasImageErrored = _useState2[0],
    setHasImageErrored = _useState2[1];

  // If url changes, reset state
  (0, _react.useEffect)(function () {
    setHasImageErrored(false);
  }, [url]);
  if (hasImageErrored) {
    return defaultIcon;
  }
  if (hideLoadingSkeleton) {
    return /*#__PURE__*/React.createElement("img", {
      src: url,
      "data-testid": "".concat(testId, "-image"),
      alt: "",
      style: {
        width: width,
        height: height
      },
      onError: function onError() {
        return setHasImageErrored(true);
      },
      className: (0, _runtime.ax)([appearance === 'round' && styles.roundImg])
    });
  } else {
    return /*#__PURE__*/React.createElement(_reactRenderImage.default, {
      src: url,
      loading: /*#__PURE__*/React.createElement(_loadingSkeleton.LoadingSkeleton, {
        testId: "".concat(testId, "-loading"),
        width: width,
        height: height
      }),
      loaded: /*#__PURE__*/React.createElement("img", {
        src: url,
        "data-testid": "".concat(testId, "-image"),
        alt: "",
        style: {
          width: width,
          height: height
        },
        className: (0, _runtime.ax)([appearance === 'round' && styles.roundImg])
      }),
      errored: defaultIcon,
      onError: onError,
      onLoad: onLoad
    });
  }
};
var _default = exports.default = ImageIcon;