<?php
    $jsonTarget = "/json.php?file=users";
    if(debug::isFile("debug")){
        debug::log(debug::getBadge($jsonTarget, "OUVRIR LE JSON : ".$jsonTarget), "JSON chargé en arrière plan");
    } 
?>
<header class="d-flex flex-column flex-md-row align-items-md-center p-3 bg-light ">
    <h2 class="bd-title" id="content">
        <span>Administration : Utilisateurs</span>
    </h2>
</header>
<?php
echo core::filAriane(array(
    "current" => "Utilisateurs",
    "arbo" => array(
        "Administration" => NULL,
        "Utilisateurs" => "/parametre-users.html"
    )
));
?>

<?php
    json::create("users");
?>

<div style="margin-top:20px;">
    <a href="/add-user.html" style="position:absolute; right:25px; margin-top:-60px;">
    <button type="submit" class="btn btn-outline-success btn-sm">
        <?php icon::getFont(["icon" => "bi bi-file-earmark-plus"]) ?> Ajouter un utilisateur</button>
    </a>
</div>
<div>
        <table
            id="table"
            class="table-striped table-hover table-sm" 
            data-toggle="table"
            data-buttons-align="left"
            data-flat="true"
            data-url="<?php echo $jsonTarget ?>">
            <thead>
                <tr>
                    <th data-sortable="true" data-field="id" data-filter-control="input">#</th>
                    <th data-sortable="true" data-field="nom" data-filter-control="input">Nom</th>
                    <th data-sortable="true" data-field="prenom" data-filter-control="input">Prénom</th>
                    <th data-sortable="true" data-field="email" data-filter-control="select">Email</th>
                    <th data-sortable="true" data-field="googleAuthenticator" data-filter-control="select">OTP</th>
                    <th data-sortable="true" data-field="type" data-filter-control="select">Type de compte</th>
                    <th data-sortable="true" data-field="cree" data-filter-control="input">Créé</th>
                    <th data-sortable="true" data-field="last_connect" data-filter-control="input">Dernière connexion</th>
                    <th data-sortable="true" data-field="actif" data-filter-control="select">Actif</th>
                    <th data-field="id" data-formatter="selectUser"></th>
                </tr>
            </thead>
        </table> 
</div>

<script>
        function selectUser(value, row) { 
            return '<a href="/user-' + row.id + '.html"><button type="submit" class="btn btn-outline-primary btn-sm">Administrer</button></a>';

        }
</script>

