<?= $this->render('show/components/header.phtml') ?>
<?php
$history->limit(10);
$hhistory = $this->history->paginate();

?>
<?php if (empty($hhistory)): ?>
There are no matching history entries right now
<?php else: ?>
<?= $this->paginationControl($hhistory, null, null, array('preserve' => $preserve)); ?>

<table class="table table-condensed">
  <tbody>
  <?php foreach ($hhistory as $event): ?>
  <?php
  if ($event->object_type == 'host') {
      $states = array('up', 'down', 'unreachable', 'unknown', 99 => 'pending', null => 'pending');
  } else {
      $states = array('ok', 'warning', 'critical', 'unknown', 99 => 'pending', null => 'pending');
  }

  ?>
    <tr>
      <td><?= date('d.m. H:i', $event->timestamp ) ?></td>

      <? if (! $object): ?>
      <td><?= $this->escape($event->host_name) ?></td>
      <? endif ?>

      <? if (! $object instanceof Monitoring\Object\Service): ?>
      <td>
        <? if ($object): ?>
        <a href="<?= $this->href('monitoring/show/service',array(
                'host'    => $object->host_name,
                'service' => $event->service_description
            )); ?>"><?php $event->service_description; ?></a>
        </a>
        <? else: ?>
        <?= $this->escape($event->service_description) ?>
        <? endif ?>
      </td>
<? endif ?>
      <td>
        <?php

            switch ($event->type) {
                case 'notify':
                    echo 'NOTIFICATION_ICON';
                    break;
                case 'comment':
                    echo 'COMMENT_ICON';
                    break;
                case 'ack':
                    echo 'ACKNOWLEDGEMENT_ICON';
                    break;
                case 'dt_comment':
                    echo 'IN_DOWNTIME_ICON';
                    break;
                case 'flapping':
                    echo 'FLAPPING_ICON';
                    break;
                case 'hard_state':
                    echo 'HARDSTATE_ICON';
                    break;
                case 'soft_state':
                    echo 'SOFTSTATE_ICON';
                    break;
                case 'dt_start':
                    echo 'DOWNTIME_START_ICON';
                    echo ' Downtime start';
                    break;
                case 'dt_end':
                    echo 'DOWNTIME_END_ICON';
                    echo ' Downtime end';
                    break;
            }
      ?>
      <? if ($event->attempt !== null): ?>
      [ <?= $event->attempt ?>/<?=$event->max_attempts ?> ]
      <? endif ?>
      </td>
    </tr>
<? endforeach ?>
  </tbody>
</table>
<? endif ?>
