<?php
require_once 'includes/functions.php';

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    redirect(BASE_URL);
}

$name = sanitize($_POST['name'] ?? '');
$email = sanitize($_POST['email'] ?? '');
$phone = sanitize($_POST['phone'] ?? '');
$packageId = intval($_POST['package_id'] ?? 0);
$message = sanitize($_POST['message'] ?? '');

if (empty($name) || empty($email) || empty($message)) {
    setFlash('danger', 'Please fill in all required fields.');
    redirect(BASE_URL);
}

$db = getDBConnection();
$stmt = $db->prepare("INSERT INTO enquiries (name, email, phone, package_id, message) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$name, $email, $phone ?: null, $packageId ?: null, $message]);

setFlash('success', 'Your enquiry has been submitted successfully! We will get back to you soon.');
redirect(BASE_URL);
