<div class="page-heading compact">
    <div>
        <span>Модул 7</span>
        <h1>Tracking</h1>
        <p>Следи статус, доказателство за доставка, входящ номер, срок и следващи действия.</p>
    </div>
</div>

<section class="two-column">
    <article class="panel">
        <form class="stack-form js-track-form" action="/tracking" method="post">
            <?= csrf_field() ?>
            <label>Номер на сигнал
                <input name="tracking_number" value="<?= e($report['tracking_number']) ?>">
            </label>
            <button class="btn btn-success" type="submit"><i class="bi bi-search"></i> Проследи</button>
        </form>

        <div class="tracking-card js-track-output">
            <h2>#<?= e($report['id']) ?> <?= e($report['title']) ?></h2>
            <p><?= e($report['address']) ?></p>
            <span class="status-pill <?= e(status_class($report['status'])) ?>"><?= e(status_label($report['status'])) ?></span>
        </div>

        <div class="delivery-proof mt-3">
            <h3>Входящ номер</h3>
            <p>Маркирай сигнала като реално получен само след входящ номер от ССЕВ, портал или институция.</p>
            <div class="form-grid mt-2">
                <input placeholder="Напр. 94-00-1234 / 02.07.2026">
                <button class="btn btn-outline-dark" type="button"><i class="bi bi-save"></i> Запази</button>
            </div>
        </div>
    </article>

    <aside class="panel">
        <h2>Timeline</h2>
        <ol class="timeline">
            <li><strong>Подаден</strong><span><?= e($report['created_at']) ?></span></li>
            <li><strong>Изпратен към институция</strong><span><?= e($report['institution']) ?></span></li>
            <li><strong>Очакван срок</strong><span><?= e($report['deadline_at']) ?></span></li>
            <li><strong>Отговор</strong><span>Очаква се</span></li>
        </ol>

        <div class="delivery-proof mt-4">
            <h3>Контрол на срока</h3>
            <dl class="proof-grid">
                <div><dt>Статус</dt><dd><?= e($enforcement['status'] ?? 'waiting') ?></dd></div>
                <?php if (isset($enforcement['days_left'])): ?>
                    <div><dt>Остават</dt><dd><?= e($enforcement['days_left']) ?> дни</dd></div>
                <?php endif; ?>
                <?php if (isset($enforcement['days_late'])): ?>
                    <div><dt>Просрочие</dt><dd><?= e($enforcement['days_late']) ?> дни</dd></div>
                <?php endif; ?>
            </dl>
            <div class="deadline-list mt-3">
                <?php foreach (($enforcement['actions'] ?? []) as $action): ?>
                    <div><span><?= e($action) ?></span></div>
                <?php endforeach; ?>
            </div>
        </div>
    </aside>
</section>
