{% extends 'base.html' %}

{% block title %}{{ resource.title }} - LMS{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="card shadow-sm">
        <div class="card-header">
            <div class="d-flex justify-content-between align-items-center">
                <h2>{{ resource.title }}</h2>
                <div>
                    <span class="badge bg-{% if resource.resource_type == 'document' %}primary{% elif resource.resource_type == 'video' %}danger{% elif resource.resource_type == 'link' %}success{% else %}secondary{% endif %}">
                        {{ resource.get_resource_type_display }}
                    </span>
                    {% if not resource.is_published %}
                    <span class="badge bg-warning">Draft</span>
                    {% endif %}
                </div>
            </div>
        </div>

        <div class="card-body">
            <p class="card-text">{{ resource.description }}</p>
            
            {% if resource.file %}
            <div class="mb-3">
                <strong>File:</strong> {{ resource.filename }}
                <br>
                <a href="{% url 'download_resource' resource.pk %}" class="btn btn-success mt-2">
                    <i class="fas fa-download"></i> Download File
                </a>
            </div>
            {% endif %}
            
            {% if resource.url %}
            <div class="mb-3">
                <strong>URL:</strong> 
                <a href="{{ resource.url }}" target="_blank" class="btn btn-info mt-2">
                    <i class="fas fa-external-link-alt"></i> Visit Link
                </a>
            </div>
            {% endif %}
            
            <div class="mt-4">
                <small class="text-muted">
                    Uploaded by: {{ resource.uploaded_by.get_full_name|default:resource.uploaded_by.username }}<br>
                    Created: {{ resource.created_at|date:"M d, Y H:i" }}<br>
                    {% if resource.updated_at != resource.created_at %}
                    Updated: {{ resource.updated_at|date:"M d, Y H:i" }}
                    {% endif %}
                </small>
            </div>
        </div>

        <div class="card-footer d-flex justify-content-between">
            <a href="{% url 'resources' %}" class="btn btn-secondary">
                <i class="fas fa-arrow-left"></i> Back to Resources
            </a>
            
            {% if is_trainer and resource.uploaded_by == request.user %}
            <div class="btn-group">
                <a href="{% url 'edit_resource' resource.pk %}" class="btn btn-warning">
                    <i class="fas fa-edit"></i> Edit
                </a>
                <form action="{% url 'delete_resource' resource.pk %}" method="post" class="d-inline">
                    {% csrf_token %}
                    <button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure you want to delete this resource?');">
                        <i class="fas fa-trash"></i> Delete
                    </button>
                </form>
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}
