const { fmt, ui, $ } = Admin;

Admin.onStatus((status) => {
  const runs = status.runs || [];
  $('import-rows').innerHTML = runs.length ? runs.map((run) => {
    const tone = run.status === 'success' ? 'ok' : run.status === 'running' ? 'warn' : 'bad';
    return '<tr><td>' + fmt.escape(fmt.when(run.startedAt)) + '</td>' +
      '<td>' + fmt.escape(run.kind) + '</td>' +
      '<td>' + fmt.escape(run.trigger) + '</td>' +
      '<td>' + ui.tag(run.status, tone) + '</td>' +
      '<td class="num">' + fmt.number(run.itemsSeen) + '</td>' +
      '<td class="num">' + fmt.number(run.itemsUpserted) + '</td>' +
      '<td class="num">' + fmt.number(run.itemsRemoved) + '</td>' +
      '<td class="muted">' + fmt.escape(run.error || '') + '</td></tr>';
  }).join('') : ui.emptyRow(8, 'Nothing has been imported yet.');
});
