'use strict';

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

exports.__esModule = true;
exports.BrandedImage = void 0;

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

var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _BrandedFileLoader = _interopRequireDefault(require("../utils/BrandedFileLoader"));

var BrandedImage =
/*#__PURE__*/
function (_React$Component) {
  (0, _inheritsLoose2.default)(BrandedImage, _React$Component);

  function BrandedImage() {
    return _React$Component.apply(this, arguments) || this;
  }

  var _proto = BrandedImage.prototype;

  _proto.render = function render() {
    var _this$props = this.props,
        src = _this$props.src,
        folderContext = _this$props.folderContext,
        props = (0, _objectWithoutPropertiesLoose2.default)(_this$props, ["src", "folderContext"]);
    var imageLoader = new _BrandedFileLoader.default(folderContext);
    var fileInfo = imageLoader.getFileInfo(src);
    return _react.default.createElement("img", (0, _extends2.default)({}, props, {
      src: fileInfo.file,
      "data-src": fileInfo.requirePath
    }));
  };

  return BrandedImage;
}(_react.default.Component);

exports.BrandedImage = BrandedImage;
(0, _defineProperty2.default)(BrandedImage, "propTypes", {
  src: _propTypes.default.string.isRequired,
  // file path relative to target folder
  folderContext: _propTypes.default.func.isRequired,
  // require.context('./target/folder/relative/path/to/current/file')
  alt: _propTypes.default.string
});
(0, _defineProperty2.default)(BrandedImage, "defaultProps", {
  alt: ''
});