<?php
use Icinga\Module\Monitoring\Object\Host;

if (! $this->compact): ?>
<div class="controls">
    <?= $this->tabs ?>
    <?= $this->paginator ?>
    <div class="sort-controls-container">
        <?= $this->limiter ?>
        <?= $this->sortBox ?>
    </div>
    <?= $this->filterEditor ?>
</div>
<?php endif ?>
<div class="content">
<?php if (! $hosts->hasResult()): ?>
    <p><?= $this->translate('No hosts found matching the filter.') ?></p>
</div>
<?php return; endif ?>
    <table data-base-target="_next"
           class="table-row-selectable state-table multiselect"
           data-icinga-multiselect-url="<?= $this->href('monitoring/hosts/show') ?>"
           data-icinga-multiselect-controllers="<?= $this->href("monitoring/hosts") ?>"
           data-icinga-multiselect-data="host">
    <tbody>
    <?php foreach($hosts->peekAhead($this->compact) as $host):
        $hostStateName = Host::getStateText($host->host_state);
        $hostLink = $this->href('monitoring/host/show', array('host' => $host->host_name)); ?>
        <tr>
            <td class="state-col state-<?= $hostStateName ?><?= $host->host_handled ? ' handled' : '' ?>">
                <div class="state-label"><?= Host::getStateText($host->host_state, true) ?></div>
                <?php if ((int) $host->host_state !== 99): ?>
                    <div class="state-meta">
                        <?= $this->timeSince($host->host_last_state_change, $this->compact) ?>
                    <?php if ((int) $host->host_state > 0 && (int) $host->host_state_type === 0): ?>
                        <div><?= $this->translate('Soft', 'Soft state') ?> <?= $host->host_attempt ?></div>
                    <?php endif ?>
                    </div>
                <?php endif ?>
            </td>
            <td>
                <div class="state-header">
                    <?= $this->iconImage()->host($host) ?>
                    <?= $this->qlink(
                        $host->host_display_name,
                        $hostLink,
                        null,
                        array(
                            'title' => sprintf(
                                $this->translate('Show detailed information for host %s'),
                                $host->host_display_name
                            ),
                            'class' => 'rowaction'
                        )
                    ) ?>
                <?php if (isset($summary[$host->host_name])): ?>
                    <span class="host-services-incidents"> &#40;<?= $this->qlink(
                          sprintf(
                              $this->translatePlural(
                                  '%u unhandled service', '%u unhandled services', $summary[$host->host_name]
                              ),
                              $summary[$host->host_name]
                          ),
                          'monitoring/list/services',
                          array(
                              'host'               => $host->host_name,
                              'service_problem'    => 1,
                              'service_handled'    => 0
                          ),
                          array(
                              'title' => sprintf(
                                  $this->translatePlural(
                                      'List %s unhandled service problem on host %s',
                                      'List %s unhandled service problems on host %s',
                                      $summary[$host->host_name]
                                  ),
                                  $summary[$host->host_name],
                                  $host->host_name
                              )
                          )
                    ) ?>&#41;</span>
                <?php endif ?>
                    <span class="state-icons"><?= $this->hostFlags($host) ?></span>
                </div>
                <p class="overview-plugin-output"><?= $this->pluginOutput($this->ellipsis($host->host_output, 10000), true, $host->host_check_command) ?></p>
            </td>
        <?php foreach($this->addColumns as $col): ?>
            <td><?= $this->escape($host->$col) ?></td>
        <?php endforeach ?>
        </tr>
    <?php endforeach ?>
    </tbody>
    </table>
<?php if ($hosts->hasMore()): ?>
    <div class="action-links">
        <?= $this->qlink(
            $this->translate('Show More'),
            $this->url()->without(array('view', 'limit')),
            null,
            array(
                'class'             => 'action-link',
                'data-base-target'  => '_next'
            )
        ) ?>
    </div>
<?php endif ?>
</div>
<?php if (! $this->compact): ?>
<div class="monitoring-statusbar-ghost dont-print"></div>
<div class="monitoring-statusbar dont-print">
    <?= $this->render('list/components/hostssummary.phtml') ?>
    <?= $this->render('list/components/selectioninfo.phtml') ?>
</div>
<?php endif ?>
