<?php
require_once __DIR__ . '/../config/auth.php';
header('Content-Type: application/json');

if (!isLoggedIn()) { echo json_encode([]); exit; }

$product_id = (int)($_GET['product_id'] ?? 0);
if (!$product_id) { echo json_encode([]); exit; }

$pdo = getDB();
$stmt = $pdo->prepare("SELECT id, imei_number FROM product_imei WHERE product_id = ? AND status = 'Available' ORDER BY imei_number");
$stmt->execute([$product_id]);
echo json_encode($stmt->fetchAll());
