<?php
require_once __DIR__ . '/../lib/auth.php';
require_once __DIR__ . '/../lib/layout.php';
require_login();

$user_id = current_user()['id'];
$stmt    = db()->prepare('SELECT * FROM einsatzanweisung WHERE user_id = ?');
$stmt->execute([$user_id]);
$ea = $stmt->fetch();

layout_start('OMSORG – Einsatzanweisung', 'einsatzanweisung');
?>
      <h1 class="main-title">Einsatz<span>anweisung</span></h1>
      <p class="main-sub">Deine persönliche Einsatzanweisung als PDF-Dokument.</p>

      <?php if (!$ea || ($ea['filename'] === '' && $ea['ort'] === '')): ?>
        <p style="color:var(--muted);margin-top:40px">Noch keine Einsatzanweisung hinterlegt.</p>
      <?php else: ?>
        <div class="glass" style="max-width:520px;padding:28px;border-radius:20px;margin-top:24px">
          <?php if ($ea['ort'] !== ''): ?>
            <div style="margin-bottom:24px">
              <div style="color:var(--cyan2);font-size:.78rem;font-weight:900;text-transform:uppercase;letter-spacing:.08em;margin-bottom:6px">Einsatzort</div>
              <div style="font-size:1.15rem;font-weight:800"><?= e($ea['ort']) ?></div>
            </div>
          <?php endif; ?>

          <?php if ($ea['filename'] !== ''): ?>
            <div>
              <div style="color:var(--cyan2);font-size:.78rem;font-weight:900;text-transform:uppercase;letter-spacing:.08em;margin-bottom:10px">Dokument</div>
              <a href="einsatzanweisung-serve.php" class="btn" style="display:inline-flex;align-items:center;gap:8px">
                &#8595; <?= e($ea['original_name']) ?>
              </a>
              <?php if ($ea['uploaded_at'] !== ''): ?>
                <div style="color:var(--muted);font-size:.82rem;margin-top:8px">
                  Hochgeladen: <?= e(date('d.m.Y', strtotime($ea['uploaded_at']))) ?>
                </div>
              <?php endif; ?>
            </div>
          <?php endif; ?>
        </div>
      <?php endif; ?>
<?php layout_end(); ?>
