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

$cnic = $_GET['cnic'] ?? '';

// Validate CNIC format (XXXXX-XXXXXXX-X)
if (!preg_match('/^\d{5}-\d{7}-\d{1}$/', $cnic)) {
    die(json_encode(['exists' => false]));
}

// Check database (assuming column name is 'cnic')
$stmt = $conn->prepare("SELECT 1 FROM employees WHERE cnic = ? LIMIT 1");
$stmt->bind_param("s", $cnic);
$stmt->execute();
$exists = $stmt->fetch();

echo json_encode(['exists' => $exists]);

$stmt->close();
$conn->close();
?>