<?php
// Handle form submission
$showSuccess = false;

include "config/db.php";

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    // Sanitize input
    $fullname = $_POST['fullname'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];
    $address = $_POST['address'];
    $subject = $_POST['subject'];
    $gender = $_POST['gender'] ?? '';
    $birthday = $_POST['birthday'];

    // Insert data
    $stmt = $conn->prepare("INSERT INTO contacts (fullname, email, phone, address, subject, gender, birthday) VALUES (?, ?, ?, ?, ?, ?, ?)");
    $stmt->bind_param("sssssss", $fullname, $email, $phone, $address, $subject, $gender, $birthday);

    if ($stmt->execute()) {
        $showSuccess = true;
    }

    $stmt->close();
    $conn->close();
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Contact Me - Glassmorphism Form</title>
    <link rel="stylesheet" href="navbar.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: Arial, sans-serif;
            background: linear-gradient(135deg, rgba(0, 0, 33, 1), rgba(20, 20, 50, 1));
            margin: 0;
            color: #fff;
            overflow-x: hidden;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }
       

        main {
            flex-grow: 1;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        form {
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(15px);
            padding: 30px 25px;
            border-radius: 15px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
            max-width: 450px;
            width: 100%;
            color: #fff;
        }

        form label {
            display: block;
            margin-bottom: 6px;
            font-weight: 600;
        }

        form input[type="text"],
        form input[type="email"],
        form input[type="tel"],
        form input[type="date"],
        form select {
            width: 100%;
            padding: 10px;
            margin-bottom: 20px;
            border: none;
            border-radius: 8px;
            background: rgba(255, 255, 255, 0.2);
            color: #fff;
            outline: none;
            font-size: 1rem;
        }

        form input[type="radio"] {
            margin-right: 6px;
            cursor: pointer;
        }

        form select option {
            background-color: #222;
            /* dark */
            color: #fff;
            /* White  */
        }


        .gender-options {
            display: flex;
            gap: 15px;
            margin-bottom: 20px;
            align-items: center;
        }

        form input[type="submit"] {
            background-color: rgba(76, 175, 80, 0.8);
            color: white;
            border: none;
            padding: 12px;
            border-radius: 8px;
            width: 100%;
            cursor: pointer;
            font-size: 18px;
            font-weight: bold;
            transition: background-color 0.3s;
        }

        form input[type="submit"]:hover {
            background-color: rgba(76, 175, 80, 1);
        }

        /* Success Popup */
        .popup-message {
            position: fixed;
            top: 20px;
            right: 20px;
            background-color: #4CAF50;
            color: white;
            padding: 15px 25px;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
            font-size: 1rem;
            z-index: 1000;
            opacity: 0;
            transition: opacity 0.5s ease;
        }

        .popup-message.show {
            opacity: 1;
        }
    </style>
</head>

<body>

    <?php if ($showSuccess): ?>
        <div class="popup-message" id="successPopup">Thank you! Your details have been submitted successfully.</div>
        <script>
            const popup = document.getElementById('successPopup');
            popup.classList.add('show');
            setTimeout(() => {
                popup.classList.remove('show');
            }, 4000);
        </script>
    <?php endif; ?>

<?php include 'navbar.php'; ?>

    <main>
        <form action="contact.php" method="POST">
            <label for="fullname">Full Name:</label>
            <input type="text" id="fullname" name="fullname" required />

            <label for="email">Email Address:</label>
            <input type="email" id="email" name="email" placeholder="abc@gmail.com" required />

            <label for="phone">Phone Number:</label>
            <input type="tel" id="phone" name="phone" placeholder="+1234567890" />

            <label for="address">Address:</label>
            <input type="text" id="address" name="address" />

            <label for="subject">Subject:</label>
            <select id="subject" name="subject" required>
                <option value="" disabled selected>Select an option</option>
                <option value="feedback">Feedback</option>
                <option value="general-inquiry">General Inquiry</option>
                <option value="support">Support</option>
            </select>

            <label>Gender:</label>
            <div class="gender-options">
                <label><input type="radio" name="gender" value="male" /> Male</label>
                <label><input type="radio" name="gender" value="female" /> Female</label>
                <label><input type="radio" name="gender" value="other" /> Other</label>
            </div>

            <label for="birthday">Date of Birth:</label>
            <input type="date" id="birthday" name="birthday" />

            <input type="submit" value="Submit" />
        </form>
    </main>

</body>

</html>