<?php
session_start();
if (!isset($_SESSION['name'])) {
    http_response_code(401);
    echo json_encode(['message' => 'Unauthorized']);
    die;
}

require_once 'config/db.php';
$id = isset($_GET['id']) ? $_GET['id'] : die('Item ID not provided');

$query = "SELECT * FROM items WHERE id = :id";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':id', $id);
$stmt->execute();

$item = $stmt->fetch(PDO::FETCH_ASSOC);

if ($item) {
    echo json_encode($item);
} else {
    http_response_code(404);
    echo json_encode(['message' => 'Item not found']);
}
