<?= $this->extend('layouts/admin') ?>

<?= $this->section('content') ?>

<div class="animate-up">
    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 40px;">
        <div>
            <h1 style="margin: 0; font-size: 1.8rem; font-weight: 800;">Business Proposals</h1>
            <p style="color: var(--text-admin-muted); margin-top: 5px;">Manage and track your dynamic project proposals.</p>
        </div>
        <a href="<?= base_url('admin/proposal_add') ?>" class="btn btn-primary" style="padding: 12px 25px; border-radius: 10px; display: flex; align-items: center; gap: 10px; font-weight: 700;">
            <i class="bi bi-plus-lg"></i> New Proposal
        </a>
    </div>

    <div class="admin-card">
        <table class="admin-table">
            <thead>
                <tr>
                    <th style="width: 30%;">Proposal Name</th>
                    <th style="width: 45%;">Description</th>
                    <th style="width: 15%;">Created Date</th>
                    <th style="width: 10%; text-align: right;">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php if (empty($proposals)): ?>
                    <tr>
                        <td colspan="4" style="text-align: center; padding: 60px; color: var(--text-admin-muted);">
                            <i class="bi bi-file-earmark-text" style="font-size: 3rem; opacity: 0.2; display: block; margin-bottom: 15px;"></i>
                            <div style="font-weight: 600;">No proposals found.</div>
                            <p style="font-size: 0.85rem;">Start by creating your first business proposal.</p>
                        </td>
                    </tr>
                <?php else: ?>
                    <?php foreach ($proposals as $p): ?>
                        <tr>
                            <td>
                                <div style="display: flex; align-items: center; gap: 12px;">
                                    <div style="width: 36px; height: 36px; background: #eef2ff; color: #4285f4; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 1.1rem;">
                                        <i class="bi bi-file-earmark-text"></i>
                                    </div>
                                    <span style="font-weight: 700; color: #1e293b;"><?= $p['name'] ?></span>
                                </div>
                            </td>
                            <td>
                                <div style="color: #64748b; font-size: 0.9rem; line-height: 1.5; max-width: 400px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;">
                                    <?= strip_tags($p['description']) ?>
                                </div>
                            </td>
                            <td>
                                <div style="font-size: 0.85rem; color: #64748b; font-weight: 600;">
                                    <i class="bi bi-calendar3" style="margin-right: 5px; opacity: 0.5;"></i>
                                    <?= date('M d, Y', strtotime($p['created_at'])) ?>
                                </div>
                            </td>
                            <td style="text-align: right;">
                                <div style="display: flex; gap: 8px; justify-content: flex-end;">
                                    <a href="<?= base_url('admin/proposal_delete/' . $p['id']) ?>" class="btn-action delete" title="Delete Proposal" onclick="return confirm('Are you sure you want to delete this proposal?')">
                                        <i class="bi bi-trash-fill"></i>
                                    </a>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

<?= $this->endSection() ?>
