<?php
require_once 'databaseConnection.php';

if (isset($_GET['query'])) {
    $search = $_GET['query'];

    $mysqli = db_connect();
    if (!$mysqli) {
        die(json_encode(["status" => "error", "message" => "Database connection failed"]));
    }

    // Fetch job numbers that match the search query
    $stmt = $mysqli->prepare("SELECT register_number FROM customerField WHERE register_number LIKE CONCAT(?, '%') LIMIT 10");
    $stmt->bind_param("s", $search);
    $stmt->execute();
    $result = $stmt->get_result();

    $jobNumbers = [];
    while ($row = $result->fetch_assoc()) {
        $jobNumbers[] = $row['register_number'];
    }

    echo json_encode($jobNumbers);
}
