{% extends "base.html" %}
{% load static i18n crispy_forms_tags %}

{% block title %}Update Training Material - {{ block.super }}{% endblock %}

{% block customCSS %}
<style>
    /* ================================================= */
    /* THEME VARIABLES AND GLOBAL STYLES */
    /* ================================================= */
    :root {
        --kaauh-teal: #00636e;
        --kaauh-teal-dark: #004a53;
        --kaauh-border: #eaeff3;
        --kaauh-primary-text: #343a40;
    }

    /* Primary Color Overrides */
    .text-primary { color: var(--kaauh-teal) !important; }

    /* Main Action Button Style */
    .btn-main-action, .btn-primary {
        background-color: var(--kaauh-teal);
        border-color: var(--kaauh-teal);
        color: white;
        font-weight: 600;
        padding: 0.6rem 1.2rem;
        transition: all 0.2s ease;
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
    }
    .btn-main-action:hover, .btn-primary:hover {
        background-color: var(--kaauh-teal-dark);
        border-color: var(--kaauh-teal-dark);
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    }
    
    /* Outlined Button Styles */
    .btn-secondary, .btn-outline-secondary {
        background-color: #f8f9fa;
        color: var(--kaauh-teal-dark);
        border: 1px solid var(--kaauh-teal);
        font-weight: 500;
    }
    .btn-secondary:hover, .btn-outline-secondary:hover {
        background-color: var(--kaauh-teal-dark);
        color: white;
        border-color: var(--kaauh-teal-dark);
    }

    /* Card enhancements */
    .card {
        border: 1px solid var(--kaauh-border);
        border-radius: 0.75rem;
        overflow: hidden;
        box-shadow: 0 4px 12px rgba(0,0,0,0.06);
        background-color: white;
    }
    
    /* Colored Header Card */
    .list-header-card {
        background: linear-gradient(135deg, var(--kaauh-teal), #004d57);
        color: white;
        border-radius: 0.75rem 0.75rem 0 0;
        padding: 1.5rem;
        box-shadow: 0 4px 10px rgba(0,0,0,0.15);
    }
    .list-header-card h1 {
        font-weight: 700;
        margin: 0;
        font-size: 1.8rem;
    }
    .heroicon {
        width: 1.25rem;
        height: 1.25rem;
        vertical-align: text-bottom;
        stroke: currentColor;
        margin-right: 0.5rem;
    }
    
    /* Form Fixes for consistency with manual rendering */
    .form-label {
        font-weight: 600;
        color: var(--kaauh-primary-text);
        margin-bottom: 0.3rem; /* Small space under label */
        display: block; /* Ensure full width for label */
    }
    
    /* Ensure form fields use Bootstrap's standard look */
    .form-control {
        border-radius: 0.5rem;
    }
</style>
{% endblock %}

{% block content %}
<div class="container-fluid py-4">
    
    <div class="card mb-4">
        <div class="list-header-card">
            <div class="d-flex justify-content-between align-items-start flex-wrap">
                <div class="flex-grow-1">
                    <h1 class="h3 mb-1">
                        <i class="fas fa-edit"></i> 
                        {% trans "Update Training Material:" %} {{ object.title }}
                    </h1>
                    <p class="text-white opacity-75 mb-0">{% trans "Edit the details of this training document or guide." %}</p>
                </div>
                <div class="d-flex gap-2 mt-1">
                    <a href="{% url 'training_list' %}" class="btn btn-outline-light btn-sm" title="{% trans 'Back to List' %}">
                        <i class="fas fa-arrow-left"></i>
                        <span class="d-none d-sm-inline">{% trans "Back to List" %}</span>
                    </a>
                    {% if object.pk %}
                        <a href="{% url 'training_detail' object.pk %}" class="btn btn-outline-light btn-sm" title="{% trans 'View Material' %}">
                            <i class="fas fa-eye"></i>
                            <span class="d-none d-sm-inline">{% trans "View" %}</span>
                        </a>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

    <div class="card shadow-sm">
        <div class="card-header bg-white border-bottom">
            <h2 class="h5 mb-0 text-primary">
                <i class="fas fa-file-alt me-1"></i>
                {% trans "Material Details" %}
            </h2>
        </div>
        
        <form method="post" enctype="multipart/form-data">
            {% csrf_token %}
            <div class="card-body">
                
                <div class="row g-4">
                    
                    {# Title and Video Link on a single row #}
                    <div class="col-md-6">
                        <div class="mb-0">
                            <label for="{{ form.title.id_for_label }}" class="form-label">{% trans "Title" %}</label>
                            {{ form.title|attr:"class:form-control" }}
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="mb-0">
                            <label for="{{ form.video_link.id_for_label }}" class="form-label">{% trans "Video Link" %}</label>
                            {{ form.video_link|attr:"class:form-control" }}
                        </div>
                    </div>
                    
                    {# Content (Full width) #}
                    <div class="col-12">
                        <div class="mb-0">
                            <label for="{{ form.content.id_for_label }}" class="form-label">{% trans "Content" %}</label>
                            {{ form.content|attr:"class:form-control"|attr:"rows:6" }}
                        </div>
                    </div>

                    {# File Upload (Full width as it's often complex) #}
                    <div class="col-12">
                        <div class="mb-0">
                            <label for="{{ form.file.id_for_label }}" class="form-label">{% trans "File" %}</label>
                            {{ form.file }}
                            {% if form.file.help_text %}
                                <div class="form-text">{{ form.file.help_text }}</div>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="card-footer bg-light border-top">
                <div class="d-flex justify-content-end gap-3">
                    <button type="submit" class="btn btn-main-action">
                        <i class="fas fa-save me-1"></i>
                        {% trans "Update Material" %}
                    </button>
                    <a href="{% url 'training_delete' object.pk %}" class="btn btn-danger" onclick="return confirm('{% trans "Are you sure you want to delete this material?" %}')">
                        <i class="fas fa-trash-alt me-1"></i>
                        {% trans "Delete" %}
                    </a>
                </div>
            </div>
        </form>
    </div>
</div>
{% endblock %}