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

{% block content %}
<div class="container-fluid py-4">
    <div class="row justify-content-center">
        <div class="col-lg-6">
            <div class="card shadow-sm border-0">
                <div class="card-header bg-white py-3 fw-bold">
                    {% if form.instance.pk %}Редактировать ТО{% else %}Запланировать ТО{% endif %}
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}
                        {% for field in form %}
                        <div class="mb-3">
                            <label class="form-label small fw-bold">{{ field.label }}</label>
                            {{ field }}
                            {% if field.help_text %}
                            <div class="form-text">{{ field.help_text }}</div>
                            {% endif %}
                            {% for error in field.errors %}
                            <div class="text-danger small">{{ error }}</div>
                            {% endfor %}
                        </div>
                        {% endfor %}
                        <div class="mt-4 pt-3 border-top">
                            <button type="submit" class="btn btn-primary px-4 rounded-pill">Сохранить</button>
                            <a href="{% url 'maintenance_list' %}" class="btn btn-link text-muted">Отмена</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    // Add bootstrap classes to form fields
    document.querySelectorAll('input, select, textarea').forEach(el => {
        if (!el.classList.contains('form-check-input')) {
            el.classList.add('form-control');
        }
    });
</script>
{% endblock %}
