<?php
session_start();
if (!isset($_SESSION['patient_id'])) {
    header("Location: ../login.php");
    exit();
}
include '../../include/config.php';

$user_id = $_SESSION['patient_id'];

$vitals = $conn->query("
    SELECT * FROM vital_signs 
    WHERE patient_id = '$user_id' 
    ORDER BY recorded_at DESC LIMIT 10
");

$page_title = 'Vital Signs | UHD';
include '../../include/header.php';
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vital Signs</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.6.0/css/all.min.css">
</head>
<body>
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2 class="text-white"><i class="fas fa-heartbeat me-2"></i> Vital Signs</h2>
        <a href="index.php" class="btn btn-outline-light rounded-pill">← Back</a>
    </div>

    <?php if ($vitals && $vitals->num_rows > 0): ?>
        <div class="table-responsive">
            <table class="table table-dark table-hover">
                <thead>
                    <tr><th>Date</th><th>Blood Pressure</th><th>Heart Rate</th><th>Temperature</th><th>Oxygen</th><th>Weight</th></tr>
                </thead>
                <tbody>
                    <?php while($v = $vitals->fetch_assoc()): ?>
                        <tr>
                            <td><?= date('M d, Y', strtotime($v['recorded_at'])) ?></td>
                            <td><?= $v['blood_pressure'] ?? '—' ?></td>
                            <td><?= $v['heart_rate'] ?? '—' ?> bpm</td>
                            <td><?= $v['temperature'] ?? '—' ?> °C</td>
                            <td><?= $v['oxygen_saturation'] ?? '—' ?>%</td>
                            <td><?= $v['weight'] ?? '—' ?> kg</td>
                        </tr>
                    <?php endwhile; ?>
                </tbody>
            </table>
        </div>
    <?php else: ?>
        <div class="alert alert-info text-center py-5">
            <i class="fas fa-chart-line fa-3x mb-3"></i>
            <h5>No vital signs recorded yet</h5>
            <p>Your vital signs will appear here after checkups</p>
        </div>
    <?php endif; ?>
</div>
<?php include '../../include/footer.php'; ?>