{% extends 'cabinet/_internal_base.html' %}
{% load bootstrap4 %}

{% block breadcrumbs %}
    <li><a href="{% url 'cabinet:bots:index' %}">Bot list</a></li>
    <li><span>{{ title }}</span></li>
{% endblock %}

{% block content %}
    <form action="" method="post" class="card" enctype="multipart/form-data">
        {% csrf_token %}
        <header class="card-header">
            <h2 class="card-title">{% if feed %}Bot "{{ feed.title }}" configuration{% else %}New bot{% endif %}</h2>
        </header>
        <div class="card-body">
            <h4>General options</h4>
            {% bootstrap_form bot_form layout='horizontal' %}
            <hr>
            <h4>Module options</h4>
            {% bootstrap_form config_form layout='horizontal' %}
            {% if formset %}
                {% bootstrap_form formset.management_form layout='horizontal' %}
                {% for form in formset %}
                    {% bootstrap_form form layout='horizontal' %}
                {% endfor %}
            {% endif %}
        </div>
        <footer class="card-footer text-right">
            {% if feed %}<a href="#delete-modal" class="modal-basic btn btn-danger">Delete</a>{% endif %}
            <button type="submit" class="btn btn-primary">Save</button>
        </footer>
    </form>

    {% if feed %}
        <div id="delete-modal" class="modal-block modal-full-color modal-block-danger mfp-hide">
            <section class="card">
                <header class="card-header">
                    <h2 class="card-title">Delete bot "{{ feed.title }}"</h2>
                </header>
                <div class="card-body">
                    <div class="modal-wrapper">
                        <div class="modal-icon"><i class="fas fa-times-circle"></i></div>
                        <div class="modal-text">
                            <h4>Are you sure?</h4>
                            <p>This action cannot be undone.</p>
                        </div>
                    </div>
                </div>
                <footer class="card-footer">
                    <div class="row">
                        <form action="{% url 'cabinet:bots:delete' pk=feed.pk %}" method="post" class="col-md-12 text-right">
                            {% csrf_token %}
                            <button type="button" class="btn btn-default modal-dismiss">Cancel</button>
                            <button type="submit" class="btn btn-danger">Delete</button>
                        </form>
                    </div>
                </footer>
            </section>
        </div>
    {% endif %}
{% endblock %}

{% block extra_body %}
    {{ bot_form.media }}
    {{ config_form.media }}
{% endblock %}
