<?= $this->tabs->render($this); ?>

<?php
$paginator = $services->paginate();
$viewHelper = $this->getHelper('MonitoringState');
$trimArea = $this->getHelper('Trim');
?>

<?php if (empty($services)): ?>
<div>
  Sorry, no services found for this search
</div>
<?php return; endif ?>

<form method="get" action="<?= $this->href('monitoring/list/services', $this->services->getAppliedFilter()->toParams()); ?>">
  <label>Sort By</label>
  <?= $this->formSelect(
          'sort',
          $this->sort,
          array('class' => 'autosubmit'),
          array(
            'service_severity' => 'Severity',
            'service_last_state_change' => 'Last state change',
            'service_last_time_unknown' => 'Last UNKNOWN',
            'service_last_time_critical' => 'Last CRITICAL',
            'service_last_time_warning' => 'Last WARNING',
            'service_last_time_ok' => 'Last OK',
            'service_description' => 'Service',
          )
      ); ?>
  <noscript>
      <button class="btn btn-small btn-default">
        <i>ICON REFRESH</i>
      </button>
  </noscript>
</form>

<?=  $this->paginationControl($paginator, null, null, array('preserve' => $this->preserve)) ?>

<table class="table table-condensed">
  <thead>
    <tr>
      <th colspan="2">Status</th>
      <th>Service</th>
      <th>Host</th>
      <th>Output</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
  <?php foreach ($services->fetchAll() as $service): ?>
    <tr>
      <td>
        <div>
          <?php if ($service->service_icon_image) : ?>
          <img src="<?= $service->service_icon_image; ?>"/>
          <?php endif; ?>
        </div>
      </td>
      <td>
        <div>
          <?php if (!$service->service_handled && $service->service_state > 0): ?>
          <a href="#" title="<?= 'Unhandled service' ?>">
            <i>{{UNHANDLED_ICON}}</i>
          </a>
          <?php endif; ?>

          <?php if ($service->service_acknowledged && !$service->service_in_downtime): ?>
          <a href="#" title="<?= 'Acknowledged' ?>">
            <i>{{ACKNOWLEDGED_ICON}}</i>
          </a>
          <?php endif; ?>

          <?php if ($service->service_is_flapping): ?>
          <a href="#" title="<?= 'Flapping' ?>">
            <i>{{FLAPPING_ICON}}</i>
          </a>
          <?php endif; ?>

          <?php if (!$service->service_notifications_enabled): ?>
          <a href="#" title="<?= 'Notifications disabled' ?>">
            <i>{{NOTIFICATIONS_DISABLED_ICON}}</i>
          </a>
          <?php endif; ?>

          <?php if ($service->service_in_downtime): ?>
          <a href="#" title="<?= 'In downtime' ?>">
            <i>{{IN_DOWNTIME_ICON}}</i>
          </a>
          <?php endif; ?>

        </div>
      </td>


      <td title="<?= $viewHelper->getStateTitle($service, 'service'); ?>">
        <div>
          <b><?= ucfirst($viewHelper->monitoringState($service, 'service')); ?></b>
          <div> Since&nbsp;
            <?= $this->timeSince($service->service_last_state_change); ?>

            <?php if ($service->service_state_type == 0): ?>
            <a href="#" title="<?= 'Soft state' ?>">
              <i>{{SOFTSTATE_ICON}}</i>
            </a>
          <?php endif; ?>
          </div>
        </div>
      </td>


      <td>
        <?php if ($service->service_last_comment !== null): ?>
        <a href="#" title="<?= 'Comments' ?>">
          <i>{{COMMENT_ICON}}</i>
        </a>
        <?php endif; ?>

        <b> <?= $service->service_display_name; ?></b>
        <br/>

        <?php if ($service->service_action_url != ""): ?>
        <a href="<?= $service->service_action_url; ?>">Action</a>
        <?php endif; ?>

        <?php if ($service->service_notes_url != ""): ?>
        <a href="<?= $service->service_notes_url; ?>">Notes</a>
        <?php endif; ?>

      </td>

      <td title="<?= $viewHelper->getStateTitle($service, 'host'); ?>">
        <?= $service->host_name; ?>

        <div>
          (<?= ucfirst($viewHelper->monitoringState($service, 'host')); ?>)
        </div>
        <span>
            <?= $service->host_address ?>
        </span>
      </td>

      <td>
        <?= $this->escape(substr(strip_tags($service->service_output), 0, 10000)); ?>
      </td>
    </tr>
  <?php endforeach; ?>
  </tbody>
</table>
