<?php
// Konfigurasi database
define('DB_HOST', 'localhost');
define('DB_USER', 'wiselie_nanda');
define('DB_PASS', 'Clemira123');
define('DB_NAME', 'wiselie_inventory');

// Koneksi database
$db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($db->connect_error) {
    die("Koneksi ke database gagal: " . $db->connect_error);
}

// Ambil query pencarian
$term = $_GET['term'] ?? '';

// Query untuk mendapatkan nama produk berdasarkan pencarian
$sql = "SELECT DISTINCT name FROM indirect_code WHERE name LIKE ? LIMIT 10";
$stmt = $db->prepare($sql);
$search = "%$term%";
$stmt->bind_param("s", $search);
$stmt->execute();
$result = $stmt->get_result();

// Format hasil dalam JSON
$names = [];
while ($row = $result->fetch_assoc()) {
    $names[] = $row['name'];
}

echo json_encode($names);
