<?php declare(strict_types=1); ?>

<?php $groups = $viewModel->userGroupList(); ?>

<!-- Container -->
<div class="container">

<div class="row">
  <div class="col">
    <h1 class="page-title"><?php echo xss($viewModel->pageTitle()); ?></h1>
  </div>
</div>

<div class="row">
  <div class="col form-buttons clearfix">
    <form method="post">
      <input type="hidden" name="token" value="<?php echo xss($_SESSION['token']); ?>" />
      <button class="btn btn-primary float-start add-content" type="submit" formaction="<?php echo TFISH_ADMIN_USER_URL . 'edit/'; ?>"><?php echo TFISH_ADD; ?></button>
    </form>
  </div>
</div>

<div class="row">
  <div class="col main-content clearfix">
  <table class="table table-bordered table-striped table-hover text-left">
    <thead class="table-success">
      <tr>
        <th class="d-none d-md-table-cell d-lg-table-cell d-xl-table-cell"><?php echo TFISH_ID; ?></th>
        <th><?php echo TFISH_EMAIL; ?></th>
        <th><?php echo TFISH_USER_GROUP; ?></th>
        <th class="d-none d-md-table-cell d-lg-table-cell d-xl-table-cell"><?php echo TFISH_USER_YUBIKEY_ID; ?></th>
        <th class="d-none d-md-table-cell d-lg-table-cell d-xl-table-cell"><?php echo TFISH_USER_YUBIKEY_ID . '2'; ?></th>
        <th class="d-none d-md-table-cell d-lg-table-cell d-xl-table-cell"><?php echo TFISH_USER_YUBIKEY_ID . '3'; ?></th>
        <th class="d-none d-md-table-cell d-lg-table-cell d-xl-table-cell"><?php echo TFISH_USER_LOGIN_ERRORS; ?></th>
        <th class="text-center"><?php echo TFISH_ONLINE; ?></th>
        <th colspan="2" class="text-center"><?php echo TFISH_ACTION; ?></th>
      </tr>
      </thead>
    <tbody>
    <?php foreach($viewModel->contentList() as &$row): ?>
      <tr>
        <td class="d-none d-md-table-cell d-lg-table-cell d-xl-table-cell"><?php echo xss($row['id']); ?></td>
        <td><?php echo xss($row['adminEmail']); ?></td>
        <td><?php echo xss($groups[$row['userGroup']]); ?></td>
        <td class="d-none d-md-table-cell d-lg-table-cell d-xl-table-cell"><?php echo xss($row['yubikeyId']); ?></td>
        <td class="d-none d-md-table-cell d-lg-table-cell d-xl-table-cell"><?php echo xss($row['yubikeyId2']); ?></td>
        <td class="d-none d-md-table-cell d-lg-table-cell d-xl-table-cell"><?php echo xss($row['yubikeyId3']); ?></td>
        <td class="d-none d-md-table-cell d-lg-table-cell d-xl-table-cell"><?php echo xss($row['loginErrors']); ?></td>
        <?php if ((int) $row['userGroup'] === 1): ?>
        <td class="text-center"><i class="fas fa-check"></i></td>
        <td class="text-center"><a href="<?php echo TFISH_ADMIN_USER_URL . 'edit/'; ?>?action=edit&amp;id=<?php echo xss($row['id']); ?>"><i class="fas fa-edit"></i></a></td>
        <td class="text-center"><i class="fas fa-trash-alt"></a></td>
        <?php else: ?>
        <?php if ($row['onlineStatus']): ?>
        <td class="text-center"><a class="text-success" href="<?php echo TFISH_ADMIN_USER_URL; ?>?action=toggle&amp;id=<?php echo xss($row['id']); ?>"><i class="fas fa-check"></i></a></td>
        <?php else: ?>
        <td class="text-center"><a class="text-danger" href="<?php echo TFISH_ADMIN_USER_URL; ?>?action=toggle&amp;id=<?php echo xss($row['id']); ?>"><i class="fas fa-times"></i></a></td>
        <?php endif; ?>
        <td class="text-center"><a href="<?php echo TFISH_ADMIN_USER_URL . 'edit/'; ?>?action=edit&amp;id=<?php echo xss($row['id']); ?>"><i class="fas fa-edit"></i></a></td>
        <td class="text-center"><a href="<?php echo TFISH_ADMIN_USER_URL; ?>?action=confirmDelete&amp;id=<?php echo xss($row['id']); ?>"><i class="fas fa-trash-alt"></i></a></td>
        <?php endif; ?>
        <?php unset($row); ?>
      </tr>
    <?php endforeach; ?>
    </tbody>
  </table>
  </div>
</div>

</div>