"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

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

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

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

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

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

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

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

var _contentRendering = require("../../rce/contentRendering");

var _dragHtml = _interopRequireDefault(require("../dragHtml"));

var _formatMessage = _interopRequireDefault(require("../../format-message"));

/*
 * Copyright (C) 2018 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */
var UploadedImage =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(UploadedImage, _Component);

  function UploadedImage() {
    var _getPrototypeOf2;

    var _this;

    (0, _classCallCheck2.default)(this, UploadedImage);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf2.default)(UploadedImage)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.handleImageClick = function (e) {
      e.preventDefault();

      _this.props.onImageEmbed(_this.props.image);
    };

    _this.onDrag = function (ev) {
      (0, _dragHtml.default)(ev, (0, _contentRendering.renderImage)(_this.props.image));
    };

    return _this;
  }

  (0, _createClass2.default)(UploadedImage, [{
    key: "imgTitle",
    value: function imgTitle() {
      return "Klicka f\xF6r att b\xE4dda in " + this.props.image.display_name;
    }
  }, {
    key: "renderImg",
    value: function renderImg() {
      var image = this.props.image;
      return _react.default.createElement("img", {
        draggable: true,
        onDragStart: this.onDrag,
        src: image.thumbnail_url,
        alt: image.display_name,
        title: this.imgTitle(),
        style: {
          maxHeight: 50,
          maxWidth: 200
        }
      });
    }
  }, {
    key: "render",
    value: function render() {
      return _react.default.createElement("a", {
        href: this.props.image,
        role: "button",
        title: "Klicka f\xF6r att b\xE4dda in bild",
        draggable: false,
        onDragStart: this.onDrag,
        onClick: this.handleImageClick,
        style: imgLinkStyles
      }, _react.default.createElement("div", {
        style: {
          minHeight: "50px"
        }
      }, this.renderImg()), _react.default.createElement("div", {
        style: {
          wordBreak: "break-all"
        }
      }, this.props.image.display_name));
    }
  }]);
  UploadedImage.displayName = "UploadedImage";
  return UploadedImage;
}(_react.Component);

UploadedImage.propTypes = {
  image: _propTypes.default.shape({
    id: _propTypes.default.number.isRequired,
    filename: _propTypes.default.string,
    display_name: _propTypes.default.string.isRequired,
    preview_url: _propTypes.default.string.isRequired,
    thumbnail_url: _propTypes.default.string,
    href: _propTypes.default.string
  }).isRequired,
  onImageEmbed: _propTypes.default.func.isRequired
};
var imgLinkStyles = {
  cursor: "pointer",
  overflow: "hidden",
  border: "1px solid #ccc",
  margin: "3px",
  padding: "3px",
  float: "left"
};
var _default = UploadedImage;
exports.default = _default;