<?php
include 'includes/config.php';

if (isset($_POST['search'])) {
    $search = $_POST['search'];
    $query = $conn->prepare("
        SELECT id, name 
        FROM products 
        WHERE (name LIKE ? OR barcode LIKE ?) 
        AND business_id = 3 
        LIMIT 50
    ");
    $query->execute(["%$search%", "%$search%"]);
    $results = $query->fetchAll();

    foreach ($results as $product) {
        echo '<div class="dropdown-item product-item" data-id="' . $product['id'] . '">' . htmlspecialchars($product['name']) . '</div>';
    }
}
?>
