'use strict';

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

var _path = require('path');

var _path2 = _interopRequireDefault(_path);

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

function recursiveFolder(obj) {
  var index = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  var dataShow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  var links = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  var visible = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
  var translate = arguments[5];

  var classHidden = '';
  if (index > 1 && !visible) {
    classHidden = 'hidden';
  }

  var id = 'level-' + index;
  var parent = obj[0] ? obj[0].path.split('/')[0] : '';
  var levelText = translate['level-' + index] != null ? translate['level-' + index] : 'Level ' + index;
  var res = '<div class="form-group level-' + index + ' ' + classHidden + '" data-parent="' + parent + '" data-shown="' + dataShow + '">\n    <label for="' + id + '" class="control-label">' + levelText + '</label>\n      <select data-precontrib="true" data-slug="true" data-slug-type="path" data-show-hide-sub-folder="true" id="' + id + '" data-id="' + id + '" class="form-control">\n        <option data-level-hide="' + (index + 1) + '"></option>';

  var sub = '';

  Array.prototype.forEach.call(obj, function (o) {
    var selected = '';
    var isVisible = false;
    var name = _path2.default.basename(o.path);
    if (links != null && links[index - 1] != null) {
      if (links[index - 1] === name) {
        selected = 'selected="selected"';
        isVisible = true;
      }
    }
    res += '<option ' + selected + ' data-level-hide="' + (index + 2) + '" data-level-show="' + (index + 1) + '" data-show="' + name.replace(/\.| |\#/g, '_') + '">' + name + '</option>';

    if (o.folders != null && o.folders.length > 0) {
      sub += recursiveFolder(o.folders, index + 1, name.replace(/\.| |\#/g, '_'), links, isVisible, translate);
    }
  });

  res += '</select>\n  </div>';

  res += sub;

  return res;
}