'use strict';

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

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _ramda;

function _load_ramda() {
  return _ramda = _interopRequireDefault(require('ramda'));
}

var _bitId;

function _load_bitId() {
  return _bitId = require('../../../bit-id');
}

var _bitMap;

function _load_bitMap() {
  return _bitMap = _interopRequireDefault(require('../../bit-map'));
}

var _constants;

function _load_constants() {
  return _constants = require('../../../constants');
}

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Dependency = function () {
  function Dependency(id, relativePaths) {
    _classCallCheck(this, Dependency);

    this.id = id;
    this.relativePaths = relativePaths;
  }

  _createClass(Dependency, null, [{
    key: 'stripOriginallySharedDir',
    value: function stripOriginallySharedDir(dependency, bitMap, originallySharedDir) {
      var pathWithoutSharedDir = function pathWithoutSharedDir(pathStr, sharedDir) {
        if (!sharedDir) return pathStr;
        var partToRemove = `${sharedDir}/`;
        return pathStr.replace(partToRemove, '');
      };
      var dependencyId = dependency.id.toString();
      var depFromBitMap = bitMap.getComponent(dependencyId);
      dependency.relativePaths.forEach(function (relativePath) {
        relativePath.sourceRelativePath = pathWithoutSharedDir(relativePath.sourceRelativePath, originallySharedDir);
        if (depFromBitMap && depFromBitMap.origin === (_constants || _load_constants()).COMPONENT_ORIGINS.IMPORTED) {
          relativePath.destinationRelativePath = pathWithoutSharedDir(relativePath.destinationRelativePath, depFromBitMap.originallySharedDir);
        }
      });
    }
  }, {
    key: 'getClone',
    value: function getClone(dependency) {
      return {
        id: dependency.id,
        relativePaths: (_ramda || _load_ramda()).default.clone(dependency.relativePaths)
      };
    }
  }]);

  return Dependency;
}();

exports.default = Dependency;