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

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    header('Location: contact.php');
    exit;
}
if (!verifyCsrf() || !empty($_POST['website'])) {
    $_SESSION['flash'] = 'Form guvenlik dogrulamasi basarisiz oldu. Lutfen tekrar deneyin.';
    header('Location: contact.php');
    exit;
}

$data = [
    'full_name' => trim((string)($_POST['full_name'] ?? '')),
    'phone' => trim((string)($_POST['phone'] ?? '')),
    'branch' => trim((string)($_POST['branch'] ?? '')),
    'service' => trim((string)($_POST['service'] ?? '')),
    'message' => trim((string)($_POST['message'] ?? '')),
];

if ($data['full_name'] === '' || $data['phone'] === '' || $data['branch'] === '' || $data['service'] === '') {
    $_SESSION['flash'] = 'Lutfen zorunlu alanlari doldurun.';
    header('Location: contact.php');
    exit;
}

insertLead($data);
$_SESSION['flash'] = 'Tesekkurler. Bilgi talebiniz alindi, ASSK ekibi en kisa surede sizinle iletisime gececek.';
header('Location: contact.php');
exit;
