function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

import * as React from 'react';
import classNames from 'classnames';

var Image =
/*#__PURE__*/
function (_React$PureComponent) {
  _inherits(Image, _React$PureComponent);

  function Image() {
    var _this;

    _classCallCheck(this, Image);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(Image).apply(this, arguments));
    _this.state = {
      isIE: false
    };

    _this.stripQueryStringAndHashFromPath = function (url) {
      return url.split('?')[0].split('#')[0];
    };

    _this.detectIE = function () {
      var ua = window.navigator.userAgent; // IE 10
      // ua = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)';

      var msie = ua.indexOf('MSIE ');

      if (msie > 0) {
        return true;
      } // IE 11
      // ua = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko';


      var trident = ua.indexOf('Trident/');

      if (trident > 0) {
        return true;
      } // other browser


      return false;
    };

    return _this;
  }

  _createClass(Image, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      this.setState({
        isIE: this.detectIE()
      });
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props = this.props,
          src = _this$props.src,
          alt = _this$props.alt,
          className = _this$props.className,
          adjustMargin = _this$props.adjustMargin,
          height = _this$props.height,
          fit = _this$props.fit;
      var isIE = this.state.isIE;
      if (!src) return null;
      var link = this.stripQueryStringAndHashFromPath(src);
      var extension = link.split('.').pop();
      var imagepath = link.split('.').slice(0, -1).join('.');
      return React.createElement("div", {
        className: classNames(className, adjustMargin ? "screen-adjust-margin-".concat(adjustMargin) : '', 'ant-image'),
        style: height ? {
          height: height
        } : {}
      }, !isIE && React.createElement("picture", null, React.createElement("source", {
        srcSet: "".concat(imagepath, ".").concat(extension, " 1x, ").concat(imagepath, "@2x.").concat(extension, " 2x, ").concat(imagepath, "@3x.").concat(extension, " 3x")
      }), React.createElement("img", {
        src: "".concat(imagepath, ".").concat(extension),
        alt: alt,
        style: {
          objectFit: fit
        }
      })), isIE && React.createElement("div", {
        className: "image-wrapper",
        style: {
          backgroundImage: "url(".concat(src, ")"),
          backgroundSize: fit,
          backgroundPosition: fit === 'cover' ? 'center' : 'left'
        }
      }));
    }
  }]);

  return Image;
}(React.PureComponent);

export { Image as default };
Image.defaultProps = {
  fit: 'contain'
};