{% extends 'base.html' %}

{% block title %}{% if object %}Редактировать тег{% else %}Создать тег{% endif %}{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="row justify-content-center">
        <div class="col-sm-6 col-md-5 col-lg-4">
            <div class="card shadow-sm border-0">
                <div class="card-body p-4">
                    <h5 class="text-center mb-4">
                        <i class="bi bi-tag{% if not object %}-fill{% endif %} text-primary"></i>
                        {% if object %}Редактировать{% else %}Новый тег{% endif %}
                    </h5>

                    <form method="post">
                        {% csrf_token %}

                        <div class="mb-3">
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-type"></i></span>
                                {{ form.name }}
                            </div>
                            {% if form.name.errors %}<small class="text-danger">{{ form.name.errors.0 }}</small>{% endif %}
                        </div>

                        <div class="mb-3">
                            <div class="input-group">
                                <span class="input-group-text"><i class="bi bi-link-45deg"></i></span>
                                {{ form.slug }}
                            </div>
                            {% if form.slug.errors %}<small class="text-danger">{{ form.slug.errors.0 }}</small>{% endif %}
                        </div>

                        <div class="form-check form-switch mb-4">
                            {{ form.is_active }}
                            <label class="form-check-label small" for="id_is_active">Активен</label>
                        </div>

                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary">
                                <i class="bi bi-check2"></i> {% if object %}Сохранить{% else %}Создать{% endif %}
                            </button>
                            <a href="{% url 'products:tag-list' %}" class="btn btn-light btn-sm">Отмена</a>
                        </div>
                    </form>

                    {% if object %}
                    <hr class="my-3">
                    <small class="text-muted d-block text-center">
                        <i class="bi bi-clock-history"></i> {{ object.updated_at|date:"d.m.Y H:i" }}
                    </small>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}
