<?php if (! $this->compact): ?>
<div class="controls">
    <?= $this->tabs ?>
    <div class="sort-controls-container">
        <?= $this->sortBox ?>
        <a href="<?= $this->href('monitoring/list/servicegroups')->addFilter($this->filterEditor->getFilter()) ?>" 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\Servicegroup $serviceGroups */
if (! $serviceGroups->hasResult()): ?>
    <p><?= $this->translate('No service groups found matching the filter.') ?></p>
</div>
<?php return; endif ?>
<div class="group-grid">
<?php foreach ($serviceGroups as $serviceGroup): ?>
    <div class="group-grid-cell">
    <?php if ($serviceGroup->services_critical_unhandled > 0): ?>
        <?= $this->qlink(
            $serviceGroup->services_critical_unhandled,
            $this->url('monitoring/list/servicegrid')->addFilter($this->filterEditor->getFilter()),
            [
                'servicegroup_name' => $serviceGroup->servicegroup_name,
                'service_handled'   => 0,
                'service_state'     => 2
            ],
            [
                'class' => 'state-critical',
                'title' => sprintf(
                    $this->translatePlural(
                        'List %s service that is currently in state CRITICAL in service group "%s"',
                        'List %s services which are currently in state CRITICAL in service group "%s"',
                        $serviceGroup->services_critical_unhandled
                    ),
                    $serviceGroup->services_critical_unhandled,
                    $serviceGroup->servicegroup_alias
                )
            ]
        ) ?>
    <?php elseif ($serviceGroup->services_warning_unhandled > 0): ?>
        <?= $this->qlink(
            $serviceGroup->services_warning_unhandled,
            $this->url('monitoring/list/servicegrid')->addFilter($this->filterEditor->getFilter()),
            [
                'servicegroup_name' => $serviceGroup->servicegroup_name,
                'service_handled'   => 0,
                'service_state'     => 1
            ],
            [
                'class' => 'state-warning',
                'title' => sprintf(
                    $this->translatePlural(
                        'List %s service that is currently in state WARNING in service group "%s"',
                        'List %s services which are currently in state WARNING in service group "%s"',
                        $serviceGroup->services_warning_unhandled
                    ),
                    $serviceGroup->services_warning_unhandled,
                    $serviceGroup->servicegroup_alias
                )
            ]
        ) ?>
    <?php elseif ($serviceGroup->services_unknown_unhandled > 0): ?>
        <?= $this->qlink(
            $serviceGroup->services_unknown_unhandled,
            $this->url('monitoring/list/servicegrid')->addFilter($this->filterEditor->getFilter()),
            [
                'servicegroup_name' => $serviceGroup->servicegroup_name,
                'service_handled'   => 0,
                'service_state'     => 3
            ],
            [
                'class' => 'state-unknown',
                'title' => sprintf(
                    $this->translatePlural(
                        'List %s service that is currently in state UNKNOWN in service group "%s"',
                        'List %s services which are currently in state UNKNOWN in service group "%s"',
                        $serviceGroup->services_unknown_unhandled
                    ),
                    $serviceGroup->services_unknown_unhandled,
                    $serviceGroup->servicegroup_alias
                )
            ]
        ) ?>
    <?php elseif ($serviceGroup->services_critical_handled > 0): ?>
        <?= $this->qlink(
            $serviceGroup->services_critical_handled,
            $this->url('monitoring/list/servicegrid')->addFilter($this->filterEditor->getFilter()),
            [
                'servicegroup_name' => $serviceGroup->servicegroup_name,
                'service_handled'   => 1,
                'service_state'     => 2
            ],
            [
                'class' => 'state-critical handled',
                'title' => sprintf(
                    $this->translatePlural(
                        'List %s service that is currently in state CRITICAL (Acknowledged) in service group "%s"',
                        'List %s services which are currently in state CRITICAL (Acknowledged) in service group "%s"',
                        $serviceGroup->services_critical_handled
                    ),
                    $serviceGroup->services_critical_handled,
                    $serviceGroup->servicegroup_alias
                )
            ]
        ) ?>
    <?php elseif ($serviceGroup->services_warning_handled > 0): ?>
        <?= $this->qlink(
            $serviceGroup->services_warning_handled,
            $this->url('monitoring/list/servicegrid')->addFilter($this->filterEditor->getFilter()),
            [
                'servicegroup_name' => $serviceGroup->servicegroup_name,
                'service_handled'   => 1,
                'service_state'     => 1
            ],
            [
                'class' => 'state-warning handled',
                'title' => sprintf(
                    $this->translatePlural(
                        'List %s service that is currently in state WARNING (Acknowledged) in service group "%s"',
                        'List %s services which are currently in state WARNING (Acknowledged) in service group "%s"',
                        $serviceGroup->services_warning_handled
                    ),
                    $serviceGroup->services_warning_handled,
                    $serviceGroup->servicegroup_alias
                )
            ]
        ) ?>
    <?php elseif ($serviceGroup->services_unknown_handled > 0): ?>
        <?= $this->qlink(
            $serviceGroup->services_unknown_handled,
            $this->url('monitoring/list/servicegrid')->addFilter($this->filterEditor->getFilter()),
            [
                'servicegroup_name' => $serviceGroup->servicegroup_name,
                'service_handled'   => 1,
                'service_state'     => 3
            ],
            [
                'class' => 'state-unknown handled',
                'title' => sprintf(
                    $this->translatePlural(
                        'List %s service that is currently in state UNKNOWN (Acknowledged) in service group "%s"',
                        'List %s services which are currently in state UNKNOWN (Acknowledged) in service group "%s"',
                        $serviceGroup->services_unknown_handled
                    ),
                    $serviceGroup->services_unknown_handled,
                    $serviceGroup->servicegroup_alias
                )
            ]
        ) ?>
    <?php elseif ($serviceGroup->services_pending > 0): ?>
        <?= $this->qlink(
            $serviceGroup->services_pending,
            $this->url('monitoring/list/servicegrid')->addFilter($this->filterEditor->getFilter()),
            [
                'servicegroup_name' => $serviceGroup->servicegroup_name,
                'service_state'     => 99
            ],
            [
                'class' => 'state-pending',
                'title' => sprintf(
                    $this->translatePlural(
                        'List %s service that is currenlty in state PENDING in service group "%s"',
                        'List %s services which are currently in state PENDING in service group "%s"',
                        $serviceGroup->services_pending
                    ),
                    $serviceGroup->services_pending,
                    $serviceGroup->servicegroup_alias
                )
            ]
        ) ?>
    <?php elseif ($serviceGroup->services_ok > 0): ?>
        <?= $this->qlink(
            $serviceGroup->services_ok,
            $this->url('monitoring/list/servicegrid')->addFilter($this->filterEditor->getFilter()),
            [
                'servicegroup_name' => $serviceGroup->servicegroup_name,
                'service_state'     => 0
            ],
            [
                'class' => 'state-ok',
                'title' => sprintf(
                    $this->translatePlural(
                        'List %s service that is currently in state OK in service group "%s"',
                        'List %s services which are currently in state OK in service group "%s"',
                        $serviceGroup->services_ok
                    ),
                    $serviceGroup->services_ok,
                    $serviceGroup->servicegroup_alias
                )
            ]
        ) ?>
    <?php else: ?>
        <div class="state-none">
            0
        </div>
    <?php endif ?>
    <?= $this->qlink(
        $serviceGroup->servicegroup_alias,
        $this->url('monitoring/list/servicegrid')->addFilter($this->filterEditor->getFilter()),
        ['servicegroup_name' => $serviceGroup->servicegroup_name],
        [
            'title' => sprintf(
                $this->translate('List all services in the group "%s"'),
                $serviceGroup->servicegroup_alias
            )
        ]
    ) ?>
    </div>
<?php endforeach ?>
</div>
</div>
