<?php
session_start();
require_once('includes/header.php') ?>

<?php
$_SESSION['form_token'] = bin2hex(random_bytes(32));
?>



<div class="container py-5">
    <h2 class="text-center mb-4">Contact Us</h2>

    <?php if (isset($_GET['success'])): ?>
        <div class="alert alert-success">
            Message sent successfully!
        </div>
    <?php endif; ?>

    <?php if (isset($_GET['error'])): ?>
        <div class="alert alert-danger">
            Something went wrong, try again!
        </div>
    <?php endif; ?>
    <?php if (isset($_GET['duplicate'])): ?>
        <div class="alert alert-warning">
            This email has already sent a message!
        </div>
    <?php endif; ?>

    <form action="contact_submit.php" method="POST" class="shadow p-4 bg-white rounded">

        <input type="hidden" name="csrf" value="<?php echo $_SESSION['form_token']; ?>">

        <!-- honeypot -->
        <input type="text" name="hp" style="display:none">

        <div class="mb-3">
            <label>Name *</label>
            <input type="text" name="name" maxlength="200" required class="form-control">
        </div>

        <div class="mb-3">
            <label>Email *</label>
            <input type="email" name="email" maxlength="200" required class="form-control">
        </div>

        <div class="mb-3">
            <label>Phone</label>
            <input type="text" name="phone" maxlength="50" class="form-control">
        </div>

        <div class="mb-3">
            <label>Subject *</label>
            <input type="text" name="subject" maxlength="255" required class="form-control">
        </div>

        <div class="mb-3">
            <label>Message *</label>
            <textarea name="message" rows="5" maxlength="2000" required class="form-control"></textarea>
        </div>

        <button class="btn btn-primary w-100 py-2">Send Message</button>

    </form>
</div>



<?php require_once('includes/footer.php') ?>