<div class="controls">
  <?= $this->tabs ?>
</div>
<div class="content">
  <?php if (! $module): ?>
    <?= $this->translate('There is no such module installed.') ?>
  <?php return; endif ?>
  <?php
    $requiredMods = $module->getRequiredModules();
    $requiredLibs = $module->getRequiredLibraries();
    $restrictions = $module->getProvidedRestrictions();
    $permissions = $module->getProvidedPermissions();
    $unmetDependencies = $moduleManager->hasUnmetDependencies($module->getName());
    $isIcingadbSupported = isset($requiredMods['icingadb']);
    $state = $moduleData->enabled ? ($moduleData->loaded ? 'enabled' : 'failed') : 'disabled';
  ?>
  <table class="name-value-table">
    <tr>
      <th><?= $this->escape($this->translate('Name')) ?></th>
      <td><?= $this->escape($module->getName()) ?></td>
    </tr>
    <tr>
      <th><?= $this->translate('State') ?></th>
      <td>
        <?= $state ?>
      <?php if (isset($this->toggleForm)): ?>
        <?php if ($moduleData->enabled || ! $unmetDependencies): ?>
          <?= $this->toggleForm ?>
        <?php else: ?>
          <?= $this->icon('attention-alt', $this->translate('Module can\'t be enabled due to unmet dependencies')) ?>
        <?php endif ?>
      <?php endif ?>
      </td>
    <tr>
      <th><?= $this->escape($this->translate('Version')) ?></th>
      <td><?= $this->escape($module->getVersion()) ?></td>
    </tr>
    <?php if (isset($moduleGitCommitId) && $moduleGitCommitId !== false): ?>
      <tr>
        <th><?= $this->escape($this->translate('Git commit')) ?></th>
        <td><?= $this->escape($moduleGitCommitId) ?></td>
      </tr>
    <?php endif ?>
    <tr>
      <th><?= $this->escape($this->translate('Description')) ?></th>
      <td>
        <strong><?= $this->escape($module->getTitle()) ?></strong><br>
        <?= nl2br($this->escape($module->getDescription())) ?>
      </td>
    </tr>
    <tr>
      <th><?= $this->escape($this->translate('Dependencies')) ?></th>
      <td class="module-dependencies">
      <?php if (empty($requiredLibs) && empty($requiredMods)): ?>
          <?= $this->translate('This module has no dependencies') ?>
      <?php else: ?>
        <?php if ($unmetDependencies): ?>
          <strong class="unmet-dependencies">
            <?= $this->translate('Unmet dependencies found! Module can\'t be enabled unless all dependencies are met.') ?>
          </strong>
        <?php endif ?>
        <?php if (! empty($requiredLibs)): ?>
          <table class="name-value-table">
              <caption><?= $this->translate('Libraries') ?></caption>
          <?php foreach ($requiredLibs as $libraryName => $versionString): ?>
              <tr>
                  <th><?= $this->escape($libraryName) ?></th>
                  <td>
                  <?php if ($libraries->has($libraryName, $versionString === true ? null : $versionString)): ?>
                      <?= $versionString === true ? '*' : $this->escape($versionString) ?>
                  <?php else: ?>
                      <span class="missing"><?= $versionString === true ? '*' : $this->escape($versionString) ?></span>
                    <?php if (($library = $libraries->get($libraryName)) !== null): ?>
                      (<?= $library->getVersion() ?>)
                    <?php endif ?>
                  <?php endif ?>
                  </td>
              </tr>
          <?php endforeach ?>
          </table>
        <?php endif ?>
        <?php if (! empty($requiredMods)): ?>
          <table class="name-value-table">
              <caption><?= $this->translate('Modules') ?></caption>
          <?php foreach ($requiredMods as $moduleName => $versionString): ?>
              <?php if ($moduleName === 'monitoring' && $isIcingadbSupported && $moduleManager->has('icingadb', $requiredMods['icingadb'])) : ?>
                  <?php continue; ?>
              <?php endif ?>
              <tr>
                  <th><?= $this->escape($moduleName) ?></th>
                  <td>
                  <?php if ($moduleManager->has($moduleName, $versionString === true ? null : $versionString)): ?>
                      <?= $versionString === true ? '*' : $this->escape($versionString) ?>
                  <?php else: ?>
                      <span <?= ($moduleName === 'icingadb' && isset($requiredMods['monitoring']) && $moduleManager->has('monitoring', $requiredMods['monitoring'])) ? 'class="optional"' : 'class="missing"' ?>>
                          <?= $versionString === true ? '*' : $this->escape($versionString) ?>
                      </span>
                    <?php if (! $moduleManager->hasInstalled($moduleName)): ?>
                      (<?= $this->translate('not installed') ?>)
                    <?php else: ?>
                      (<?= $moduleManager->getModule($moduleName, false)->getVersion() ?><?= $moduleManager->hasEnabled($moduleName) ? '' : ', ' . $this->translate('disabled') ?>)
                    <?php endif ?>
                  <?php endif ?>
                  </td>
                  <?php if ($moduleName === 'monitoring' && $isIcingadbSupported) : ?>
                      <td class="or-separator"><?= $this->translate('or') ?></td>
                  <?php endif ?>
              </tr>
          <?php endforeach ?>
          </table>
        <?php endif ?>
      <?php endif ?>
      </td>
    </tr>
    <?php if (! empty($permissions)): ?>
      <tr>
        <th><?= $this->escape($this->translate('Permissions')) ?></th>
        <td>
          <?php foreach ($permissions as $permission): ?>
            <strong><?= $this->escape($permission->name) ?></strong>: <?= $this->escape($permission->description) ?><br />
          <?php endforeach ?>
        </td>
      </tr>
    <?php endif ?>
    <?php if (! empty($restrictions)): ?>
      <tr>
        <th><?= $this->escape($this->translate('Restrictions')) ?></th>
        <td>
          <?php foreach ($restrictions as $restriction): ?>
            <strong><?= $this->escape($restriction->name) ?></strong>: <?= $this->escape($restriction->description) ?><br />
          <?php endforeach ?>
        </td>
      </tr>
    <?php endif ?>
  </table>
</div>
