<?php
require __DIR__ . '/includes/config.php';
$page_title = ($LOCALE === 'de' ? 'Kontakt' : 'Contact') . ' — ' . SITE_NAME;
$page_description = $LOCALE === 'de' ? 'Kontaktiere das Tradelyst-Team.' : 'Get in touch with the Tradelyst team.';

$status   = $_GET['status']  ?? null;
$message  = $_GET['message'] ?? null;

include __DIR__ . '/includes/head.php';
include __DIR__ . '/includes/header.php';
?>

<section class="hero" style="padding-bottom: 32px;">
  <div class="container">
    <span class="hero-eyebrow"><?= h(t('contact.eyebrow')) ?></span>
    <h1><?= h(t('contact.h1')) ?></h1>
    <p class="lead">
      <?= h(t('contact.lead')) ?>
      <a href="mailto:<?= h(CONTACT_EMAIL) ?>" style="color:var(--lime);"><?= h(CONTACT_EMAIL) ?></a>
    </p>
  </div>
</section>

<section class="block">
  <div class="container">
    <?php if ($status === 'ok'): ?>
      <div class="form-status ok" role="status">
        <?= h(t('contact.form_ok')) ?>
      </div>
    <?php elseif ($status === 'error'): ?>
      <div class="form-status error" role="alert">
        <?= sprintf(h(t('contact.form_error')), h((string)$message), h(CONTACT_EMAIL)) ?>
      </div>
    <?php endif; ?>

    <form action="<?= url('api/contact-submit.php') ?>" method="post" class="contact-form" novalidate>
      <input type="hidden" name="lang" value="<?= h($LOCALE) ?>">
      <div>
        <label for="name"><?= h(t('contact.form_name')) ?></label>
        <input id="name" name="name" type="text" autocomplete="name" required maxlength="100">
      </div>
      <div>
        <label for="email"><?= h(t('contact.form_email')) ?></label>
        <input id="email" name="email" type="email" autocomplete="email" required maxlength="160">
      </div>
      <div>
        <label for="subject"><?= h(t('contact.form_subject')) ?></label>
        <input id="subject" name="subject" type="text" required maxlength="160">
      </div>
      <div>
        <label for="message"><?= h(t('contact.form_message')) ?></label>
        <textarea id="message" name="message" required maxlength="4000"></textarea>
      </div>

      <div class="honeypot" aria-hidden="true">
        <label for="website">Website (leave blank)</label>
        <input id="website" name="website" type="text" tabindex="-1" autocomplete="off">
      </div>
      <input type="hidden" name="loaded_at" value="0">

      <button type="submit" class="btn btn-primary" style="justify-self:start;"><?= h(t('contact.form_submit')) ?></button>
      <p class="text-muted" style="font-size:12px;">
        <?php
          $privacyLink = '<a href="' . h(localePath('/legal/datenschutz.php')) . '" style="color:var(--lime);text-decoration:underline;">'
            . h($LOCALE === 'de' ? 'Datenschutzerklärung' : 'privacy policy') . '</a>';
          echo sprintf(h(t('contact.privacy_note')), $privacyLink);
        ?>
      </p>
    </form>
  </div>
</section>

<?php include __DIR__ . '/includes/footer.php'; ?>
