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

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

<div>
    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 40px;">
        <div>
            <h1>Project Portfolio</h1>
            <p style="color: var(--text-muted);">Manage your construction projects and their public visibility.</p>
        </div>
        <a href="<?= base_url('admin/project_add') ?>" class="btn btn-primary"><i class="bi bi-plus-lg"></i> New Project</a>
    </div>

    <div class="admin-card">
        <table class="admin-table">
            <thead>
                <tr>
                    <th>Project</th>
                    <th>Status</th>
                    <th>Budget</th>
                    <th>Start Date</th>
                    <th>Assigned Employees</th>
                    <th style="text-align: right;">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($projects as $project): ?>
                    <tr>
                        <td>
                            <div style="display: flex; align-items: center; gap: 15px;">
                                <img src="<?= $project['image'] ?? base_url('assets/images/placeholder.jpg') ?>" alt="" style="width: 40px; height: 40px; border-radius: 6px; object-fit: cover;">
                                <span style="font-weight: 600;"><?= $project['title'] ?></span>
                            </div>
                        </td>
                        <td>
                            <span class="status-badge status-<?= strtolower(str_replace(' ', '-', $project['status'])) ?>">
                                <?= $project['status'] ?>
                            </span>
                        </td>
                        <td>₹<?= number_format($project['budget'], 2) ?></td>

                        <td style="color: var(--text-muted); font-size: 0.9rem;"><?= date('M d, Y', strtotime($project['start_date'])) ?></td>
                        <td>
                            <?php if (!empty($project['assigned_employees'])): ?>
                                <div style="display: flex; flex-wrap: wrap; gap: 5px;">
                                    <?php foreach ($project['assigned_employees'] as $name): ?>
                                        <span style="background: rgba(66, 133, 244, 0.1); color: #4285f4; padding: 2px 10px; border-radius: 50px; font-size: 0.75rem; font-weight: 700; border: 1px solid rgba(66, 133, 244, 0.2);"><?= $name ?></span>
                                    <?php endforeach; ?>
                                </div>
                            <?php else: ?>
                                <span style="color: var(--text-muted); font-size: 0.8rem; font-style: italic;">No employees assigned</span>
                            <?php endif; ?>
                        </td>
                        <td style="text-align: right;">
                            <div style="display: flex; gap: 8px; justify-content: flex-end;">
                                <a href="<?= base_url('admin/project_assign/' . $project['id']) ?>" class="btn-action" style="background: #eef2ff; color: #4285f4; border: 1px solid #e0e7ff;" title="Assign Employees"><i class="bi bi-people-fill"></i></a>
                                <a href="<?= base_url('admin/project_sheet/' . $project['id']) ?>" class="btn-action" style="background: #fff; color: #64748b; border: 1px solid var(--border);" title="Project Sheets"><i class="bi bi-table"></i></a>
                                <a href="<?= base_url('admin/project_edit/' . $project['id']) ?>" class="btn-action edit" title="Edit"><i class="bi bi-pencil-square"></i></a>
                                <a href="<?= base_url('admin/project_delete/' . $project['id']) ?>" class="btn-action delete" title="Delete" onclick="return confirm('Are you sure you want to delete this project?')"><i class="bi bi-trash-fill"></i></a>
                            </div>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>

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