"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 _LoadMore = _interopRequireDefault(require("../../common/components/LoadMore"));

var _UploadedImage = _interopRequireDefault(require("./UploadedImage"));

/*
 * 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 ImageUploadsList =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(ImageUploadsList, _Component);

  function ImageUploadsList() {
    (0, _classCallCheck2.default)(this, ImageUploadsList);
    return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(ImageUploadsList).apply(this, arguments));
  }

  (0, _createClass2.default)(ImageUploadsList, [{
    key: "componentWillMount",
    value: function componentWillMount() {
      this.props.fetchImages({
        calledFromRender: true
      });
    }
  }, {
    key: "renderImages",
    value: function renderImages() {
      var _this = this;

      return _react.default.createElement("div", {
        style: {
          width: "100%"
        }
      }, this.props.images.records.map(function (image) {
        return _react.default.createElement(_UploadedImage.default, {
          key: "image-" + image.id,
          image: image,
          onImageEmbed: _this.props.onImageEmbed
        });
      }));
    }
  }, {
    key: "render",
    value: function render() {
      return _react.default.createElement("div", {
        style: {
          maxHeight: "300px",
          overflow: "auto"
        }
      }, _react.default.createElement("div", {
        style: {
          clear: "both"
        }
      }, _react.default.createElement(_LoadMore.default, {
        focusSelector: ".img_link",
        hasMore: this.props.images.hasMore,
        isLoading: this.props.images.isLoading,
        loadMore: this.props.fetchImages
      }, this.renderImages())));
    }
  }]);
  ImageUploadsList.displayName = "ImageUploadsList";
  return ImageUploadsList;
}(_react.Component);

ImageUploadsList.propTypes = {
  images: _propTypes.default.shape({
    records: _propTypes.default.array.isRequired,
    isLoading: _propTypes.default.bool.isRequired,
    hasMore: _propTypes.default.bool.isRequired
  }),
  fetchImages: _propTypes.default.func.isRequired,
  onImageEmbed: _propTypes.default.func.isRequired
};
ImageUploadsList.defaultProps = {
  images: []
};
var _default = ImageUploadsList;
exports.default = _default;