<?php if (false === $this->compact): ?>
<div class="controls">
  <?= $this->tabs->render($this); ?>
  <div style="margin: 1em" class="dontprint">
    <?= $this->translate('Sort by'); ?> <?= $this->sortControl->render($this); ?>
  </div>
  <?= $this->widget('limiter', array('url' => $this->url, 'max' => $this->history->count())); ?>
  <?= $this->paginationControl($history, null, null, array('preserve' => $this->preserve)); ?>
</div>
<?php endif ?>

<div class="content">
<?php if (empty($history)): ?>
  <?= $this->translate('No history events matching the filter') ?>
</div>
<?php return; endif ?>

  <table data-base-target="_next" class="action">
    <tbody>
    <?php foreach ($history as $event): ?>
    <?php
      $stateName = 'invalid';
      $isService = isset($event->service);
      switch ($event->type) {
        case 'notify':
          $icon = 'notification';
          $title = $this->translate('Notification');
          $msg = $event->output;
          break;
        case 'comment':
          $icon = 'comment';
          $title = $this->translate('Comment');
          $msg = $event->output;
          break;
        case 'ack':
          $icon = 'acknowledgement';
          $title = $this->translate('Acknowledgement');
          $msg = $event->output;
          break;
        case 'dt_comment':
          $icon = 'in_downtime';
          $title = $this->translate('In Downtime');
          $msg = $event->output;
          break;
        case 'flapping':
          $icon = 'flapping';
          $title = $this->translate('Flapping');
          $msg = $event->output;
          break;
        case 'hard_state':
          $icon = $isService ? 'service' : 'host';
          $msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $event->output;
          $stateName = (
            $isService
              ? strtolower($this->util()->getServiceStateName($event->state))
              : strtolower($this->util()->getHostStateName($event->state))
          );
          $title = strtoupper($stateName); // TODO: Should be translatable!
          break;
        case 'soft_state':
          $icon = 'softstate';
          $msg = '[ ' . $event->attempt . '/' . $event->max_attempts . ' ] ' . $event->output;
          $stateName = (
            $isService
              ? strtolower($this->util()->getServiceStateName($event->state))
              : strtolower($this->util()->getHostStateName($event->state))
          );
          $title = strtoupper($stateName); // TODO: Should be translatable!
          break;
        case 'dt_start':
          $icon = 'downtime_start';
          $title = $this->translate('Downtime Start');
          $msg = $event->output;
          break;
        case 'dt_end':
          $icon = 'downtime_end';
          $title = $this->translate('Downtime End');
          $msg = $event->output;
          break;
        }
      ?>
      <tr class="state <?= $stateName; ?>">
        <td class="state">
          <strong><?= $this->escape($title); ?></strong>
          <br>
          <?= date('d.m. H:i', $event->timestamp); ?>
        </td>
        <td>
        <?php if ($isService): ?>
          <a href="<?= $this->href('monitoring/show/service', array(
            'host'      => $event->host,
            'service'   => $event->service
          )); ?>">
            <?= $event->service; ?>
          </a>
          <small>
            <?= $this->translate('on') . ' ' . $event->host; ?>
          </small>
        <?php else: ?>
          <a href="<?= $this->href('monitoring/show/host', array(
            'host' => $event->host
          )); ?>">
            <?= $event->host; ?>
          </a>
        <?php endif ?>
          <br>
          <div>
            <?= $this->icon($icon . '.png', $title); ?> <?= empty($msg) ? '' : $msg; ?>
          </div>
        </td>
      </tr>
    <?php endforeach ?>
    </tbody>
  </table>
</div>
