"use strict";

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

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

function _objectSpread2() {
  const data = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));

  _objectSpread2 = function () {
    return data;
  };

  return data;
}

function _defineProperty2() {
  const data = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

  _defineProperty2 = function () {
    return data;
  };

  return data;
}

function _ramda() {
  const data = _interopRequireDefault(require("ramda"));

  _ramda = function () {
    return data;
  };

  return data;
}

function _chalk() {
  const data = _interopRequireDefault(require("chalk"));

  _chalk = function () {
    return data;
  };

  return data;
}

function _command() {
  const data = _interopRequireDefault(require("../../command"));

  _command = function () {
    return data;
  };

  return data;
}

function _consumer() {
  const data = require("../../../api/consumer");

  _consumer = 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 _ejectTemplate() {
  const data = _interopRequireDefault(require("../../templates/eject-template"));

  _ejectTemplate = function () {
    return data;
  };

  return data;
}

class Export extends _command().default {
  constructor(...args) {
    super(...args);
    (0, _defineProperty2().default)(this, "name", 'export <remote> [id...]');
    (0, _defineProperty2().default)(this, "description", `export components to a remote scope.
  https://${_constants().BASE_DOCS_DOMAIN}/docs/organizing-components-in-scopes.html
  the id can be used with wildcards (e.g. bit export remote-scope "utils/*")`);
    (0, _defineProperty2().default)(this, "alias", 'e');
    (0, _defineProperty2().default)(this, "opts", [['e', 'eject', 'replaces the exported components from the local scope with the corresponding packages']]);
    (0, _defineProperty2().default)(this, "loader", true);
    (0, _defineProperty2().default)(this, "migration", true);
  }

  action([remote, ids], {
    eject
  }) {
    return (0, _consumer().exportAction)(ids, remote, eject).then(results => (0, _objectSpread2().default)({}, results, {
      remote
    }));
  }

  report({
    componentsIds,
    nonExistOnBitMap,
    ejectResults,
    remote
  }) {
    if (_ramda().default.isEmpty(componentsIds) && _ramda().default.isEmpty(nonExistOnBitMap)) return _chalk().default.yellow('nothing to export');

    const exportOutput = () => {
      if (_ramda().default.isEmpty(componentsIds)) return '';
      return _chalk().default.green(`exported ${componentsIds.length} components to scope ${_chalk().default.bold(remote)}`);
    };

    const nonExistOnBitMapOutput = () => {
      if (_ramda().default.isEmpty(nonExistOnBitMap)) return '';
      const ids = nonExistOnBitMap.map(id => id.toString()).join(', ');
      return _chalk().default.yellow(`${ids}\nexported successfully. bit did not update the workspace as the component files are not tracked. this might happen when a component was tracked in a different git branch. to fix it check if they where tracked in a different git branch, checkout to that branch and resync by running 'bit import'. or stay on your branch and track the components again using 'bit add'.`);
    };

    const ejectOutput = () => {
      if (!ejectResults) return '';
      const output = (0, _ejectTemplate().default)(ejectResults);
      return `\n${output}`;
    };

    return nonExistOnBitMapOutput() + exportOutput() + ejectOutput();
  }

}

exports.default = Export;