{% import 'macros/forms.html' as forms %}
{% import 'macros/modal.html' as modal %}


{% macro plasmid_add_form(form, endpoint, method, id) %}

    {% if id == -1 %}
        {% set action = url_for(endpoint) %}
        {% set title = 'Add Plasmid' %}
    {% else %}
        {% set action = url_for(endpoint, id_=id) %}
        {% set title = 'Edit Plasmid' %}
    {% endif %}

    {% set modal_id = 'modal-edit-plasmid-' ~ id %}
    {% set form_id = 'form-edit-plasmid-' ~ id %}

    {% call modal.modal(id=modal_id, title=title) %}

        <form action="{{ action }}" method="get" id="{{ form_id }}">

            {{ form.hidden_tag() }}

            <div class="row mb-3">
                {{ forms.field_row(form.label, 'Name') }}
            </div>

            <div class="row mb-3">
                {{ forms.field_row(form.cloning_date, 'Cloning date') }}
            </div>

            <div class="row mb-3">
                {{ forms.field_row(form.insert, 'Insert') }}
            </div>

            <div class="row mb-3">
                {{ forms.field_row(form.vector, 'Vector') }}
            </div>

            <div class="row mb-3">
                {{ forms.field_row(form.reference, 'Reference') }}
            </div>

            <div class="row mb-3">
                {{ forms.field_row(form.description, 'Description') }}
            </div>

            <div class="row mb-3">
                <div class="col-sm-10">
                    {{ form.submit() }}
                </div>
            </div>

        </form>

        <div id="form-edit-plasmid-{{ id }}-messages"></div>

        {{ forms.script_send_form(
            form=form,
            form_name=form_id,
            method=method,
            message_field=form_id ~ '-messages'
            ) }}

    {% endcall %}

{% endmacro %}



{% macro upload_plasmid_form(form, endpoint, id, type) %}

    {% if type == 'map' %}
        {% set title = 'Upload plasmid map' %}
    {% elif type == 'plasmid' %}
        {% set title = 'Upload plasmid file' %}
    {% endif %}

    {% set modal_id = 'modal-upload-' ~ id ~ '-' ~ type %}

    {% call modal.modal(id=modal_id, title=title) %}

        <form action="{{ url_for(endpoint, id_=id, type_=type) }}"
              method="POST"
              enctype=multipart/form-data>

            {{ form.hidden_tag() }}

            <div class="row mb-3">
                {{ forms.field_row(form.file, 'File') }}
            </div>

            <div class="row mb-3">
                <div class="col-sm-10">
                    {{ form.submit() }}
                </div>
            </div>

        </form>

    {% endcall %}

{% endmacro %}