<!DOCTYPE html>
<html>
<head>
    <title>Manage Status</title>
    <link rel="stylesheet" type="text/css" href="css/common.css">
    <link rel="stylesheet" type="text/css" href="css/manage_status.css">
    <link href="css/dark.css" rel="stylesheet">
</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" 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 htmlspecialchars($_SESSION['username']); ?></div>
                    <div class="user-uid">UID: <?php echo htmlspecialchars(getUserId()); ?></div>
                </div>
            </div>
            <img class="logout-button" src="/images/icons/logout.svg" onclick="logout()">
        </div>
    </div>

    <div class="content-container">
        <div class="title-container">
            <h1>Manage Status</h1>
        </div>

        <div class="staff-panel-container">
            <form method="post" action="">
                <label for="software">Software:</label>
                <select name="software" id="software" required>
                    <?php foreach ($statuses as $software => $info): ?>
                        <option value="<?php echo htmlspecialchars($software); ?>"><?php echo htmlspecialchars($software); ?></option>
                    <?php endforeach; ?>
                </select>
                
                <label for="status">Status:</label>
                <select name="status" id="status" required>
                    <option value="undetected">Undetected</option>
                    <option value="detected">Detected</option>
                    <option value="updating">Updating</option>
                </select>
                
                <label for="indicator_color">Indicator Color:</label>
                <input type="color" id="indicator_color" name="indicator_color" required>

                <label for="details">Details:</label>
                <textarea id="details" name="details" rows="4" required></textarea>

                <button type="submit" class="button">Update Status</button>
            </form>
        </div>

        <div class="panel-section">
            <h2>Current Software Statuses</h2>
            <table class="users-table">
                <thead>
                    <tr>
                        <th>Software</th>
                        <th>Status</th>
                        <th>Indicator Color</th>
                        <th>Details</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($statuses as $software => $statusDetails): ?>
                    <tr>
                        <td><?php echo htmlspecialchars($software); ?></td>
                        <td><?php echo htmlspecialchars($statusDetails['status']); ?></td>
                        <td style="background-color: <?php echo htmlspecialchars($statusDetails['indicatorColor']); ?>;"><?php echo htmlspecialchars($statusDetails['indicatorColor']); ?></td>
                        <td><?php echo htmlspecialchars($statusDetails['details']); ?></td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </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>

<?php
$conn->close();
?>
