<?php
include 'session_check.php';
include 'config/db.php';

$id = intval($_GET['id']);
$query = mysqli_query($conn, "SELECT * FROM pasien WHERE id = $id");
$data = mysqli_fetch_assoc($query);
?>

<!DOCTYPE html>
<html>
<head>
    <title>Detail Pasien</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <style>
        .table-detail th {
            width: 150px;
            background-color: #f8f9fa;
        }
    </style>
</head>
<body class="bg-light">
<div class="container mt-5">
    <div class="card shadow">
        <div class="card-header bg-primary text-white">
            <h5 class="mb-0">Detail Pasien</h5>
        </div>
        <div class="card-body">
            <table class="table table-bordered table-detail">
                <tr>
                    <th>NIK</th>
                    <td><?= $data['nik'] ?></td>
                </tr>
                <tr>
                    <th>Nama</th>
                    <td><?= $data['nama'] ?></td>
                </tr>
                <tr>
                    <th>Hasil Lab</th>
                    <td>
                        <?php if ($data['hasil_lab']): ?>
                            <?php if (preg_match('/\\.(jpg|jpeg|png|gif)$/i', $data['hasil_lab'])): ?>
                                <img src="<?= $data['hasil_lab'] ?>" alt="Hasil Lab" class="img-thumbnail mb-2" style="max-width: 300px;"><br>
                            <?php endif; ?>
                            <a href="<?= $data['hasil_lab'] ?>" download class="btn btn-sm btn-outline-primary">Download File</a>
                        <?php else: ?>
                            <em>Belum tersedia</em>
                        <?php endif; ?>
                    </td>
                </tr>
            </table>
            <a href="index.php" class="btn btn-secondary mt-3">Kembali</a>
        </div>
    </div>
</div>
</body>
</html>
