<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}Fox Fitt | Work & Payroll{% endblock %}</title>
    {% if project_description %}
    <meta name="description" content="{{ project_description }}">
    {% endif %}
    {% load static %}
    <!-- Bootstrap 5 CDN -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Poppins:wght@600;700&display=swap" rel="stylesheet">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <!-- Custom CSS -->
    <link rel="stylesheet" href="{% static 'css/custom.css' %}?v={{ deployment_timestamp }}">
    {% block head %}{% endblock %}
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark">
        <div class="container">
            <a class="navbar-brand heading-font fw-bold" href="{% url 'home' %}">
                <span style="color: var(--accent-color);">Fox</span> Fitt
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ms-auto align-items-center">
                    {% if user.is_authenticated %}
                        {# Dashboard - visible to Admin & Work Logger #}
                        {% if user.is_staff or user.is_superuser or perms.core.view_project or user.managed_teams.exists or user.assigned_projects.exists %}
                            <li class="nav-item"><a class="nav-link" href="{% url 'home' %}">Dashboard</a></li>
                        {% endif %}

                        {# Log Work - visible to Admin & Work Logger #}
                        {% if user.is_staff or user.is_superuser or perms.core.add_worklog or user.managed_teams.exists or user.assigned_projects.exists %}
                            <li class="nav-item"><a class="nav-link" href="{% url 'log_attendance' %}">Log Work</a></li>
                        {% endif %}

                        {# History - visible to Admin & Work Logger #}
                        {% if user.is_staff or user.is_superuser or perms.core.view_worklog or user.managed_teams.exists or user.assigned_projects.exists %}
                            <li class="nav-item"><a class="nav-link" href="{% url 'work_log_list' %}">History</a></li>
                        {% endif %}

                        {# Payroll - Admin only #}
                        {% if user.is_staff or user.is_superuser %}
                            <li class="nav-item"><a class="nav-link" href="{% url 'payroll_dashboard' %}">Payroll</a></li>
                        {% endif %}

                        {# Receipts - visible to Admin & Work Logger #}
                        {% if user.is_staff or user.is_superuser or perms.core.add_expensereceipt or user.managed_teams.exists or user.assigned_projects.exists %}
                            <li class="nav-item"><a class="nav-link" href="{% url 'create_receipt' %}">Receipts</a></li>
                        {% endif %}

                        <li class="nav-item dropdown ms-lg-3">
                            <a class="nav-link dropdown-toggle btn btn-sm btn-outline-light text-white px-3" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                                {{ user.username }}
                            </a>
                            <ul class="dropdown-menu dropdown-menu-end shadow border-0" aria-labelledby="userDropdown">
                                {% if user.is_staff or user.is_superuser %}
                                <li><a class="dropdown-item" href="/admin/">Admin Panel</a></li>
                                <li><hr class="dropdown-divider"></li>
                                {% endif %}
                                <li>
                                    <form action="{% url 'logout' %}" method="post" style="display: inline;">
                                        {% csrf_token %}
                                        <button type="submit" class="dropdown-item">Logout</button>
                                    </form>
                                </li>
                            </ul>
                        </li>
                    {% else %}
                        <li class="nav-item"><a class="nav-link btn btn-sm btn-primary px-3" href="{% url 'login' %}">Login</a></li>
                    {% endif %}
                </ul>
            </div>
        </div>
    </nav>

    <main>
        {% if messages %}
        <div class="container mt-3">
            {% for message in messages %}
            <div class="alert alert-{{ message.tags|default:'info' }} alert-dismissible fade show" role="alert">
                {{ message }}
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
            {% endfor %}
        </div>
        {% endif %}
        
        {% block content %}{% endblock %}
    </main>

    <footer class="py-4 mt-5 border-top bg-light">
        <div class="container text-center text-muted small">
            &copy; 2026 Fox Fitt Management System. All rights reserved.
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>