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

{% block title %}{% trans "Update Zoom Meeting" %} - {{ block.super }}{% endblock %}

{% block customCSS %}
<style>
    /* UI Variables for the KAAT-S Theme */
    :root {
        --kaauh-teal: #00636e;
        --kaauh-teal-dark: #004a53;
        --kaauh-border: #eaeff3;
        --kaauh-primary-text: #343a40;
        --kaauh-gray: #6c757d;

        /* Status Colors for Django messages/alerts */
        --kaauh-success: #28a745; 
        --kaauh-warning: #ffc107;
        --kaauh-danger: #dc3545;
        --kaauh-info: #17a2b8;
        --kaauh-secondary: #6c757d; /* Added for button consistency */
    }

    /* CARD STYLING */
    .card {
        border: 1px solid var(--kaauh-border);
        border-radius: 0.75rem;
        box-shadow: 0 4px 12px rgba(0,0,0,0.06);
        max-width: 600px; /* Constrain width for a better form layout */
        margin: 2rem auto; /* Center the form card */
    }
    
    /* HEADER STYLING */
    .card-header {
        background-color: white; /* Ensure header background is white */
        border-bottom: 1px solid var(--kaauh-border);
        padding: 1.5rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-top-left-radius: 0.75rem;
        border-top-right-radius: 0.75rem;
    }
    /* Grouping the main title and subtitle */
    .card-header-title-group { 
        display: flex; 
        flex-direction: column; 
        gap: 0.2rem;
    }
    .card-header h1 {
        font-size: 1.5rem;
        color: var(--kaauh-teal-dark);
        font-weight: 700;
        margin: 0;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
    .card-header h1 svg {
        width: 1.25rem;
        height: 1.25rem;
    }
    .card-header p { 
        color: var(--kaauh-gray);
        font-size: 0.9rem;
        margin: 0; /* Reset margin */
        padding-left: 1.75rem; /* Indent to align with text after SVG */
    }

    /* FORM STYLING */
    form {
        padding: 1.5rem;
    }
    .form-row {
        margin-bottom: 1.5rem;
    }
    .form-label {
        display: block;
        font-weight: 600;
        color: var(--kaauh-gray);
        margin-bottom: 0.5rem;
        font-size: 0.9rem;
    }
    .form-row input,
    .form-row select {
        display: block;
        width: 100%;
        padding: 0.75rem 1rem;
        font-size: 1rem;
        line-height: 1.5;
        color: var(--kaauh-primary-text);
        background-color: #fff;
        border: 1px solid var(--kaauh-border);
        border-radius: 0.5rem;
        transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    }
    .form-row input:focus,
    .form-row select:focus {
        border-color: var(--kaauh-teal);
        outline: 0;
        box-shadow: 0 0 0 0.1rem rgba(0, 99, 110, 0.25);
    }
    input[type="datetime-local"] {
        font-family: inherit;
    }

    /* BUTTON STYLING */
    .btn-base {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        text-align: center;
        vertical-align: middle;
        cursor: pointer;
        user-select: none;
        padding: 0.5rem 1rem;
        font-size: 1rem;
        line-height: 1.5;
        border-radius: 0.5rem;
        font-weight: 600;
        border: 1px solid transparent;
        transition: all 0.2s ease;
        text-decoration: none;
    }
    .btn-main-action {
        background-color: var(--kaauh-teal-dark);
        border-color: var(--kaauh-teal);
        color: white;
    }
    .btn-main-action:hover {
        background-color: var(--kaauh-teal-dark);
        border-color: var(--kaauh-teal-dark);
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
        color: white;
    }
    .btn-kaats-outline-secondary {
        color: var(--kaauh-secondary);
        border-color: var(--kaauh-secondary);
        background-color: transparent;
    }
    .btn-kaats-outline-secondary:hover {
        background-color: var(--kaauh-secondary);
        color: white;
        border-color: var(--kaauh-secondary);
    }

    /* MESSAGE STYLING (For Django messages) */
    .messages-container {
        max-width: 600px; 
        margin: 1rem auto;
    }
    .alert {
        padding: 0.75rem 1.25rem;
        margin-bottom: 1rem;
        border: 1px solid transparent;
        border-radius: 0.5rem;
        font-size: 0.95rem;
    }
    .alert-success { background-color: #d4edda; color: var(--kaauh-success); border-color: #c3e6cb; }
    .alert-danger { background-color: #f8d7da; color: var(--kaauh-danger); border-color: #f5c6cb; }
    .alert-info { background-color: #d1ecf1; color: var(--kaauh-info); border-color: #bee5eb; }
    .alert-warning { background-color: #fff3cd; color: var(--kaauh-warning); border-color: #ffeeba; }
</style>
{% endblock %}

{% block content %}
<div class="messages-container">
    {# Display Django messages outside the card. Using safe if/else for tag mapping. #}
    {% if messages %}
        <div class="messages">
            {% for message in messages %}
                {% if 'error' in message.tags %}
                    <div class="alert alert-danger">
                {% elif 'success' in message.tags %}
                    <div class="alert alert-success">
                {% elif 'warning' in message.tags %}
                    <div class="alert alert-warning">
                {% else %}
                    <div class="alert alert-info">
                {% endif %}
                        {{ message }}
                    </div>
            {% endfor %}
        </div>
    {% endif %}
</div>

<div class="card">
    <div class="card-header">
        <div class="card-header-title-group">
            <h1>
                <svg class="heroicon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
                    {# Using a generic edit/pencil icon for update #}
                    <path d="M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7m-8 6l-5 1 1-5 9.5-9.5a1.5 1.5 0 012.12 0l2.88 2.88a1.5 1.5 0 010 2.12L13 19z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
                </svg>
                {% trans "Update Zoom Meeting" %}
            </h1>
            <p>{% trans "Modify the details of your scheduled meeting" %}</p>
        </div>
        
        {# BUTTON 1: Back to Details (matching the visual style of the create page's "Back to Meetings") #}
        <a href="{% url 'meeting_details' meeting.slug %}" class="btn-base btn-kaats-outline-secondary">
            <svg class="heroicon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" style="width: 1.25rem;">
                 {# Arrow left icon #}
                <path d="M15 18l-6-6 6-6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
            </svg>
            {% trans "Back to Details" %}
        </a>
    </div>

    <form method="post" action="{% url 'update_meeting' meeting.slug %}">
        {% csrf_token %}

        <div class="form-row">
            <label class="form-label" for="{{ form.topic.id_for_label }}">{% trans "Topic" %}</label>
            {{ form.topic }}
        </div>
        <div class="form-row">
            <label class="form-label" for="{{ form.start_time.id_for_label }}">{% trans "Start Time" %}</label>
            {{ form.start_time }}
        </div>
        <div class="form-row">
            <label class="form-label" for="{{ form.duration.id_for_label }}">{% trans "Duration (minutes)" %}</label>
            {{ form.duration }}
        </div>

        {# BUTTONS 2 & 3: Action Buttons at the bottom #}
        <div class="form-row d-flex gap-3">
            <button type="submit" class="btn-base btn-main-action">
                <svg class="heroicon" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" style="width: 1.25rem;">
                    <path d="M5 13l4 4L19 7" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
                </svg>
                {% trans "Update Meeting" %}
            </button>
            
            <a href="{% url 'meeting_details' meeting.slug %}" class="btn-base btn-kaats-outline-secondary">
                {% trans "Cancel" %}
            </a>
        </div>
    </form>
</div>
{% endblock %}