<?php
header("Content-Type: application/json");
require_once "../config.php";
$search = isset($_GET['search']) ? trim($_GET['search']) : '';

try {
    $stmt = $dbh->prepare("
        SELECT 
            id AS copy_id,
            book_id,
            book_no,
            book_status,
            QRCode
        FROM tblbookcopies
        WHERE book_no LIKE :q
           OR CAST(book_id AS CHAR) LIKE :q
           OR QRCode LIKE :q
    ");
    $stmt->bindValue(':q', "%$search%", PDO::PARAM_STR);
    $stmt->execute();

    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
    echo json_encode(['status' => 'success', 'data' => $rows]);
} catch (PDOException $e) {
    echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
}
