{% extends "rest_framework/base.html" %}
{% load request_static %}
{% load rest_framework %}

{% block content %}

        <section class="content-header">
            <h1>{% if name %}{{ name }}{% endif %}{% block description %}{% block.super %}{% endblock %}</h1>
            <ol class="breadcrumb">
                {% block breadcrumbs %}
                <li><a href="/"><i class="fas fa-tachometer-alt"></i> Home</a></li>
                {% for breadcrumb_name, breadcrumb_url in breadcrumblist %}
                    {% if forloop.last %}
                    <li class="active"><a href="{{ breadcrumb_url }}"> {{ breadcrumb_name }}</a></li>
                    {% else %}
                    <li><a href="{{ breadcrumb_url }}"> {{ breadcrumb_name }}</a></li>
                    {% endif %}
                {% endfor %}
                {% endblock %}
            </ol>
        </section>

        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        {% if 'GET' in allowed_methods %}
                        <form id="get-form" class="pull-right">
                            <fieldset>
                                <div class="btn-group format-selection no-print">
                                    <button class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
                                        Format <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu">
                                        {% for format in available_formats %}
                                        <li class="dropdown-item">
                                            <a class="format-option"
                                               href='{% add_query_param request api_settings.URL_FORMAT_OVERRIDE format %}'
                                               rel="nofollow">
                                                {{ format }}
                                            </a>
                                        </li>
                                        {% endfor %}
                                    </ul>
                                </div>
                            </fieldset>
                        </form>
                        {% endif %}

                        {% if post_form %}
                        <button type="button" class="button-form btn btn-primary no-print" data-toggle="modal" data-target="#createModal">
                            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Create
                        </button>
                        {% endif %}

                        {% if put_form %}
                        <button type="button" class="button-form btn btn-primary no-print" data-toggle="modal" data-target="#editModal">
                            <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span> Edit
                        </button>
                        {% endif %}

                        <button type="button" class="button-form btn btn-primary no-print" onclick="javaScript:window.print();" >
                            <span class="glyphicon glyphicon-print" aria-hidden="true"></span> Print
                        </button>

                        {% if delete_form %}
                        <form class="button-form no-print" action="{{ request.get_full_path }}" data-method="DELETE">
                            <button class="btn btn-danger">
                                <span class="fa fa-times" aria-hidden="true"></span> Delete
                            </button>
                        </form>
                        {% endif %}

                        {% if filter_form %}
                        <button style="float: right; margin-right: 10px" data-toggle="modal" data-target="#filtersModal" class="btn btn-default no-print">
                            <span class="glyphicon glyphicon-wrench" aria-hidden="true"></span>
                            {% trans "Filters" %}
                        </button>
                        {% endif %}

                        </div>
                    </div>
                    <br>
                    <div class="row">
                        <div class="col-md-12">
                            {% if paginator %}
                            <nav style="float: right" class="no-print" >
                                {% get_pagination_html paginator %}
                            </nav>
                            {% endif %}

                            <div class="box">
                                <!-- /.card-header -->
                                <div class="card-body">
                                    {% if style == 'list' %}
                                    {% include "rest_framework/admin/list.html" %}
                                    {% else %}
                                    {% include "rest_framework/admin/detail.html" %}
                                    {% endif %}
                                </div>
                            </div>

                            {% if paginator %}
                            <nav style="float: right" class="no-print" >
                                {% get_pagination_html paginator %}
                            </nav>
                            {% endif %}
                    </div>
                </div>
            </div>
    </section>

    <!-- Create Modal -->
    <div class="modal fade" id="createModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">Create</h4>
                </div>
                <form action="{{ request.get_full_path }}" method="POST" enctype="multipart/form-data" class="form-horizontal" novalidate>
                    <div class="modal-body">
                        <fieldset>
                            {% csrf_token %}
                            {{ post_form }}
                        </fieldset>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-primary">Save</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- Edit Modal -->
    <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">Edit</h4>
                </div>
                <form action="{{ request.get_full_path }}" data-method="PUT" enctype="multipart/form-data" class="form-horizontal" novalidate>
                    <div class="modal-body">
                        <fieldset>
                            {{ put_form }}
                        </fieldset>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-primary">Save</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    {% if error_form %}
    <!-- Errors Modal -->
    <div class="modal" id="errorModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">{{ error_title }}</h4>
                </div>
                <form action="{{ request.get_full_path }}" data-method="{{ request.method }}" enctype="multipart/form-data" class="form-horizontal" novalidate>
                    <div class="modal-body">
                        <fieldset>
                            {{ error_form }}
                        </fieldset>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                        <button type="submit" class="btn btn-primary">Save</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    {% endif %}

    {% if filter_form %}
    {{ filter_form }}
    {% endif %}

{% endblock %}

