<?php
// get_detail_penilaian.php
require_once 'config.php';
requireLogin();

// Memastikan parameter yang dibutuhkan ada
if (!isset($_GET['nisn']) || !isset($_GET['domisili'])) {
    http_response_code(400);
    echo json_encode(['error' => 'Parameter tidak lengkap']);
    exit;
}

$nisn = sanitizeInput($_GET['nisn']);
$domisili = sanitizeInput($_GET['domisili']);

$conn = connectDB();

// Query untuk mendapatkan detail penilaian dari semua juri
$stmt = $conn->prepare("SELECT p.id, p.id_juri, u.nama_lengkap as nama_juri, p.nilai_teknik, p.nilai_penampilan, p.nilai_kreativitas, p.total_nilai, p.catatan 
                       FROM penilaian p
                       JOIN users u ON p.id_juri = u.id
                       WHERE p.nisn_peserta = ? AND p.domisili = ?
                       ORDER BY p.id_juri");
$stmt->bind_param("ss", $nisn, $domisili);
$stmt->execute();
$result = $stmt->get_result();

$data = [];
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $data[] = $row;
    }
}

echo json_encode($data);
$conn->close();