"use strict";

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

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

function _bluebird() {
  const data = require("bluebird");

  _bluebird = function () {
    return data;
  };

  return data;
}

function _scope() {
  const data = require("../../../scope");

  _scope = function () {
    return data;
  };

  return data;
}

function _componentObjects() {
  const data = _interopRequireDefault(require("../../../scope/component-objects"));

  _componentObjects = function () {
    return data;
  };

  return data;
}

function _constants() {
  const data = require("../../../constants");

  _constants = function () {
    return data;
  };

  return data;
}

function _hooks() {
  const data = _interopRequireDefault(require("../../../hooks"));

  _hooks = function () {
    return data;
  };

  return data;
}

function _exportScopeComponents() {
  const data = require("../../../scope/component-ops/export-scope-components");

  _exportScopeComponents = function () {
    return data;
  };

  return data;
}

function _bitIds() {
  const data = _interopRequireDefault(require("../../../bit-id/bit-ids"));

  _bitIds = function () {
    return data;
  };

  return data;
}

function _checkVersionCompatibility() {
  const data = require("../../../scope/network/check-version-compatibility");

  _checkVersionCompatibility = function () {
    return data;
  };

  return data;
}

const HooksManagerInstance = _hooks().default.getInstance();

var _default =
/*#__PURE__*/
function () {
  var _put = (0, _bluebird().coroutine)(function* ({
    path,
    componentObjects
  }, headers) {
    if (typeof componentObjects === 'string') {
      componentObjects = _componentObjects().default.manyFromString(componentObjects);
    }

    yield HooksManagerInstance.triggerHook(_constants().PRE_RECEIVE_OBJECTS, {
      path,
      componentObjects
    }, headers);
    const scope = yield (0, _scope().loadScope)(path); // @todo: remove this once v15 is out.

    const clientIsOld = Boolean(headers && headers.version && (0, _checkVersionCompatibility().isClientHasVersionBefore)('14.1.1', headers.version));
    const componentsBitIds = yield (0, _exportScopeComponents().exportManyBareScope)(scope, componentObjects, clientIsOld);
    const componentsIds = componentsBitIds.map(id => id.toString());
    yield HooksManagerInstance.triggerHook(_constants().POST_RECEIVE_OBJECTS, {
      componentObjects,
      componentsIds,
      scopePath: path,
      scopeName: scope.scopeJson.name
    }, headers);
    return componentsIds;
  });

  function put(_x, _x2) {
    return _put.apply(this, arguments);
  }

  return put;
}();

exports.default = _default;