<!DOCTYPE html>
<html>
<head>
    <title>Contact</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 500px;
            margin: 50px auto;
            padding: 20px;
        }
        h1 {
            color: #333;
        }
        input, textarea {
            width: 100%;
            padding: 8px;
            margin: 10px 0;
            border: 1px solid #ddd;
            box-sizing: border-box;
        }
        textarea {
            min-height: 100px;
        }
        button {
            background: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            cursor: pointer;
        }
        button:hover {
            background: #45a049;
        }
        #response {
            margin-top: 20px;
            padding: 10px;
            display: none;
        }
    </style>
</head>
<body>
    <h1>Contact</h1>
    <form id="contactForm">
        <input type="text" name="name" placeholder="Name" required>
        <input type="email" name="email" placeholder="Email" required>
        <textarea name="message" placeholder="Message" required></textarea>
        <button type="submit">Submit</button>
    </form>
    <div id="response"></div>
    
    <script>
        document.getElementById('contactForm').addEventListener('submit', function(e) {
            e.preventDefault();
            const formData = new FormData(this);
            
            fetch('/api/contact', {
                method: 'POST',
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                body: new URLSearchParams(formData)
            })
            .then(response => response.text())
            .then(text => {
                document.getElementById('response').innerHTML = text;
                document.getElementById('response').style.display = 'block';
            })
            .catch(error => {
                document.getElementById('response').innerHTML = 'Error: ' + error.message;
                document.getElementById('response').style.display = 'block';
            });
        });
    </script>
</body>
</html>
