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

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

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

<!-- Select filters -->
<div class="row">
  <div class="col col-md-12 col-lg-8 mx-auto select-filters">
    <form class="form-horizontal" name="selectFilters" method="post">
      <div class="row">
      
        <div class="col-md-4">
          <select class="form-control custom-select" name="tag" id="tag" onchange="this.form.submit()">
          <?php foreach ($viewModel->tagOptions() as $key => $value) {
            echo ($key === $viewModel->tag()) ?
              '<option value="' . xss($key) . '" selected>' . xss($value) . '</option>' :
              '<option value="' . xss($key) . '">' . xss($value) . '</option>';
          } ?>
          </select>
        </div>

        <div class="col-md-4">
          <select class="form-control custom-select" name="type" id="type" onchange="this.form.submit()">
          <?php
            foreach ($viewModel->typeOptions() as $key => $value) {
              echo ($key === $viewModel->type()) ?
                '<option value="' . xss($key) . '" selected>' . xss($value) . '</option>' :
                '<option value="' . xss($key) . '">' . xss($value) . '</option>';
            }
          ?>
          </select>
        </div>

        <div class="col-md-4">
          <select class="form-control custom-select" name="onlineStatus" id="onlineStatus" onchange="this.form.submit()">
          <?php
            foreach ($viewModel->statusOptions() as $key => $value) {
              echo ($key === $viewModel->onlineStatus()) ?
                '<option value="' . xss($key) . '" selected>' . xss($value) . '</option>' :
                '<option value="' . xss($key) . '">' . xss($value) . '</option>';
            }
          ?>
          </select>
        </div>

      </div>
    </form>
  </div>
</div>

<?php if ($pagination ?? null): ?>
<div class="row">
  <div class="col d-flex justify-content-end pagination-top clearfix">
    <?php echo $pagination; ?>
  </div>
</div>
<?php endif; ?>

<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-left add-content" type="submit" formaction="<?php echo TFISH_ADMIN_URL . 'content/'; ?>"><?php echo TFISH_ADD_CONTENT; ?></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>
      <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_TYPE; ?></th>
        <th><?php echo TFISH_TITLE; ?></th>
        <th class="d-none d-md-table-cell d-lg-table-cell d-xl-table-cell"><?php echo TFISH_SUBMISSION_TIME; ?></th>
        <th class="d-none d-md-table-cell d-lg-table-cell d-xl-table-cell"><?php echo TFISH_COUNTER; ?></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($viewModel->listTypes()[$row['type']]); ?></td>
        <td><a href="<?php echo TFISH_URL . '?id=' . xss($row['id']); ?>"><?php echo xss($row['title']); ?></a></td>
        <td class="d-none d-md-table-cell d-lg-table-cell d-xl-table-cell"><?php echo xss(\date($viewModel->dateFormat(), (int) $row['submissionTime'])); ?></td>
        <td class="d-none d-md-table-cell d-lg-table-cell d-xl-table-cell"><?php echo xss($row['counter']); ?></td>
        <?php if ($row['onlineStatus']): ?>
        <td class="text-center"><a class="text-success" href="<?php echo TFISH_ADMIN_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_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_URL . 'content/'; ?>?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_URL; ?>?action=confirmDelete&amp;id=<?php echo xss($row['id']); ?>"><i class="fas fa-trash-alt"></i></a></td>
        <?php unset($row); ?>
      </tr>
    <?php endforeach; ?>
    </tbody>
  </table>
  </div>
</div>

<?php if ($pagination ?? null): ?>
<div class="row">
  <div class="col d-flex justify-content-end pagination-bottom clearfix">
    <?php echo $pagination; ?>
  </div>
</div>
<?php endif; ?>

</div>