<?php

use Fisharebest\Webtrees\Http\RequestHandlers\ControlPanel;
use Fisharebest\Webtrees\Http\RequestHandlers\UserListData;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\View;

/**
 * @var string $filter
 * @var string $title
 */

?>

<?= view('components/breadcrumbs', ['links' => [route(ControlPanel::class) => I18N::translate('Control panel'), $title]]) ?>

<h1><?= $title ?></h1>

<table class="table table-sm table-bordered table-user-list"
    <?= view('lists/datatables-attributes') ?>
>
    <thead>
        <tr>
            <th><?= I18N::translate('Edit') ?></th>
            <th><!-- user id --></th>
            <th><?= I18N::translate('Username') ?></th>
            <th><?= I18N::translate('Real name') ?></th>
            <th><?= I18N::translate('Email address') ?></th>
            <th><?= I18N::translate('Language') ?></th>
            <th><!-- date registered --></th>
            <th><?= I18N::translate('Date registered') ?></th>
            <th><!-- last login --></th>
            <th><?= I18N::translate('Last signed in') ?></th>
            <th><?= I18N::translate('Verified') ?></th>
            <th><?= I18N::translate('Approved') ?></th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

<?php View::push('javascript') ?>
<script>
  $(".table-user-list").dataTable({
    processing:          true,
    serverSide:          true,
    ajax:                {
      url: "<?= e(route(UserListData::class)) ?>"
    },
    autoWidth:           false,
    sorting:             [[2, "asc"]],
    columns:             [
      /* details           */ {sortable: false},
      /* user-id           */ {visible: false},
      /* user_name         */ null,
      /* real_name         */ null,
      /* email             */ null,
      /* language          */ null,
      /* registered (sort) */ {visible: false},
      /* registered        */ {dataSort: 6},
      /* last_login (sort) */ {visible: false},
      /* last_login        */ {dataSort: 8},
      /* verified          */ null,
      /* approved          */ null
    ]
  }).fnFilter("<?= e($filter) ?>"); // Pre-fill the search box
</script>
<?php View::endpush() ?>
