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

{% block title %}Assign Task{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header bg-primary text-white">
                    <h4 class="mb-0">Assign Task</h4>
                </div>
                <div class="card-body">
                    <form method="post" class="needs-validation" novalidate>
                        {% csrf_token %}
                        
                        {% if form.non_field_errors %}
                            <div class="alert alert-danger">
                                {% for error in form.non_field_errors %}
                                    {{ error }}
                                {% endfor %}
                            </div>
                        {% endif %}
                        
                        <div class="mb-3">
                            {{ form.assigned_to.label_tag }}
                            {{ form.assigned_to }}
                            {% if form.assigned_to.errors %}
                                <div class="invalid-feedback d-block">
                                    {{ form.assigned_to.errors.0 }}
                                </div>
                            {% endif %}
                        </div>
                        
                        <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                            <a href="{% url 'dashboards:head_dashboard' %}" class="btn btn-secondary me-md-2">
                                <i class="fas fa-arrow-left me-1"></i> Back to Dashboard
                            </a>
                            <button type="submit" class="btn btn-primary">
                                <i class="fas fa-user-plus me-1"></i> Assign Task
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
// Enable form validation
(function () {
    'use strict'
    
    // Fetch the form we want to apply custom Bootstrap validation styles to
    const form = document.querySelector('.needs-validation')
    
    // Prevent submission if form is invalid
    form.addEventListener('submit', function (event) {
        if (!form.checkValidity()) {
            event.preventDefault()
            event.stopPropagation()
        }
        
        form.classList.add('was-validated')
    }, false)
})()
</script>
{% endblock %}
