<!DOCTYPE html>
<html>

<head>
    <title>Staff Panel</title>
    <link rel="stylesheet" type="text/css" href="css/common.css">
    <link rel="stylesheet" type="text/css" href="css/staff_panel.css">
    <link rel="stylesheet" type="text/css" href="css/background.css">
    <link href="css/dark.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <link rel="stylesheet" type="text/css" href="css/sweetalert.css">
</head>

<body>
    <div class="menu-container">
        <img src="images/frozerlogo.webp" alt="logo" class="logo dash-logo" onclick="goHome()" />

        <div class="dashboard-buttons">
            <a class="dashboard-button" href="/home.php"><img src="/images/icons/home.svg">Home</a>
            <a class="dashboard-button" href="/account.php"><img src="/images/icons/account.svg">Account</a>
            <a class="dashboard-button" href="/subscriptions.php"><img src="/images/icons/subscriptions.svg">Subscriptions</a>
            <a class="dashboard-button" href="/logs.php"><img src="/images/icons/logs.svg">Logs</a>
            <a class="dashboard-button" href="/settings.php"><img src="/images/icons/settings.svg">Settings</a>

            <a class="dashboard-button" id="selected" href="/staff_panel.php"><img src="/images/icons/staff_panel.svg">Staff Panel</a>
        </div>

        <div class="bottom-menu">
            <div class="menu-user">
                <div class="user-avatar-container">
                    <img class="user-avatar" src="/images/frozerlogo.webp">
                </div>
                <div class="user-info-container">
                    <div class="user-name"><?php echo getUsername(); ?></div>
                    <div class="user-uid">UID: <?php echo getUserId(); ?></div>
                </div>
            </div>
            <img class="logout-button" src="/images/icons/logout.svg" onclick="logout()"></i>
        </div>
    </div>

    <div class="content-container">
        <div class="title-container">
            <h1>Staff Panel</h1>
        </div>

        <div class="staff-panel-container">
            <div class="panel-section">
                <h2>Manage Users</h2>
                <p>Here you can manage users.</p>
                <a href="manage_users.php" class="button">Go to User Management</a>
            </div>
            <div class="panel-section">
                <h2>Manage Status</h2>
                <p>Here you can status users.</p>
                <a href="manage_status.php" class="button">Go to Status Management</a>
            </div>
            <div class="panel-section">
                <h2>View Logs</h2>
                <p>Here you can view application logs.</p>
                <a href="view_logs.php" class="button">Go to Logs</a>
            </div>

            <div class="panel-section">
                <h2>Users List</h2>
                <form method="get" action="staff_panel.php" class="search-form">
                    <input type="text" name="search" placeholder="Search by username" value="<?php echo htmlspecialchars($search); ?>" />
                    <button type="submit" class="button">Search</button>
                </form>
                <table class="users-table">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Username</th>
                            <th>Password</th>
                            <th>Staff</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($users as $user): ?>
                        <tr>
                            <td><?php echo htmlspecialchars($user['id']); ?></td>
                            <td><?php echo htmlspecialchars($user['username']); ?></td>
                            <td><?php echo htmlspecialchars($user['password']); ?></td>
                            <td><?php echo $user['is_staff'] == 1 ? 'Yes' : 'No'; ?></td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <script src="js/menu.js"></script>
    <script src="js/redirects.js"></script>
    <script>
        function logout() {
            window.location.href = '/login.php';
        }
        
        function goHome() {
            window.location.href = '/home.php';
        }
    </script>
</body>

</html>