<?php
require_once 'db.php';

header('Content-Type: application/json');

$phone = $_GET['phone'] ?? '';

if (preg_match('/^0\d{9}$/', $phone)) {
    $stmt = $pdo->prepare("SELECT name FROM customers WHERE contact_number = ?");
    $stmt->execute([$phone]);
    $customer = $stmt->fetch(PDO::FETCH_ASSOC);
    if ($customer) {
        echo json_encode(['name' => $customer['name']]);
        exit;
    }
}

echo json_encode(['name' => '']);
