<?php
require __DIR__ . '/../includes/db.php';

$type = $_GET['type'] ?? 'supplier';
switch ($type) {
  case 'customer':
    $table = 'customers';
    break;
  case 'agent':
    $table = 'agents';
    break;
  default:
    $table = 'suppliers';
}

$stmt = $pdo->query("SELECT id, name FROM $table ORDER BY name");
echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
