<?php 
    $data = array();
    $data['title'] = "Kullanıcı Grupları | ".$App->title;
    $data['links'] = [];
    $data['styles'] = [];
    $data['header']['scripts'] = [];
    $data['version'] = $App->version;
    $data['csrf_token'] = $csrf_generator->create();
    $data['sidebar_menu'] = $menu->get(array('position'=>'sidebar'));
    $data['sidebar_active_menu'] = $menu->getActiveMenuItemId(trim($_SERVER['REQUEST_URI']));
    $data['footer']['scripts'] = [];
    $menu_items = $menu->get(array('position'=>'footer'));
    foreach($menu_items as $item){
        if($item['col'] == "1"){
            $data['menu']['footer']["1"][] = $item;
        }
        if($item['col'] == "2"){
            $data['menu']['footer']["2"][] = $item;
        }
        if($item['col'] == "3"){
            $data['menu']['footer']["3"][] = $item;
        }
        if($item['col'] == "4"){
            $data['menu']['footer']["4"][] = $item;
        }
    }

    $data['breadcrumbs'] = array();
    $data['breadcrumbs'][] = array(
        'text' => "Pano",
        'href' => "/admin",
        'index' => 1
    );
    $data['breadcrumbs'][] = array(
        'text' => "Kullanıcı Grupları",
        'href' => "/admin/user-groups/list",
        'index' => 2
    );

    $search_keywords    = isset($_GET['q']) ? htmlspecialchars($_GET['q'], ENT_QUOTES, 'UTF-8') : "";
    $status             = isset($_GET["status"]) ? $_GET["status"] : "";
    $sort               = isset($_GET["sort"]) ? $_GET["sort"] : "id";
    $sort_order         = isset($_GET["order"]) ? $_GET["order"] : "DESC";

    $page               = !isset($_GET["page"]) || $_GET["page"] < 1 ? 1 : (int)$_GET["page"];
    $limit	            = isset($_GET["limit"]) ? (int)$_GET["limit"] : 25;
    $offset             = ($page-1)*$limit;
    $filter_data = array(
        'search_keywords'    => $search_keywords,
        'status'             => $status,
        'sort'               => $sort,
        'order'              => $sort_order,
        'offset'             => $offset,
        'limit'              => $limit
    );
    
    $user_groups 	    = $user->getUserGroups();
?>
<?php include DIR_VIEWS."parts/header.php"; ?>
        <main class="content">
            <div class="container-fluid">
                <div class="card">
                    <div class="card-header">
                        <h5 class="card-title">Kullanıcı Grupları</h5>
                        <a href="/admin/user-groups/add" class="btn btn-primary btn-sm"><i class="bi bi-plus-circle me-1"></i> Yeni</a>
                    </div>
                    <div class="card-body p-0">
                        <div class="table-responsive">
                            <table class="table table-striped table-hover mb-0">
                                <thead>
                                    <tr>
                                        <th style="width:50px;">ID</th>
                                        <th style="width:100px;">Durum</th>
                                        <th>Ad</th>
                                        <th>Ek Alan</th>
                                        <th style="width:110px;"></th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                        if(count($user_groups)>0) {
                                            foreach($user_groups as $row) {
                                                echo "<tr>
                                                            <td class=\"text-center\">".$row['id']."</td>
                                                            <td>".$row['status']."</td>
                                                            <td>".$row['title']."</td>
                                                            <td>".$row['identifier_text']."</td>
                                                            <td style=\"width: 110px;vertical-align: middle;\" class=\"text-center\">
                                                                <a class=\"btn btn-sm btn-primary me-1\" href=\"/admin/user-groups/edit?id=".$row['id']."\"><i class=\"bi bi-pencil-square\"></i></a>
                                                                <button class=\"btn btn-sm btn-danger\" data-delete data-href=\"/admin/user-groups/delete?id=".$row['id']."\"><i class=\"bi bi-trash\"></i></button>
                                                            </td>
                                                        </tr>";
                                            }
                                        }else{
                                            echo "<tr class=\"text-center\"><td colspan=\"3\">Hiçbir kayıt bulunamadı!</td></tr>";
                                        }
                                    ?>
                                </tbody>
                            </table>
                        </div>
                        <div class="d-flex table-responsive align-items-center justify-content-center mt-3">
                            <div class="table-responsive">
                                <nav aria-label="Page navigation">
                                    <ul class="pagination" id="pagination">
                                        <?php echo $pagination->render(); ?>
                                    </ul>
                                </nav>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
<?php include DIR_VIEWS."parts/footer.php"; ?>