<div class="projects-container">
    <div class="page-header">
        <div>
            <h1 class="page-title">Projects</h1>
            <p class="page-subtitle">Manage and track all organizational projects</p>
        </div>
        <div class="d-flex gap-2">
            <a href="<?= APP_URL ?>/projects/categories" class="btn btn-secondary">
                <i class="fas fa-tags"></i> Manage Categories
            </a>
            <a href="<?= APP_URL ?>/projects/create" class="btn btn-primary">
                <i class="fas fa-plus"></i> New Project
            </a>
        </div>
    </div>

    <!-- Stats Row -->
    <div class="stats-grid mb-4">
        <div class="stat-card">
            <div class="stat-icon bg-primary text-white"><i class="fas fa-briefcase"></i></div>
            <div class="stat-info">
                <div class="stat-value"><?= is_array($stats) ? ($stats['total'] ?? 0) : ($stats->total ?? 0) ?></div>
                <div class="stat-label">Total Projects</div>
            </div>
        </div>
        <div class="stat-card">
            <div class="stat-icon bg-success text-white"><i class="fas fa-spinner"></i></div>
            <div class="stat-info">
                <div class="stat-value"><?= is_array($stats) ? ($stats['active'] ?? 0) : ($stats->active ?? 0) ?></div>
                <div class="stat-label">Active</div>
            </div>
        </div>
        <div class="stat-card">
            <div class="stat-icon bg-info text-white"><i class="fas fa-check-circle"></i></div>
            <div class="stat-info">
                <div class="stat-value"><?= is_array($stats) ? ($stats['completed'] ?? 0) : ($stats->completed ?? 0) ?></div>
                <div class="stat-label">Completed</div>
            </div>
        </div>
        <div class="stat-card">
            <div class="stat-icon bg-warning text-white"><i class="fas fa-coins"></i></div>
            <div class="stat-info">
                <div class="stat-value"><?= formatCurrency((float)(is_array($stats) ? ($stats['total_value'] ?? 0) : ($stats->total_value ?? 0))) ?></div>
                <div class="stat-label">Total Value</div>
            </div>
        </div>
    </div>

    <!-- Filter Bar -->
    <div class="card mb-4">
        <div class="card-body">
            <form action="<?= APP_URL ?>/projects" method="GET" class="d-flex gap-3 flex-wrap align-center">
                <div style="flex:1;min-width:200px;">
                    <input type="text" name="search" placeholder="Search projects..." value="<?= htmlspecialchars($filters['search'] ?? '') ?>" class="form-control">
                </div>
                <div style="width:180px;">
                    <select name="status" class="form-control form-select">
                        <option value="">All Statuses</option>
                        <option value="active" <?= ($filters['status'] ?? '') == 'active' ? 'selected' : '' ?>>Active</option>
                        <option value="completed" <?= ($filters['status'] ?? '') == 'completed' ? 'selected' : '' ?>>Completed</option>
                        <option value="draft" <?= ($filters['status'] ?? '') == 'draft' ? 'selected' : '' ?>>Draft</option>
                        <option value="on_hold" <?= ($filters['status'] ?? '') == 'on_hold' ? 'selected' : '' ?>>On Hold</option>
                    </select>
                </div>
                <button type="submit" class="btn btn-secondary"><i class="fas fa-filter"></i> Filter</button>
            </form>
        </div>
    </div>

    <?php if (empty($projects)): ?>
        <div class="empty-state card">
            <div class="empty-state-icon"><i class="fas fa-folder-open"></i></div>
            <h3 class="empty-state-title">No Projects Found</h3>
            <p class="empty-state-text">No projects match your criteria or none have been created yet.</p>
            <a href="<?= APP_URL ?>/projects/create" class="btn btn-primary"><i class="fas fa-plus"></i> Create First Project</a>
        </div>
    <?php else: ?>
        <div class="stats-grid">
            <?php foreach ($projects as $project): ?>
                <?php include __DIR__ . '/partials/project_card.php'; ?>
            <?php endforeach; ?>
        </div>
        <?php @include ROOT_PATH . '/modules/shared/views/partials/pagination.php'; ?>
    <?php endif; ?>
</div>
