<?php
require_once 'shikanisha.kts.php';

if (!isset($_GET['role_id'])) {
    die(json_encode(['success' => false, 'message' => 'Role ID required']));
}

$roleId = $conn->real_escape_string($_GET['role_id']);
$query = "SELECT p.page_id, p.page_name, p.icon, 
          CASE WHEN ac.role_id IS NOT NULL THEN 1 ELSE 0 END as has_access
          FROM pages p
          LEFT JOIN access_control ac ON p.page_id = ac.page_id AND ac.role_id = '$roleId'
          ORDER BY p.page_name";

$result = $conn->query($query);
$permissions = array();
while ($row = $result->fetch_assoc()) {
    $permissions[] = $row;
}

header('Content-Type: application/json');
echo json_encode($permissions);
$conn->close();
?>