<?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" role="alert">
            <?= e($flashSuccess) ?>
        </div>
        <?php endif; ?>
        <?php if ($flashError): ?>
        <div class="contact-alert contact-alert--error" role="alert">
            <?= 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>

        <h2 class="contact-section-title">Send a Message</h2>

        <form method="POST" action="/contact" novalidate class="contact-form">
            <?= csrf_field() ?>

            <!-- Honeypot -->
            <div style="display:none;" aria-hidden="true">
                <input type="text" name="website" tabindex="-1" autocomplete="off" value="">
            </div>

            <?= render_contact_form_fields($contactFields, $formErrors, $formOld, [
                'group'       => '',
                'row'         => '',
                'label'       => '',
                'input'       => '',
                'textarea'    => '',
                'select'      => '',
                'error_class' => 'field-error',
                'input_error' => 'is-error',
            ]) ?>

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

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