<?php
// admin/get-inventory-item.php
require_once __DIR__ . '/../includes/config.php';
require_once __DIR__ . '/../includes/functions.php';

if (!isAdmin()) {
    exit;
}

$id = intval($_GET['id'] ?? 0);
if ($id > 0) {
    try {
        $stmt = $pdo->prepare("SELECT p.id, p.name, p.stock, p.min_stock, p.max_stock, p.reorder_level,
                               i.location 
                               FROM products p 
                               LEFT JOIN inventory i ON p.id = i.product_id 
                               WHERE p.id = ?");
        $stmt->execute([$id]);
        $product = $stmt->fetch();
        echo json_encode($product);
    } catch (Exception $e) {
        echo json_encode(['error' => $e->getMessage()]);
    }
} else {
    echo json_encode(['error' => 'Invalid ID']);
}
?>