<?php
include 'db.php';

if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $sql = "SELECT initialPhoto, photo_perlakuan, photo_verifikasi, updatedPhoto FROM Report WHERE id = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("s", $id);
    $stmt->execute();
    $result = $stmt->get_result();
    

    if ($row = $result->fetch_assoc()) {
        $initialPhoto = $row['initialPhoto'];
        $photoPerlakuan = $row['photo_perlakuan'];
        $photoVerifikasi = $row['photo_verifikasi'];
        $updatedPhoto = $row['updatedPhoto'];

        echo "<div id='photoContainer' class='row'>";
        // Initial Photo
        echo "<div class='col-12 col-md-6 col-lg-3 mb-4 text-center'>";
        echo "<h5 class='mb-2'>Foto Temuan Awal</h5>";
        if ($initialPhoto) {
            echo "<img src='" . htmlspecialchars($initialPhoto) . "' alt='Foto Temuan Awal' style='max-width: 100%; height: auto; border-radius:8px; box-shadow:0 2px 8px #ccc;'>";
        } else {
            echo "<div class='text-muted'>Tidak ada foto</div>";
        }
        echo "</div>";
        // Photo Perlakuan
        echo "<div class='col-12 col-md-6 col-lg-3 mb-4 text-center'>";
        echo "<h5 class='mb-2'>Foto Perlakuan</h5>";
        if ($photoPerlakuan) {
            echo "<img src='" . htmlspecialchars($photoPerlakuan) . "' alt='Foto Perlakuan' style='max-width: 100%; height: auto; border-radius:8px; box-shadow:0 2px 8px #ccc;'>";
        } else {
            echo "<div class='text-muted'>Tidak ada foto</div>";
        }
        echo "</div>";
        // Photo Verifikasi
        echo "<div class='col-12 col-md-6 col-lg-3 mb-4 text-center'>";
        echo "<h5 class='mb-2'>Foto Verifikasi</h5>";
        if ($photoVerifikasi) {
            echo "<img src='" . htmlspecialchars($photoVerifikasi) . "' alt='Foto Verifikasi' style='max-width: 100%; height: auto; border-radius:8px; box-shadow:0 2px 8px #ccc;'>";
        } else {
            echo "<div class='text-muted'>Tidak ada foto</div>";
        }
        echo "</div>";
        // Updated Photo
        echo "<div class='col-12 col-md-6 col-lg-3 mb-4 text-center'>";
        echo "<h5 class='mb-2'>Foto Setelah</h5>";
        if ($updatedPhoto) {
            echo "<img src='" . htmlspecialchars($updatedPhoto) . "' alt='Foto Setelah' style='max-width: 100%; height: auto; border-radius:8px; box-shadow:0 2px 8px #ccc;'>";
        } else {
            echo "<div class='text-muted'>Tidak ada foto</div>";
        }
        echo "</div>";
        echo "</div>";
    } else {
        echo "<div id='photoContainer'>";
        echo "<h3>Initial Photo</h3>";
        echo "<img id='initialPhoto' src='' alt='Initial Photo' style='max-width: 100%; height: auto;'>";
        echo "<h3>Updated Photo</h3>";
        echo "<img id='updatedPhoto' src='' alt='Updated Photo' style='max-width: 100%; height: auto;'>";
        echo "<p>Tidak ada foto ditemukan untuk ID: " . htmlspecialchars($id) . "</p>";
        echo "</div>";
    }
} else {
    echo "<div id='photoContainer'>";
    echo "<p>ID tidak diberikan. Silakan masukkan ID yang valid.</p>";
    echo "</div>";
}

$conn->close();
?>