<?php
// System tab — System Information, Hostname Settings, Timezone Settings
// Variables ($current_hostname, $current_timezone, $system_info, $common_timezones)
// are prepared in the parent server-settings.php before the include.
?>

<!-- System Information -->
<div class="row">
    <div class="col-md-12">
        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">System Information</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <table class="table table-sm">
                            <tr>
                                <td><strong>Hostname:</strong></td>
                                <td><?php echo htmlspecialchars($current_hostname); ?></td>
                            </tr>
                            <tr>
                                <td><strong>Operating System:</strong></td>
                                <td><?php echo htmlspecialchars($system_info['os']); ?></td>
                            </tr>
                            <tr>
                                <td><strong>Kernel:</strong></td>
                                <td><?php echo htmlspecialchars($system_info['kernel']); ?></td>
                            </tr>
                            <tr>
                                <td><strong>Timezone:</strong></td>
                                <td><?php echo htmlspecialchars($current_timezone); ?></td>
                            </tr>
                        </table>
                    </div>
                    <div class="col-md-6">
                        <table class="table table-sm">
                            <tr>
                                <td><strong>Uptime:</strong></td>
                                <td><?php echo htmlspecialchars($system_info['uptime']); ?></td>
                            </tr>
                            <tr>
                                <td><strong>Load Average:</strong></td>
                                <td><?php echo htmlspecialchars($system_info['load_avg']); ?></td>
                            </tr>
                            <tr>
                                <td><strong>Disk Usage:</strong></td>
                                <td><?php echo htmlspecialchars($system_info['disk_usage']); ?></td>
                            </tr>
                            <tr>
                                <td><strong>Memory Usage:</strong></td>
                                <td><?php echo htmlspecialchars($system_info['memory_usage']); ?>%</td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="row g-3">
    <!-- Hostname Settings -->
    <div class="col-lg-6">
        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">Hostname Settings</h5>
            </div>
            <div class="card-body">
                <form method="post">
                    <input type="hidden" name="action" value="update_hostname">
                    <input type="hidden" name="csrf_token" value="<?php echo get_csrf_token(); ?>">

                    <div class="mb-3">
                        <label for="hostname" class="form-label">Server Hostname</label>
                        <input type="text" class="form-control" id="hostname" name="hostname"
                               value="<?php echo htmlspecialchars($current_hostname); ?>"
                               placeholder="server.example.com" required>
                        <div class="form-text text-muted">The server's hostname (FQDN recommended)</div>
                    </div>

                    <button type="submit" class="btn btn-primary">
                        <i class="fa fa-save"></i> Update Hostname
                    </button>
                </form>
            </div>
        </div>
    </div>

    <!-- Timezone Settings -->
    <div class="col-lg-6">
        <div class="card mb-4">
            <div class="card-header">
                <h5 class="card-title mb-0">Timezone Settings</h5>
            </div>
            <div class="card-body">
                <form method="post">
                    <input type="hidden" name="action" value="update_timezone">
                    <input type="hidden" name="csrf_token" value="<?php echo get_csrf_token(); ?>">

                    <div class="mb-3">
                        <label for="timezone" class="form-label">System Timezone</label>
                        <select class="form-control" id="timezone" name="timezone" required>
                            <?php foreach ($common_timezones as $tz): ?>
                            <option value="<?php echo $tz; ?>" <?php echo $tz === $current_timezone ? 'selected' : ''; ?>>
                                <?php echo $tz; ?>
                            </option>
                            <?php endforeach; ?>
                        </select>
                        <div class="form-text text-muted">Current timezone: <?php echo htmlspecialchars($current_timezone); ?></div>
                    </div>

                    <button type="submit" class="btn btn-primary">
                        <i class="fa fa-save"></i> Update Timezone
                    </button>
                </form>
            </div>
        </div>
    </div>
</div>
