<?php if ($this->compact): ?>
<div class="content">
<?php else: ?>
<div class="controls">
  <?= $this->tabs ?>
  <?= $this->widget('limiter')->setMaxLimit(count($hostgroups)); ?>
  <?= $this->paginationControl($hostgroups, null, null, array('preserve' => $this->preserve)); ?>
</div>
<div class="content">
  <?= $this->filterEditor; ?>
<?php endif ?>
  <?php
    if (count($hostgroups) === 0) {
      echo $this->translate('No host groups matching the filter');
      echo '</div>';
      return;
    }
  ?>
  <table class="groupview" data-base-target="_next">
    <thead>
      <th style="text-align: left;"><?= $this->translate('Last Problem'); ?></th>
      <th style="text-align: left;"><?= $this->translate('Host Group'); ?></th>
      <th><?= $this->translate('Total Services'); ?></th>
      <th colspan="5"><?= $this->translate('Service States'); ?></th>
    </thead>
    <tbody>
    <?php foreach ($hostgroups as $h): ?>
      <tr href="<?= $this->href('monitoring/list/services', array('hostgroup' => $h->hostgroup)); ?>">
       <?php if ($h->services_critical_last_state_change_unhandled): ?>
        <td class="state change critical">
          <strong><?= $this->translate('CRITICAL'); ?></strong>
          <br>
          <?= $this->prefixedTimeSince($h->services_critical_last_state_change_unhandled); ?>
        </td>
       <?php elseif ($h->services_unknown_last_state_change_unhandled): ?>
        <td class="state change unknown">
          <strong><?= $this->translate('UNKNOWN'); ?></strong>
          <br>
          <?= $this->prefixedTimeSince($h->services_unknown_last_state_change_unhandled); ?>
        </td>
       <?php elseif ($h->services_warning_last_state_change_unhandled): ?>
        <td class="state change warning">
          <strong><?= $this->translate('WARNING'); ?></strong>
          <br>
          <?= $this->prefixedTimeSince($h->services_warning_last_state_change_unhandled); ?>
        </td>
       <?php elseif ($h->services_critical_last_state_change_handled): ?>
        <td class="state change critical handled">
          <strong><?= $this->translate('CRITICAL'); ?></strong>
          <br>
          <?= $this->prefixedTimeSince($h->services_critical_last_state_change_handled); ?>
        </td>
       <?php elseif ($h->services_unknown_last_state_change_handled): ?>
        <td class="state change unknown handled">
          <strong><?= $this->translate('UNKNOWN'); ?></strong>
          <br>
          <?= $this->prefixedTimeSince($h->services_unknown_last_state_change_handled); ?>
        </td>
       <?php elseif ($h->services_warning_last_state_change_handled): ?>
        <td class="state change warning handled">
          <strong><?= $this->translate('WARNING'); ?></strong>
          <br>
          <?= $this->prefixedTimeSince($h->services_warning_last_state_change_handled); ?>
        </td>
       <?php elseif ($h->services_ok_last_state_change): ?>
        <td class="state change ok">
          <strong><?= $this->translate('OK'); ?></strong>
          <br>
          <?= $this->prefixedTimeSince($h->services_ok_last_state_change); ?>
        </td>
       <?php else: ?>
        <td class="state change pending">
          <strong><?= $this->translate('PENDING'); ?></strong>
          <br>
          <?= $this->prefixedTimeSince($h->services_pending_last_state_change); ?>
        </td>
       <?php endif ?>
        <td>
          <a href="<?= $this->href('monitoring/list/services', array('hostgroup' => $h->hostgroup)); ?>">
            <?= $h->hostgroup; ?>
          </a>
        </td>
        <td class="services-total">
          <?= $h->services_total; ?>
        </td>
        <td class="state">
        <?php if ($h->services_ok): ?>
          <span class="state ok">
            <a href="<?= $this->href(
              'monitoring/list/services',
              array(
                'service_state' => 0,
                'hostgroup'     => $h->hostgroup,
                'sort'          => 'service_severity'
              )
            ); ?>" title="<?= $this->translate('Services OK'); ?>">
              <?= $h->services_ok; ?>
            </a>
          </span>
        <?php else: ?>
          <span class="no-state">
            -
          </span>
        <?php endif ?>
        </td>
        <td class="state">
        <?php if ($h->services_critical_unhandled): ?>
          <span class="state critical">
            <a href="<?= $this->href(
              'monitoring/list/services',
              array(
                'service_state'         => 2,
                'service_acknowledged'  => 0,
                'service_in_downtime'   => 0,
                'host_problem'          => 0,
                'hostgroup'             => $h->hostgroup,
                'sort'                  => 'service_severity'
              )
            ); ?>" title="<?= $this->translate('Services CRITICAL Unhandled'); ?>">
              <?= $h->services_critical_unhandled; ?>
            </a>
        <?php endif ?>
          <?php if ($h->services_critical_handled): ?>
            <span class="state critical handled">
              <a href="<?= $this->href(
                'monitoring/list/services',
                array(
                  'service_state'     => 2,
                  'service_handled'   => 1,
                  'hostgroup'         => $h->hostgroup,
                  'sort'              => 'service_severity'
                )
              ); ?>" title="<?= $this->translate('Services CRITICAL Handled'); ?>">
                <?= $h->services_critical_handled; ?>
              </a>
            </span>
          <?php endif ?>
        <?php if ($h->services_critical_unhandled): ?>
          </span>
        <?php endif ?>
        <?php if (! $h->services_critical_unhandled && !$h->services_critical_handled): ?>
          <span class="no-state">
            -
          </span>
        <?php endif ?>
        </td>
        <td class="state">
        <?php if ($h->services_unknown_unhandled): ?>
          <span class="state unknown">
            <a href="<?= $this->href(
              'monitoring/list/services',
              array(
                'service_state'         => 3,
                'service_acknowledged'  => 0,
                'service_in_downtime'   => 0,
                'host_problem'          => 0,
                'hostgroup'             => $h->hostgroup,
                'sort'                  => 'service_severity'
              )
            ); ?>" title="<?= $this->translate('Services UNKNOWN Unhandled'); ?>">
              <?= $h->services_unknown_unhandled; ?>
            </a>
        <?php endif ?>
          <?php if ($h->services_unknown_handled): ?>
            <span class="state unknown handled">
              <a href="<?= $this->href(
                'monitoring/list/services',
                array(
                  'service_state'     => 3,
                  'service_handled'   => 1,
                  'hostgroup'         => $h->hostgroup,
                  'sort'              => 'service_severity'
                )
              ); ?>" title="<?= $this->translate('Services UNKNOWN Handled'); ?>">
                <?= $h->services_unknown_handled; ?>
              </a>
            </span>
          <?php endif ?>
        <?php if ($h->services_unknown_unhandled): ?>
          </span>
        <?php endif ?>
        <?php if (! $h->services_unknown_unhandled && !$h->services_unknown_handled): ?>
          <span class="no-state">
            -
          </span>
        <?php endif ?>
        </td>
        <td class="state">
        <?php if ($h->services_warning_unhandled): ?>
          <span class="state warning">
            <a href="<?= $this->href(
              'monitoring/list/services',
              array(
                'service_state'         => 1,
                'service_acknowledged'  => 0,
                'service_in_downtime'   => 0,
                'host_problem'          => 0,
                'hostgroup'             => $h->hostgroup,
                'sort'                  => 'service_severity'
              )
            ); ?>" title="<?= $this->translate('Services WARNING Unhandled'); ?>">
              <?= $h->services_warning_unhandled; ?>
            </a>
        <?php endif ?>
          <?php if ($h->services_warning_handled): ?>
            <span class="state warning handled">
              <a href="<?= $this->href(
                'monitoring/list/services',
                array(
                    'service_state'     => 1,
                    'service_handled'   => 1,
                    'hostgroup'         => $h->hostgroup,
                    'sort'              => 'service_severity'
                )
              ); ?>" title="<?= $this->translate('Services WARNING Handled'); ?>">
                <?= $h->services_warning_handled; ?>
              </a>
            </span>
          <?php endif ?>
        <?php if ($h->services_warning_unhandled): ?>
          </span>
        <?php endif ?>
        <?php if (! $h->services_warning_unhandled && !$h->services_warning_handled): ?>
          <span class="no-state">
            -
          </span>
        <?php endif ?>
        </td>
        <td class="state">
        <?php if ($h->services_pending): ?>
          <span class="state pending">
            <a href="<?= $this->href(
              'monitoring/list/services',
              array(
                'service_state' => 99,
                'hostgroup'     => $h->hostgroup,
                'sort'          => 'service_severity'
              )
            ); ?>" title="<?= $this->translate('Services PENDING'); ?>">
              <?= $h->services_pending; ?>
            </a>
          </span>
        <?php else: ?>
          <span class="no-state">
            -
          </span>
        <?php endif ?>
        </td>
      </tr>
    <?php endforeach ?>
    </tbody>
  </table>
</div>