<?php
declare(strict_types=1);
require_once __DIR__ . '/../db/config.php';

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

$phone = $_POST['phone'] ?? '';
$session_id = session_id();

if (!empty($phone) && !empty($session_id)) {
    $db = db();
    $stmt = $db->prepare("UPDATE visitor_logs SET phone_number = ? WHERE session_id = ? ORDER BY id DESC LIMIT 1");
    $stmt->execute([$phone, $session_id]);
    echo json_encode(['success' => true]);
} else {
    echo json_encode(['success' => false, 'error' => 'Invalid data']);
}
