<?php ob_start(); ?>

<?php
$flashSuccess  = flash('contact_success');
$flashError    = flash('contact_error');
$formErrors    = flash('contact_errors') ?: [];
$formOld       = flash('contact_old') ?: [];
$contactFields = $contact_fields ?? contact_form_fields();
?>

<section class="page-section">
    <div class="container container-narrow">
        <?php if ($system_page['show_title'] ?? 1): ?>
        <h1 class="page-title"><?= e($system_page['title'] ?? 'Contact') ?></h1>
        <?php endif; ?>

        <?php if (!empty($system_page['content'])): ?>
        <div class="page-content module-intro"><?= $system_page['content'] ?></div>
        <?php endif; ?>

        <?php if ($flashSuccess): ?>
        <div class="contact-alert contact-alert--success">
            <?= e($flashSuccess) ?>
        </div>
        <?php endif; ?>
        <?php if ($flashError): ?>
        <div class="contact-alert contact-alert--error">
            <?= e($flashError) ?>
        </div>
        <?php endif; ?>

        <div class="contact-info">
            <?php if ($email = setting('contact_email')): ?>
            <p>Email: <a href="mailto:<?= e($email) ?>"><?= e($email) ?></a></p>
            <?php endif; ?>
            <?php if ($phone = setting('contact_phone')): ?>
            <p>Phone: <a href="tel:<?= e(preg_replace('/[^+\d]/', '', $phone)) ?>"><?= e($phone) ?></a></p>
            <?php endif; ?>
        </div>

        <div class="contact-form-section">
            <h2 class="contact-form-heading">Send a Message</h2>
            <form method="POST" action="/contact" novalidate class="contact-form">
                <?= csrf_field() ?>

                <!-- Honeypot -->
                <div class="contact-form-honeypot" aria-hidden="true">
                    <input type="text" name="website" tabindex="-1" autocomplete="off" value="">
                </div>

                <?= render_contact_form_fields($contactFields, $formErrors, $formOld) ?>

                <div class="contact-form-group">
                    <button type="submit" class="contact-form-submit btn btn-primary">
                        Send Message
                    </button>
                </div>
            </form>
        </div>
    </div>
</section>

<?php $content = ob_get_clean(); include __DIR__ . '/layout.php'; ?>
