{% extends 'base.html' %}
{% load static %}

{% block title %}Staff Members{% endblock %}

{% block content %}
<div class="container">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1>Staff Members</h1>
        {% if user.is_staff %}
            <a href="{% url 'appointments:staff-create' %}" class="btn btn-primary">
                <i class="fas fa-plus"></i> Add Staff Member
            </a>
        {% endif %}
    </div>

    <div class="card shadow mb-4">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Email</th>
                            <th>Services</th>
                            <th>Status</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for staff in staff_members %}
                        <tr>
                            <td>
                                <a href="{% url 'appointments:staff-detail' staff.pk %}">
                                    {{ staff.user.get_full_name|default:staff.user.username }}
                                </a>
                            </td>
                            <td>{{ staff.user.email }}</td>
                            <td>
                                {% for service in staff.services.all %}
                                    <span class="badge bg-primary me-1">{{ service.name }}</span>
                                {% empty %}
                                    <span class="text-muted">No services assigned</span>
                                {% endfor %}
                            </td>
                            <td>
                                {% if staff.user.is_active %}
                                    <span class="badge bg-success">Active</span>
                                {% else %}
                                    <span class="badge bg-secondary">Inactive</span>
                                {% endif %}
                            </td>
                            <td>
                                <div class="btn-group">
                                    <a href="{% url 'appointments:staff-detail' staff.pk %}" class="btn btn-sm btn-outline-primary">
                                        <i class="fas fa-eye"></i>
                                    </a>
                                    {% if user.is_staff %}
                                        <a href="{% url 'appointments:staff-update' staff.pk %}" class="btn btn-sm btn-outline-secondary">
                                            <i class="fas fa-edit"></i>
                                        </a>
                                        <a href="{% url 'appointments:staff-delete' staff.pk %}" class="btn btn-sm btn-outline-danger">
                                            <i class="fas fa-trash"></i>
                                        </a>
                                    {% endif %}
                                </div>
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="5" class="text-center">
                                <p class="text-muted">No staff members found.</p>
                                {% if user.is_staff %}
                                    <a href="{% url 'appointments:staff-create' %}" class="btn btn-primary">
                                        <i class="fas fa-plus"></i> Add Staff Member
                                    </a>
                                {% endif %}
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}
