<?php include 'headerpl.php'; ?>

<section style="max-width:640px; margin:40px auto; padding:0 20px;">
    <h1 style="color:#0f1a2d; margin-bottom:8px;">Kontakt</h1>
    <p style="color:#555; margin-bottom:24px;">Wypełnij formularz — odpowiedź wyślemy na podany adres e-mail.</p>

    <form id="contact-form" style="background:#fff; padding:28px; border-radius:12px; box-shadow:0 4px 20px rgba(0,0,0,0.06);">
        <div style="margin-bottom:16px;">
            <label style="display:block; font-weight:600; margin-bottom:6px; color:#333;">Imię i nazwisko *</label>
            <input type="text" name="name" required style="width:100%; padding:10px 12px; border:1px solid #ddd; border-radius:6px; box-sizing:border-box;">
        </div>
        <div style="margin-bottom:16px;">
            <label style="display:block; font-weight:600; margin-bottom:6px; color:#333;">E-mail *</label>
            <input type="email" name="email" required style="width:100%; padding:10px 12px; border:1px solid #ddd; border-radius:6px; box-sizing:border-box;">
        </div>
        <div style="margin-bottom:16px;">
            <label style="display:block; font-weight:600; margin-bottom:6px; color:#333;">Telefon</label>
            <input type="text" name="phone" style="width:100%; padding:10px 12px; border:1px solid #ddd; border-radius:6px; box-sizing:border-box;">
        </div>
        <div style="margin-bottom:20px;">
            <label style="display:block; font-weight:600; margin-bottom:6px; color:#333;">Wiadomość *</label>
            <textarea name="message" required rows="5" style="width:100%; padding:10px 12px; border:1px solid #ddd; border-radius:6px; box-sizing:border-box; resize:vertical;"></textarea>
        </div>
        <div id="form-msg" style="margin-bottom:12px; min-height:20px; color:#c00;"></div>
        <button type="submit" id="btn-send" style="background:#ff7a00; color:#fff; border:none; padding:12px 24px; border-radius:8px; font-weight:700; cursor:pointer;">Wyślij wiadomość</button>
    </form>
</section>

<script>
(function(){
    var form = document.getElementById('contact-form');
    var msg = document.getElementById('form-msg');
    var btn = document.getElementById('btn-send');
    if (!form) return;
    form.addEventListener('submit', function(e){
        e.preventDefault();
        msg.textContent = '';
        btn.disabled = true;
        btn.textContent = 'Wysyłanie...';
        var fd = new FormData(form);
        fetch('contact_send.php', { method: 'POST', body: fd })
            .then(function(r){ return r.json(); })
            .then(function(json){
                btn.disabled = false;
                btn.textContent = 'Wyślij wiadomość';
                if (json.success) {
                    msg.style.color = '#0a0';
                    msg.textContent = 'Wiadomość została wysłana. Odpowiemy wkrótce.';
                    form.reset();
                } else {
                    msg.style.color = '#c00';
                    msg.textContent = json.error || 'Wystąpił błąd.';
                }
            })
            .catch(function(){
                btn.disabled = false;
                btn.textContent = 'Wyślij wiadomość';
                msg.style.color = '#c00';
                msg.textContent = 'Błąd połączenia. Spróbuj później.';
            });
    });
})();
</script>

<?php include 'footer.php'; ?>
