<?php if (! $this->compact): ?>
<div class="controls">
    <?= $this->tabs ?>
    <div class="sort-controls-container">
        <?= $this->sortBox ?>
        <a href="<?= $this->href('monitoring/list/hostgroups') ?>" class="grid-toggle-link"
           title="<?= $this->translate('Toogle grid view mode') ?>">
            <?= $this->icon('th-list', null, ['class' => '-inactive']) ?>
            <?= $this->icon('th-thumb-empty', null, ['class' => '-active']) ?>
        </a>
    </div>
    <?= $this->filterEditor ?>
</div>
<?php endif ?>
<div class="content" data-base-target="_next">
<?php /** @var \Icinga\Module\Monitoring\DataView\Hostgroup $hostGroups */
if (! $hostGroups->hasResult()): ?>
    <p><?= $this->translate('No host groups found matching the filter.') ?></p>
</div>
<?php return; endif ?>
<div class="group-grid">
<?php foreach ($hostGroups as $hostGroup): ?>
    <div class="group-grid-cell">
    <?php if ($hostGroup->hosts_down_unhandled > 0): ?>
        <?= $this->qlink(
            $hostGroup->hosts_down_unhandled,
            'monitoring/list/hosts',
            [
                'hostgroup_name'    => $hostGroup->hostgroup_name,
                'host_handled'      => 0,
                'host_state'        => 1
            ],
            [
                'class' => 'state-down',
                'title' => sprintf(
                    $this->translatePlural(
                        'List %u host that is currently in state DOWN in the host group "%s"',
                        'List %u hosts which are currently in state DOWN in the host group "%s"',
                        $hostGroup->hosts_down_unhandled
                    ),
                    $hostGroup->hosts_down_unhandled,
                    $hostGroup->hostgroup_alias
                )
            ]
        ) ?>
    <?php elseif ($hostGroup->hosts_unreachable_unhandled > 0): ?>
        <?= $this->qlink(
            $hostGroup->hosts_unreachable_unhandled,
            'monitoring/list/hosts',
            [
                'hostgroup_name'    => $hostGroup->hostgroup_name,
                'host_handled'      => 0,
                'host_state'        => 2
            ],
            [
                'class' => 'state-unreachable',
                'title' => sprintf(
                    $this->translatePlural(
                        'List %u host that is currently in state UNREACHABLE in the host group "%s"',
                        'List %u hosts which are currently in state UNREACHABLE in the host group "%s"',
                        $hostGroup->hosts_unreachable_unhandled
                    ),
                    $hostGroup->hosts_unreachable_unhandled,
                    $hostGroup->hostgroup_alias
                )
            ]
        ) ?>
    <?php elseif ($hostGroup->hosts_down_handled > 0): ?>
        <?= $this->qlink(
            $hostGroup->hosts_down_handled,
            'monitoring/list/hosts',
            [
                'hostgroup_name'    => $hostGroup->hostgroup_name,
                'host_handled'      => 1,
                'host_state'        => 1
            ],
            [
                'class' => 'state-down handled',
                'title' => sprintf(
                    $this->translatePlural(
                        'List %u host that is currently in state DOWN (Acknowledged) in the host group "%s"',
                        'List %u hosts which are currently in state DOWN (Acknowledged) in the host group "%s"',
                        $hostGroup->hosts_down_handled
                    ),
                    $hostGroup->hosts_down_handled,
                    $hostGroup->hostgroup_alias
                )
            ]
        ) ?>
    <?php elseif ($hostGroup->hosts_unreachable_handled > 0): ?>
        <?= $this->qlink(
            $hostGroup->hosts_unreachable_handled,
            'monitoring/list/hosts',
            [
                'hostgroup_name'    => $hostGroup->hostgroup_name,
                'host_handled'      => 0,
                'host_state'        => 2
            ],
            [
                'class' => 'state-unreachable handled',
                'title' => sprintf(
                    $this->translatePlural(
                        'List %u host that is currently in state UNREACHABLE (Acknowledged) in the host group "%s"',
                        'List %u hosts which are currently in state UNREACHABLE (Acknowledged) in the host group "%s"',
                        $hostGroup->hosts_unreachable_handled
                    ),
                    $hostGroup->hosts_unreachable_handled,
                    $hostGroup->hostgroup_alias
                )
            ]
        ) ?>
    <?php elseif ($hostGroup->hosts_pending > 0): ?>
        <?= $this->qlink(
            $hostGroup->hosts_pending,
            'monitoring/list/hosts',
            [
                'hostgroup_name'    => $hostGroup->hostgroup_name,
                'host_state'        => 99
            ],
            [
                'class' => 'state-pending',
                'title' => sprintf(
                    $this->translatePlural(
                        'List %u host that is currently in state PENDING in the host group "%s"',
                        'List %u hosts which are currently in state PENDING in the host group "%s"',
                        $hostGroup->hosts_pending
                    ),
                    $hostGroup->hosts_pending,
                    $hostGroup->hostgroup_alias
                )
            ]
        ) ?>
    <?php elseif ($hostGroup->hosts_up > 0): ?>
        <?= $this->qlink(
            $hostGroup->hosts_up,
            'monitoring/list/hosts',
            [
                'hostgroup_name'    => $hostGroup->hostgroup_name,
                'host_state'        => 0
            ],
            [
                'class' => 'state-up',
                'title' => sprintf(
                    $this->translatePlural(
                        'List %u host that is currently in state UP in the host group "%s"',
                        'List %u hosts which are currently in state UP in the host group "%s"',
                        $hostGroup->hosts_up
                    ),
                    $hostGroup->hosts_up,
                    $hostGroup->hostgroup_alias
                )
            ]
        ) ?>
    <?php else: ?>
        <div class="state-none">
            0
        </div>
    <?php endif ?>
        <?= $this->qlink(
            $hostGroup->hostgroup_alias,
            'monitoring/list/hosts',
            ['hostgroup_name' => $hostGroup->hostgroup_name],
            [
                'title' => sprintf(
                    $this->translate('List all hosts in the group "%s"'),
                    $hostGroup->hostgroup_alias
                )
            ]
        ) ?>
    </div>
<?php endforeach ?>
</div>
</div>
