<?php

use Icinga\Util\Format;
use Icinga\Module\Director\StartupLogRenderer;

?><div class="controls">
<?= $this->tabs ?>
<h1><?= $this->escape($this->title) ?></h1>
</div>

<div class="content">
<table class="name-value-table">
 <tr>
  <th><?= $this->translate('Deployment time') ?></th>
  <td><?= $deployment->start_time ?></td>
 </tr>
 <tr>
  <th><?= $this->translate('Sent to') ?></th>
  <td><?= $deployment->peer_identity ?></td>
 </tr>
 <tr>
  <th><?= $this->translate('Configuration') ?></th>
  <td><?= $this->qlink(
    sprintf(
        $this->translate('%d files'),
        $this->config->getFileCount()
    ),
    'director/config/files',
    array(
        'checksum'      => $config_checksum,
        'deployment_id' => $deployment->id
    )
) ?>, <?= sprintf(
    $this->translate('%d objects, %d templates, %d apply rules'),
    $config->getObjectCount(),
    $config->getTemplateCount(),
    $config->getApplyCount()
  )?>, <?= Format::bytes($config->getSize()) ?></td>
 </tr>
 <tr>
  <th><?= $this->translate('Duration') ?></th>
  <td><?= sprintf(
      $this->translate('Rendered in %0.2fs, deployed in %0.2fs'),
      $config->getDuration() / 1000,
      $deployment->duration_dump / 1000
  ) ?></td>
 </tr>
 <tr>
  <th><?= $this->translate('Stage name') ?></th>
  <td><?= $deployment->stage_name ?></td>
 </tr>
 <tr>
  <th><?= $this->translate('Startup') ?></th>
  <td><?php

if ($deployment->startup_succeeded === null) {
    if ($deployment->stage_collected === null) {
        echo $this->translate('Unknown, still waiting for config check outcome') . ' ' . $this->icon('spinner');
    } else {
        echo $this->translate('Unknown, failed to collect related information') . ' ' . $this->icon('help');
    }
} elseif ($deployment->startup_succeeded === 'y') {
    echo '<div style="color: green">';
    echo $this->translate('Succeeded') . ' ' . $this->icon('ok');
    echo '</div>';
} else {
    echo '<div style="color: red">';
    echo $this->translate('Failed') . ' ' . $this->icon('cancel');
    echo '</div>';
}

  ?></td>
 </tr>
</table>
<?php if ($deployment->startup_succeeded !== null): ?>
<h2>Startup log</h2>
<pre class="logfile">
<?= StartupLogRenderer::beautify($deployment, $this) ?>
</pre>
<?php endif ?>
</div>
