"use strict";

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

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

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

var _api = _interopRequireDefault(require("../sources/api"));

/*
 * 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/>.
 */
// normalize contextType. e.g. accept either of 'course' or 'courses', but
// only store 'course'
function normalizeContextType(contextType) {
  switch (contextType) {
    case "course":
    case "courses":
      return "course";

    case "group":
    case "groups":
      return "group";

    case "user":
    case "users":
      return "user";

    default:
      return undefined;
  }
}

function _default() {
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  var _props = props,
      source = _props.source,
      jwt = _props.jwt,
      refreshToken = _props.refreshToken,
      host = _props.host,
      contextType = _props.contextType,
      contextId = _props.contextId,
      collections = _props.collections,
      files = _props.files,
      folders = _props.folders,
      upload = _props.upload,
      images = _props.images,
      flickr = _props.flickr,
      newPageLinkExpanded = _props.newPageLinkExpanded; // normalize contextType (including in props)

  contextType = normalizeContextType(contextType);
  props = (0, _objectSpread2.default)({}, props, {
    contextType: contextType
  }); // default to API source

  if (source === undefined) {
    source = new _api.default({
      jwt: jwt,
      refreshToken: refreshToken,
      host: host
    });
  } // create collections in default state if none provided


  if (collections === undefined) {
    collections = {
      announcements: source.initializeCollection("announcements", props),
      assignments: source.initializeCollection("assignments", props),
      discussions: source.initializeCollection("discussions", props),
      modules: source.initializeCollection("modules", props),
      quizzes: source.initializeCollection("quizzes", props),
      wikiPages: source.initializeCollection("wikiPages", props)
    };
  }

  if (upload === undefined) {
    upload = source.initializeUpload(props);
  }

  if (flickr === undefined) {
    flickr = source.initializeFlickr(props);
  }

  if (images === undefined) {
    images = source.initializeImages(props);
  }

  if (newPageLinkExpanded === undefined) {
    newPageLinkExpanded = false;
  }

  return {
    source: source,
    jwt: jwt,
    host: host,
    contextType: contextType,
    contextId: contextId,
    collections: collections,
    files: files,
    folders: folders,
    upload: upload,
    images: images,
    flickr: flickr,
    newPageLinkExpanded: newPageLinkExpanded
  };
}