<?php
session_start();
require_once 'db_connect.php';

$category_id = $_GET['category_id'] ?? null;

if ($category_id) {
    try {
        $stmt = $conn->prepare("SELECT id, name, barcode, retail_price, wholesale_price FROM items WHERE category_id = :category_id");
        $stmt->execute([':category_id' => $category_id]);
        $items = $stmt->fetchAll(PDO::FETCH_ASSOC);
        echo json_encode($items);
    } catch (PDOException $e) {
        echo json_encode(['error' => $e->getMessage()]);
    }
} else {
    echo json_encode(['error' => 'No category ID provided']);
}
?>