<?php defined('BASE_PATH') || exit; /** @var array $polls */ ?>
<div class="page-header">
    <div class="page-header-left">
        <a href="/dashboard" class="btn btn-ghost btn-sm">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16"><path d="M19 12H5M12 19l-7-7 7-7"/></svg>
            <?= t('dashboard') ?>
        </a>
        <h1 class="page-title"><?= t('mp_nav') ?></h1>
    </div>
    <div class="page-header-actions">
        <a href="/polls/create" class="btn btn-primary btn-sm">
            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
            <?= t('mp_new_poll') ?>
        </a>
    </div>
</div>

<p class="text-muted" style="margin-top:-.5rem;margin-bottom:1.25rem;font-size:.9rem"><?= t('mp_list_intro') ?></p>

<?php if (empty($polls)): ?>
<div class="empty-state">
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" width="56" height="56" opacity=".3"><rect x="3" y="4" width="18" height="18" rx="2"/><line x1="16" y1="2" x2="16" y2="6"/><line x1="8" y1="2" x2="8" y2="6"/><line x1="3" y1="10" x2="21" y2="10"/></svg>
    <p><?= t('mp_no_polls') ?></p>
    <a href="/polls/create" class="btn btn-primary btn-sm"><?= t('mp_new_poll') ?></a>
</div>
<?php else: ?>
<div class="card">
    <table style="width:100%;border-collapse:collapse">
        <thead>
            <tr style="text-align:left;border-bottom:1px solid var(--border,#e5e7eb)">
                <th style="padding:.6rem .9rem;font-size:.8rem;color:var(--text-muted,#6b7280)"><?= t('mp_col_title') ?></th>
                <th style="padding:.6rem .9rem;font-size:.8rem;color:var(--text-muted,#6b7280)"><?= t('mp_col_options') ?></th>
                <th style="padding:.6rem .9rem;font-size:.8rem;color:var(--text-muted,#6b7280)"><?= t('mp_col_responses') ?></th>
                <th style="padding:.6rem .9rem;font-size:.8rem;color:var(--text-muted,#6b7280)"><?= t('mp_col_status') ?></th>
                <th style="padding:.6rem .9rem;font-size:.8rem;color:var(--text-muted,#6b7280)"><?= t('created_at_label') ?></th>
            </tr>
        </thead>
        <tbody>
        <?php foreach ($polls as $p): ?>
            <?php
                $finalized = !empty($p['final_option_id']);
                $expired   = !$finalized && !empty($p['deadline']) && (int)$p['deadline'] < time();
            ?>
            <tr style="border-bottom:1px solid var(--border,#f3f4f6)">
                <td style="padding:.6rem .9rem">
                    <a href="/polls/<?= (int)$p['id'] ?>" style="font-weight:600;text-decoration:none;color:var(--primary,#4f46e5)"><?= Helper::e($p['title']) ?></a>
                </td>
                <td style="padding:.6rem .9rem"><?= (int)$p['option_count'] ?></td>
                <td style="padding:.6rem .9rem"><?= (int)$p['response_count'] ?></td>
                <td style="padding:.6rem .9rem">
                    <?php if ($finalized): ?>
                        <span class="badge badge-success"><?= t('mp_status_finalized') ?></span>
                    <?php elseif ($expired): ?>
                        <span class="badge badge-neutral"><?= t('mp_status_closed') ?></span>
                    <?php else: ?>
                        <span class="badge badge-primary"><?= t('mp_status_open') ?></span>
                    <?php endif; ?>
                </td>
                <td style="padding:.6rem .9rem;color:var(--text-muted,#6b7280);font-size:.85rem"><?= Helper::e(Helper::formatDate($p['created_at'])) ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
</div>
<?php endif; ?>
