{% extends 'base.html' %}
{% block title %}Jobs - {{ company.name }}{% endblock %}
{% block content %}
<div class="container py-5">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <h1 class="h2 mb-1">Repair Jobs</h1>
            <p class="text-muted">Manage and track all repairs for {{ company.name }}</p>
        </div>
        <div class="d-flex gap-2">
            <div class="dropdown">
                <button class="btn btn-outline-secondary dropdown-toggle" type="button" id="bulkActionsDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                    <i class="bi bi-gear me-1"></i> Bulk Actions
                </button>
                <ul class="dropdown-menu dropdown-menu-end border-0 shadow" aria-labelledby="bulkActionsDropdown">
                    <li><a class="dropdown-item" href="{% url 'job_import' %}"><i class="bi bi-cloud-upload me-2 text-primary"></i> Import Jobs</a></li>
                    <li><a class="dropdown-item" href="{% url 'job_export' %}"><i class="bi bi-file-earmark-excel me-2 text-success"></i> Export All to Excel</a></li>
                </ul>
            </div>
            <a href="{% url 'job_create' %}" class="btn btn-primary">
                <i class="bi bi-plus-lg me-1"></i> Create New Job
            </a>
        </div>
    </div>

    {% if messages %}
    {% for message in messages %}
    <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
        {{ message }}
        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
    </div>
    {% endfor %}
    {% endif %}

    <div class="card border-0 shadow-sm overflow-hidden">
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead class="table-light">
                    <tr>
                        <th class="ps-4">Job Ref</th>
                        {% if company.is_uprn_required %}
                        <th>UPRN</th>
                        {% endif %}
                        <th>Address</th>
                        <th>Status</th>
                        <th>Created</th>
                        <th class="text-end pe-4">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for job in jobs %}
                    <tr>
                        <td class="ps-4 fw-semibold">{{ job.job_ref }}</td>
                        {% if company.is_uprn_required %}
                        <td>{{ job.uprn }}</td>
                        {% endif %}
                        <td>
                            <div class="small fw-medium">{{ job.address_line_1 }}</div>
                            <div class="text-muted small">{{ job.postcode }}</div>
                        </td>
                        <td>
                            <span class="badge rounded-pill bg-primary bg-opacity-10 text-primary px-3 py-2">
                                {{ job.status.name }}
                            </span>
                        </td>
                        <td class="text-muted small">{{ job.created_at|date:"M d, Y" }}</td>
                        <td class="text-end pe-4">
                            <div class="btn-group">
                                <a href="{% url 'job_detail' job.pk %}" class="btn btn-sm btn-outline-secondary">View</a>
                                <a href="{% url 'job_update' job.pk %}" class="btn btn-sm btn-outline-primary">Edit</a>
                            </div>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="{% if company.is_uprn_required %}6{% else %}5{% endif %}" class="text-center py-5">
                            <div class="py-4">
                                <div class="bg-light rounded-circle d-inline-flex p-4 mb-3">
                                    <i class="bi bi-tools fs-1 text-muted"></i>
                                </div>
                                <p class="text-muted">No jobs found. Start by creating your first repair job or import them from Excel.</p>
                                <div class="d-flex justify-content-center gap-2 mt-3">
                                    <a href="{% url 'job_create' %}" class="btn btn-primary btn-sm">Create Job</a>
                                    <a href="{% url 'job_import' %}" class="btn btn-outline-secondary btn-sm">Import Excel</a>
                                </div>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}