<?php
header('Content-Type: application/json');

require_once "../../includes/db.php"; // adjust path if needed
session_start();

$coid   = $_SESSION['co_id'];

$search = isset($_GET['search']) ? trim($_GET['search']) : '';

if (strlen($search) < 0) {
    echo json_encode([]);
    exit;
}

$stmt = $pdo->prepare("
    SELECT id, acc_name
    FROM accounts
    WHERE acc_name LIKE :search
    AND co_id = :coid
    LIMIT 20
");

$like = "%$search%";

$stmt->bindValue(':coid', $coid, PDO::PARAM_INT);
$stmt->bindParam(':search', $like, PDO::PARAM_STR);
$stmt->execute();

$data = $stmt->fetchAll(PDO::FETCH_ASSOC);

echo json_encode($data);
exit;