<?php
require_once __DIR__.'/../../config/functions.php';
header('Content-Type: application/json');
$q='%'.sanitize($_GET['q']??'').'%';
$stmt=$pdo->prepare("SELECT p.id,p.nama,p.gambar,j.nama_jawatan as jawatan,u.nama_unit as unit FROM pegawai p JOIN jawatan j ON p.jawatan_id=j.id JOIN unit u ON p.unit_id=u.id WHERE p.status=1 AND (p.nama LIKE ? OR p.email LIKE ? OR j.nama_jawatan LIKE ?) LIMIT 8");
$stmt->execute([$q,$q,$q]);
$res=$stmt->fetchAll();
foreach($res as &$r)$r['gambar_url']=getPegawaiImage($r['gambar']);
echo json_encode($res);
