import { flatten } from 'lodash';
var separator = '/';
/**
 * パスを ImmutableFile.name に相当する normalized file path に変換する
 * @param pathes 連結されるパス
 */

export default function normalize() {
  for (var _len = arguments.length, pathes = new Array(_len), _key = 0; _key < _len; _key++) {
    pathes[_key] = arguments[_key];
  }

  var segments = flatten(pathes.map(function (seg) {
    return seg.split(separator);
  }));
  var normalizedSegments = [];
  var _iteratorNormalCompletion = true;
  var _didIteratorError = false;
  var _iteratorError = undefined;

  try {
    for (var _iterator = segments[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
      var seg = _step.value;

      switch (seg) {
        case '':
          break;
        // nope

        case '.':
          break;
        //current direcotry

        case '..':
          normalizedSegments.pop(); // above directory

          break;

        default:
          normalizedSegments.push(seg);
          break;
      }
    }
  } catch (err) {
    _didIteratorError = true;
    _iteratorError = err;
  } finally {
    try {
      if (!_iteratorNormalCompletion && _iterator.return != null) {
        _iterator.return();
      }
    } finally {
      if (_didIteratorError) {
        throw _iteratorError;
      }
    }
  }

  return normalizedSegments.join(separator);
}