'use strict';

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

var _handlebars = require('handlebars');

var _handlebars2 = _interopRequireDefault(_handlebars);

var _moment = require('moment');

var _moment2 = _interopRequireDefault(_moment);

var _ = require('../../../');

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

function listPage(file, index, text) {
  var res = '';

  file = _.abeExtend.hooks.instance.trigger('beforeListPage', file, index, text);

  res += '<tr>';
  res += '<td>' + (0, _.math)(index, '+', 1) + '</td>\n        <td>\n          <a href="/abe/editor' + file.abe_meta.link + '" class="file-path">\n            ' + file.abe_meta.link + '\n          </a>\n        </td>';

  if (file.abe_meta.template) {
    res += '<td align="center">\n              ' + file.abe_meta.template + '\n            </td>';
  } else {
    res += '<td align="center"></td>';
  }

  if (file.date) {
    var dateSearch = (0, _moment2.default)(file.date).format('YYYY-MM-DD');
    var dateOrder = new Date(file.date).getTime();
    res += '<td align="center" data-search="' + dateSearch + '" data-order="' + dateOrder + '">\n              ' + dateSearch + '\n            </td>';
  } else {
    res += '<td align="center" data-search="0000-00-00" data-order="0"></td>';
  }

  var workflow = '';

  var status = file.abe_meta.status;
  var workflowUser = _.config.users.workflow;
  Array.prototype.forEach.call(workflowUser, function (flow) {
    var hidden = '';
    if (status !== flow) {
      hidden = 'hidden';
    }

    workflow += '<td align="center" class="' + flow + '">';
    if (file[flow]) {
      if (flow === 'publish') {
        workflow += '<a href="/abe/editor' + file[flow].html + '" class="checkmark label-published" title="' + file[flow].cleanDate + '">&#10004;</a>';
      } else {
        workflow += '<a href="/abe/editor' + file[flow].html + '" class="' + hidden + ' label label-default label-draft" title="' + file[flow].cleanDate + '">' + flow + '</a>';
      }
    } else {}
    workflow += '</td>';
  });

  res += workflow;

  res += '<td align="center">\n            <div class="row icons-action">';

  if (file.publish != null) {
    res += '<a href="/abe/operations/unpublish' + file.abe_meta.link + '"\n               title="' + text.unpublish + '"\n               class="icon" data-unpublish="true" data-text="' + text.confirmUnpublish + ' ' + file.abe_meta.link + '"\n               title="unpublish">\n              <span class="glyphicon glyphicon-eye-close"></span>\n            </a>';
  }

  res += '<a href="/abe/operations/delete/' + file.abe_meta.status + file.abe_meta.link + '"\n             title="' + text.delete + '"\n             class="icon"\n             data-delete="true"\n             data-text="' + text.confirmDelete + ' ' + file.abe_meta.link + '"\n             title="remove">\n            <span class="glyphicon glyphicon-trash"></span>\n          </a>';

  res += '\n        </div>\n      </td>\n    </tr>';

  res = _.abeExtend.hooks.instance.trigger('afterListPage', res, file, index, text);
  return new _handlebars2.default.SafeString(res);
}