<?php 
    $data = array();
    $data['title'] = "Kullanıcı Grupları | ".$config->get('site_title');
    $data['links'] = [];
    $data['styles'] = [];
    $data['header']['scripts'] = [];
    $data['version'] = $config->get('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/admin-groups/list",
        'index' => 2
    );
?>
<?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/admin-groups/add" class="btn btn-primary btn-sm me-2"><i class="bi bi-plus-circle-dotted"></i> Yeni</a>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-striped table-hover table-bordered table-sortable mb-0">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Durum</th>
                                    <th>Grup Adı</th>
                                    <th>Açıklama</th>
                                    <th style="width:110px;"></th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $stmt = $db->query("SELECT * FROM {$db->prefix}admin_groups");
                                    if($stmt->num_rows>0) {
                                        foreach($stmt->rows as $row) {
                                            $status = $row['status'] == 1 ? "<span class=\"badge bg-success\">Aktif</span>" : "<span class=\"badge bg-danger\">Pasif</span>";
                                            echo "<tr>
                                                        <td class=\"text-center\">".$row['id']."</td>
                                                        <td>".$status."</td>
                                                        <td>".$row['name']."</td>
                                                        <td>".$row['description']."</td>
                                                        <td style=\"width: 110px;vertical-align: middle;\" class=\"text-center\">
                                                            <a class=\"btn btn-sm btn-primary me-1\" href=\"/admin/admin-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/admin-groups/delete?id=".$row['id']."\"><i class=\"bi bi-trash\"></i></button>
                                                        </td>
                                                    </tr>";
                                        }
                                    }else{
                                        echo "<tr class=\"text-center\"><td colspan=\"5\">Hiçbir kayıt bulunamadı!</td></tr>";
                                    }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </main>
<?php include DIR_VIEWS."parts/footer.php"; ?>