<?php
header('Content-Type: application/json');
include_once('../includes/config.php');

if (!isset($_GET['customerID']) || empty($_GET['customerID'])) {
    echo json_encode([
        'success' => false,
        'message' => 'Customer ID is required'
    ]);
    exit;
}

$customerID = mysqli_real_escape_string($con, $_GET['customerID']);

$query = "SELECT ID, CustomerName FROM tblcustomers WHERE CustomerID = '$customerID'";
$result = mysqli_query($con, $query);

if ($result && mysqli_num_rows($result) > 0) {
    $customer = mysqli_fetch_assoc($result);
    echo json_encode([
        'success' => true,
        'exists' => true,
        'customer' => $customer
    ]);
} else {
    echo json_encode([
        'success' => true,
        'exists' => false,
        'message' => 'Customer ID is available'
    ]);
}
?>
