<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>BentWookie{% block title_suffix %}{% endblock %}</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
    <link rel="icon" type="image/png" href="{{ url_for('static', filename='icons/logocircle.png') }}">
</head>
<body>
    <nav class="navbar">
        <div class="nav-brand">
            <img src="{{ url_for('static', filename='icons/logocircle.png') }}" alt="BentWookie">
            <a href="{{ url_for('index') }}">BentWookie</a>
        </div>
        <ul class="nav-links">
            <li>
                <a href="{{ url_for('index') }}" {% if page == 'dashboard' %}class="active"{% endif %}>
                    <img src="{{ url_for('static', filename='icons/ui_dashboard.png') }}" alt="" class="nav-icon">
                    Dashboard
                </a>
            </li>
            <li>
                <a href="{{ url_for('projects_list') }}" {% if page == 'projects' %}class="active"{% endif %}>
                    <img src="{{ url_for('static', filename='icons/ui_viewproject.png') }}" alt="" class="nav-icon">
                    Projects
                </a>
            </li>
            <li>
                <a href="{{ url_for('requests_list') }}" {% if page == 'requests' %}class="active"{% endif %}>
                    <img src="{{ url_for('static', filename='icons/ui_editrequest.png') }}" alt="" class="nav-icon">
                    Requests
                </a>
            </li>
            <li>
                <a href="{{ url_for('status_page') }}" {% if page == 'status' %}class="active"{% endif %}>
                    <img src="{{ url_for('static', filename='icons/ui_viewloop.png') }}" alt="" class="nav-icon">
                    Status
                </a>
            </li>
        </ul>
    </nav>

    <main class="container">
        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    <div class="alert alert-{{ category }}">{{ message }}</div>
                {% endfor %}
            {% endif %}
        {% endwith %}

        {% block content %}
        {% if page == 'dashboard' %}
        <div class="page-header">
            <h1>
                <img src="{{ url_for('static', filename='icons/ui_dashboard.png') }}" alt="">
                Dashboard
            </h1>
            <div class="button-group">
                <a href="{{ url_for('project_new') }}" class="btn btn-primary">
                    <img src="{{ url_for('static', filename='icons/ui_editproject.png') }}" alt="">
                    New Project
                </a>
                <a href="{{ url_for('request_new') }}" class="btn btn-primary">
                    <img src="{{ url_for('static', filename='icons/ui_editrequest.png') }}" alt="">
                    New Request
                </a>
            </div>
        </div>

        <div class="stats-grid">
            <div class="stat-card">
                <h3>Projects</h3>
                <span class="stat-value">{{ stats.projects }}</span>
            </div>
            <div class="stat-card">
                <h3>Requests</h3>
                <span class="stat-value">{{ stats.requests }}</span>
            </div>
            <div class="stat-card">
                <h3>Pending</h3>
                <span class="stat-value">{{ stats.pending }}</span>
            </div>
            <div class="stat-card">
                <h3>In Progress</h3>
                <span class="stat-value">{{ stats.in_progress }}</span>
            </div>
            <div class="stat-card stat-success">
                <h3>Done</h3>
                <span class="stat-value">{{ stats.done }}</span>
            </div>
            <div class="stat-card stat-error">
                <h3>Errors</h3>
                <span class="stat-value">{{ stats.errors }}</span>
            </div>
        </div>

        <section class="section">
            <h2>
                <img src="{{ url_for('static', filename='icons/ui_viewdetails.png') }}" alt="">
                Recent Requests
            </h2>
            {% if recent_requests %}
            <table class="table">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Project</th>
                        <th>Name</th>
                        <th>Phase</th>
                        <th>Status</th>
                    </tr>
                </thead>
                <tbody>
                    {% for r in recent_requests %}
                    <tr>
                        <td><a href="{{ url_for('request_view', reqid=r.reqid) }}">{{ r.reqid }}</a></td>
                        <td>{{ r.prjname }}</td>
                        <td>{{ r.reqname }}</td>
                        <td><span class="badge badge-phase">{{ PHASE_NAMES.get(r.reqphase, r.reqphase) }}</span></td>
                        <td><span class="badge badge-{{ r.reqstatus }}">{{ STATUS_NAMES.get(r.reqstatus, r.reqstatus) }}</span></td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
            {% else %}
            <p class="empty-state">No requests yet. <a href="{{ url_for('request_new') }}">Create one</a></p>
            {% endif %}
        </section>

        <section class="section">
            <h2>
                <img src="{{ url_for('static', filename='icons/ui_pipeline.png') }}" alt="">
                Quick Actions
            </h2>
            <div class="button-group">
                <a href="{{ url_for('project_new') }}" class="btn btn-primary">
                    <img src="{{ url_for('static', filename='icons/ui_editproject.png') }}" alt="">
                    New Project
                </a>
                <a href="{{ url_for('request_new') }}" class="btn btn-primary">
                    <img src="{{ url_for('static', filename='icons/ui_editrequest.png') }}" alt="">
                    New Request
                </a>
            </div>
        </section>
        {% endif %}
        {% endblock %}
    </main>

    <footer class="footer">
        <img src="{{ url_for('static', filename='icons/logocircle.png') }}" alt="BentWookie">
        <p>BentWookie v0.2.0 - AI Coding Loop Workflow Manager</p>
    </footer>
</body>
</html>
