<?php $pageTitle = t('projects'); ?>
<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('projects') ?></h1>
    </div>
    <a href="/project/create" class="btn btn-primary">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16"><path d="M12 5v14M5 12h14"/></svg>
        <?= t('new_project') ?>
    </a>
</div>

<!-- Status tabs -->
<div class="tab-bar">
    <a href="/projects?status=active" class="tab <?= $status === 'active' ? 'active' : '' ?>"><?= t('active') ?></a>
    <a href="/projects?status=archived" class="tab <?= $status === 'archived' ? 'active' : '' ?>"><?= t('archived') ?></a>
</div>

<?php if (empty($projects)): ?>
<div class="empty-state">
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" width="64" height="64" opacity=".3"><path d="M22 19a2 2 0 01-2 2H4a2 2 0 01-2-2V5a2 2 0 012-2h5l2 3h9a2 2 0 012 2z"/></svg>
    <h3><?= t('no_projects') ?></h3>
    <p><?= t('create_first') ?></p>
    <a href="/project/create" class="btn btn-primary"><?= t('new_project') ?></a>
</div>
<?php else: ?>
<div class="projects-grid projects-grid-full">
    <?php foreach ($projects as $project): ?>
    <div class="project-card">
        <div class="project-card-accent" style="background:<?= Helper::e($project['color']) ?>"></div>
        <div class="project-card-body">
            <div class="project-card-header">
                <a href="/project/<?= $project['id'] ?>" class="project-card-name"><?= Helper::e($project['name']) ?></a>
                <?php $myRole = $project['my_role'] ?? Auth::getProjectRole($project['id']); ?>
                <?php if (in_array($myRole, ['owner', 'manager'])): ?>
                <div class="project-card-actions">
                    <a href="/project/<?= $project['id'] ?>/settings" class="icon-btn-sm" title="<?= t('project_settings') ?>">
                        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16"><circle cx="12" cy="12" r="3"/><path d="M19.07 4.93A10 10 0 004.93 19.07M19.07 19.07A10 10 0 004.93 4.93"/></svg>
                    </a>
                    <a href="/project/<?= $project['id'] ?>/members" class="icon-btn-sm" title="<?= t('members') ?>">
                        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="16" height="16"><path d="M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 00-3-3.87M16 3.13a4 4 0 010 7.75"/></svg>
                    </a>
                </div>
                <?php endif; ?>
            </div>
            <?php if ($project['description']): ?>
            <div class="project-card-desc"><?= Helper::e(mb_substr($project['description'], 0, 120)) ?></div>
            <?php endif; ?>
            <div class="project-card-meta">
                <span>
                    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="12" height="12"><path d="M9 11l3 3L22 4"/></svg>
                    <?= $project['task_count'] ?> <?= t('tasks') ?>
                </span>
                <span>
                    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="12" height="12"><path d="M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2"/><circle cx="9" cy="7" r="4"/></svg>
                    <?= $project['member_count'] ?> <?= t('members') ?>
                </span>
                <span><?= Helper::e($project['owner_name']) ?></span>
            </div>
        </div>
        <div class="project-card-footer">
            <a href="/project/<?= $project['id'] ?>?view=kanban" class="project-view-link <?= str_contains($_SERVER['REQUEST_URI'] ?? '', 'kanban') ? 'active' : '' ?>"><?= t('kanban') ?></a>
            <a href="/project/<?= $project['id'] ?>?view=list" class="project-view-link"><?= t('list') ?></a>
            <a href="/project/<?= $project['id'] ?>?view=gantt" class="project-view-link"><?= t('gantt') ?></a>
        </div>
    </div>
    <?php endforeach; ?>
</div>
<?php endif; ?>
