<?php
    json::create("lotterys");

    $jsonTarget = "/json.php?file=lotterys";
    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>Listes des tirages au sort</span>
</h2>
<?php if(access::ifAccesss("add-lottery")){ ?>
<div class="fix-container-button-nav">
    <a href="/add-lottery.html"><button type="submit" class="btn btn-outline-success btn-sm"><?php icon::getFont(["icon" => "bi bi-file-earmark-plus"]) ?> Ajouter un tirage au sort</button></a>   
</div>
<?php } ?>
</header>
<?php   
        echo core::filAriane(array(
            "current" => "Listes des tirages au sort", 
            "arbo" => array( 
                "Tirages au sort" => NULL,
                "Listes des tirages au sort" => "/lotterys.html")
        )); 
?>
<div>
    <table
        id="table"
        class="table-striped table-hover table-sm" 
        data-page-size="25"
        data-toggle="table"
        data-show-columns="true"
        data-search="true"
        data-buttons-align="left"
        data-pagination="true"
        data-filter-control="true"
        data-flat="true"
        data-sort-name="cree"
        data-sort-order="desc"
        data-url="<?php echo $jsonTarget ?>">
        <thead>
            <tr>
                <th data-sortable="true" data-field="id" data-filter-control="input" data-width="15">#</th>
                <th data-sortable="true" data-field="titre" data-filter-control="input">Titre</th>
                <th data-sortable="true" data-field="m_inscrits" data-filter-control="input" data-width="50">Nb. Inscrit</th>
                <th data-sortable="true" data-field="m_eligible" data-filter-control="input" data-width="50">Nb. Eligibles</th>
                <th data-sortable="true" data-field="m_ineligible" data-filter-control="input" data-width="50">Nb. Non éligibles</th>
                <th data-sortable="true" data-field="m_selected" data-filter-control="select" data-width="160">Nb. Sélectionnés</th>
                <th data-sortable="true" data-field="sortDate" data-filter-control="input" data-width="160">Date du tirage au sort</th>
                <th data-sortable="true" data-field="cree" data-filter-control="input" data-width="160">Créé le</th>
                <th data-field="id" data-formatter="selectFormatter" data-width="60"></th>
            </tr>
        </thead>
    </table> 
</div>

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