{% extends 'base.html' %}

{% block title %}{{ staff.user.get_full_name|default:staff.user.username }} - Staff Details{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="row">
        <div class="col-md-4">
            <div class="card mb-4">
                <div class="card-body text-center">
                    <div class="mb-3">
                        {% if staff.photo %}
                            <img src="{{ staff.photo.url }}" alt="{{ staff.user.get_full_name }}" class="img-fluid rounded-circle" style="width: 150px; height: 150px; object-fit: cover;">
                        {% else %}
                            <div class="bg-light rounded-circle d-flex align-items-center justify-content-center" style="width: 150px; height: 150px; margin: 0 auto;">
                                <i class="fas fa-user fa-4x text-muted"></i>
                            </div>
                        {% endif %}
                    </div>
                    <h3>{{ staff.user.get_full_name|default:staff.user.username }}</h3>
                    <p class="text-muted">{{ staff.position|default:"Staff Member" }}</p>
                    
                    <div class="mb-3">
                        {% if staff.is_active %}
                            <span class="badge bg-success">Active</span>
                        {% else %}
                            <span class="badge bg-secondary">Inactive</span>
                        {% endif %}
                    </div>
                    
                    <div class="d-flex justify-content-center gap-2 mb-3">
                        <a href="{% url 'appointments:staff-update' staff.pk %}" class="btn btn-primary btn-sm">
                            <i class="fas fa-edit"></i> Edit
                        </a>
                        <a href="{% url 'appointments:staff-delete' staff.pk %}" class="btn btn-danger btn-sm"
                           onclick="return confirm('Are you sure you want to delete this staff member? This action cannot be undone.');">
                            <i class="fas fa-trash"></i> Delete
                        </a>
                    </div>
                </div>
            </div>
            
            <div class="card mb-4">
                <div class="card-header">
                    <h5 class="mb-0">Contact Information</h5>
                </div>
                <div class="card-body">
                    <p class="mb-1"><i class="fas fa-envelope me-2"></i> {{ staff.user.email }}</p>
                    {% if staff.phone_number %}
                        <p class="mb-1"><i class="fas fa-phone me-2"></i> {{ staff.phone_number }}</p>
                    {% endif %}
                    {% if staff.bio %}
                        <hr>
                        <h6>Bio</h6>
                        <p class="small">{{ staff.bio }}</p>
                    {% endif %}
                </div>
            </div>
            
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">Services</h5>
                </div>
                <div class="card-body">
                    {% if services %}
                        <ul class="list-group list-group-flush">
                            {% for service in services %}
                                <li class="list-group-item px-0">
                                    <div class="d-flex justify-content-between align-items-center">
                                        <span>{{ service.name }}</span>
                                        <span class="badge bg-primary">{{ service.duration|time:"H:i" }}</span>
                                    </div>
                                </li>
                            {% endfor %}
                        </ul>
                    {% else %}
                        <p class="text-muted mb-0">No services assigned</p>
                    {% endif %}
                </div>
            </div>
        </div>
        
        <div class="col-md-8">
            <div class="card mb-4">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="mb-0">Upcoming Appointments</h5>
                    <a href="{% url 'appointments:appointment-create' %}?staff={{ staff.id }}" class="btn btn-primary btn-sm">
                        <i class="fas fa-plus"></i> New Appointment
                    </a>
                </div>
                <div class="card-body">
                    {% if upcoming_appointments %}
                        <div class="table-responsive">
                            <table class="table table-hover">
                                <thead>
                                    <tr>
                                        <th>Date & Time</th>
                                        <th>Client</th>
                                        <th>Service</th>
                                        <th>Status</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for appointment in upcoming_appointments %}
                                        <tr>
                                            <td>{{ appointment.start_time|date:"M d, Y H:i" }}</td>
                                            <td>{{ appointment.client.get_full_name|default:appointment.client.username }}</td>
                                            <td>{{ appointment.service.name }}</td>
                                            <td>
                                                <span class="badge {% if appointment.status == 'confirmed' %}bg-success{% elif appointment.status == 'cancelled' %}bg-danger{% else %}bg-warning{% endif %}">
                                                    {{ appointment.get_status_display }}
                                                </span>
                                            </td>
                                            <td>
                                                <a href="{% url 'appointment-detail' appointment.pk %}" class="btn btn-sm btn-outline-primary">
                                                    <i class="fas fa-eye"></i>
                                                </a>
                                            </td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    {% else %}
                        <p class="text-muted mb-0">No upcoming appointments</p>
                    {% endif %}
                </div>
            </div>
            
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">Recent Completed Appointments</h5>
                </div>
                <div class="card-body">
                    {% if recent_appointments %}
                        <div class="table-responsive">
                            <table class="table table-sm">
                                <thead>
                                    <tr>
                                        <th>Date</th>
                                        <th>Client</th>
                                        <th>Service</th>
                                        <th>Duration</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for appointment in recent_appointments %}
                                        <tr>
                                            <td>{{ appointment.start_time|date:"M d, Y" }}</td>
                                            <td>{{ appointment.client.get_full_name|default:appointment.client.username }}</td>
                                            <td>{{ appointment.service.name }}</td>
                                            <td>{{ appointment.service.duration|time:"H:i" }}</td>
                                        </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    {% else %}
                        <p class="text-muted mb-0">No recent completed appointments</p>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
    
    <div class="mt-4">
        <a href="{% url 'appointments:staff-list' %}" class="btn btn-outline-secondary">
            <i class="fas fa-arrow-left"></i> Back to Staff List
        </a>
    </div>
</div>
{% endblock %}

{% block extra_css %}
<style>
    .card {
        margin-bottom: 1.5rem;
        border: none;
        box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    }
    .card-header {
        background-color: #f8f9fa;
        border-bottom: 1px solid rgba(0, 0, 0, 0.125);
    }
    .table {
        margin-bottom: 0;
    }
    .table th {
        border-top: none;
        font-weight: 600;
    }
    .badge {
        font-weight: 500;
    }
</style>
{% endblock %}
