'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 _path;

function _load_path() {
  return _path = _interopRequireDefault(require('path'));
}

var _stringFormat;

function _load_stringFormat() {
  return _stringFormat = _interopRequireDefault(require('string-format'));
}

var _utils;

function _load_utils() {
  return _utils = require('../../utils');
}

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 ConfigDir = function () {
  function ConfigDir(dirPath) {
    _classCallCheck(this, ConfigDir);

    this.dirPath = dirPath;
  }

  _createClass(ConfigDir, [{
    key: 'clone',
    value: function clone() {
      return new ConfigDir(this.dirPath);
    }
  }, {
    key: 'repalceByComponentDirDSL',
    value: function repalceByComponentDirDSL(componentDir) {
      if (this.linuxDirPath.startsWith(componentDir)) {
        var replaced = this.linuxDirPath.replace(componentDir, `{${(_constants || _load_constants()).COMPONENT_DIR}}`);
        this.dirPath = (_path || _load_path()).default.normalize(replaced);
      }
    }
  }, {
    key: 'getCleaned',
    value: function getCleaned(_ref) {
      var cleanComponentDir = _ref.cleanComponentDir,
          cleanEnvType = _ref.cleanEnvType;

      var componentDir = cleanComponentDir ? '' : `{${(_constants || _load_constants()).COMPONENT_DIR}}`;
      var envType = cleanEnvType ? '' : '{ENV_TYPE}';
      var cleaned = (0, (_stringFormat || _load_stringFormat()).default)(this.dirPath, { [`{${(_constants || _load_constants()).COMPONENT_DIR}}`]: componentDir, ENV_TYPE: envType });
      return new ConfigDir(cleaned);
    }
  }, {
    key: 'getEnvTypeCleaned',
    value: function getEnvTypeCleaned() {
      return this.getCleaned({ cleanComponentDir: false, cleanEnvType: true });
    }
  }, {
    key: 'getComponentDirCleaned',
    value: function getComponentDirCleaned() {
      return this.getCleaned({ cleanComponentDir: true, cleanEnvType: false });
    }
  }, {
    key: 'getResolved',
    value: function getResolved(_ref2) {
      var componentDir = _ref2.componentDir,
          envType = _ref2.envType;

      var resolvedComponentDir = componentDir || `{${(_constants || _load_constants()).COMPONENT_DIR}}`;
      var resolvedEnvType = envType || '{ENV_TYPE}';
      var resolved = (0, (_stringFormat || _load_stringFormat()).default)(this.dirPath, { [(_constants || _load_constants()).COMPONENT_DIR]: resolvedComponentDir, ENV_TYPE: resolvedEnvType });
      return new ConfigDir(resolved);
    }
  }, {
    key: 'linuxDirPath',
    get: function get() {
      return (0, (_utils || _load_utils()).pathNormalizeToLinux)(this.dirPath);
    }
  }, {
    key: 'isUnderComponentDir',
    get: function get() {
      return this.dirPath.startsWith(`{${(_constants || _load_constants()).COMPONENT_DIR}}`);
    }
  }, {
    key: 'hasEnvType',
    get: function get() {
      return this.dirPath.includes('{ENV_TYPE}');
    }
  }, {
    key: 'isWorkspaceRoot',
    get: function get() {
      var linDirPath = this.linuxDirPath;
      return linDirPath === '.' || linDirPath === './';
    }
  }]);

  return ConfigDir;
}();

exports.default = ConfigDir;