"use strict";

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

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

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

var _images = require("../actions/images");

/*
 * 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/>.
 */
function imagesReducer() {
  var images = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var action = arguments.length > 1 ? arguments[1] : undefined;

  switch (action.type) {
    case _images.ADD_IMAGE:
      {
        var id = action.id,
            filename = action.filename,
            display_name = action.display_name,
            preview_url = action.preview_url,
            thumbnail_url = action.thumbnail_url;
        return (0, _objectSpread2.default)({}, images, {
          records: images.records.concat({
            id: id,
            filename: filename,
            display_name: display_name,
            preview_url: preview_url,
            thumbnail_url: thumbnail_url,
            href: preview_url
          })
        });
      }

    case _images.REQUEST_IMAGES:
      return (0, _objectSpread2.default)({}, images, {
        requested: true,
        isLoading: true
      });

    case _images.RECEIVE_IMAGES:
      {
        var receivedImages = action.imageRecords;
        return (0, _objectSpread2.default)({}, images, {
          records: images.records.concat(receivedImages),
          isLoading: false,
          bookmark: action.bookmark,
          hasMore: !!action.bookmark
        });
      }

    default:
      return images;
  }
}