"use strict";

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

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

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 _bitId() {
  const data = require("../../../bit-id");

  _bitId = 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;
}

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

function remove({
  path,
  ids,
  force
}, headers) {
  const bitIds = _bitId().BitIds.deserialize(ids);

  const args = {
    path,
    bitIds,
    force
  };
  HooksManagerInstance.triggerHook(_constants().PRE_REMOVE_REMOTE, args, headers);
  return (0, _scope().loadScope)(path).then(scope => {
    return scope.removeMany(bitIds, force).then(
    /*#__PURE__*/
    function () {
      var _ref = (0, _bluebird().coroutine)(function* (res) {
        const hookArgs = {
          removedComponentsIds: res.removedComponentIds.serialize(),
          missingComponentsIds: res.missingComponents.serialize(),
          dependentBitsIds: res.dependentBits,
          force,
          scopePath: path,
          componentsIds: bitIds.serialize(),
          scopeName: scope.scopeJson.name
        };
        yield HooksManagerInstance.triggerHook(_constants().POST_REMOVE_REMOTE, hookArgs, headers);
        return res.serialize();
      });

      return function (_x) {
        return _ref.apply(this, arguments);
      };
    }());
  });
}