{% from 'bacteria/form.html' import bacteria_add_form %}


{% macro pane_details(stock, form) %}

    {% if stock.disposal_date %}
        <div class="rounded border p-3 mb-3 opacity-50">
    {% else %}
        <div class="rounded border p-3 mb-3">
    {% endif %}

        <div class="d-flex align-items-start mb-3">

            <div class="flex-fill">

                <h5 class="mb-1">{{ stock.owner.username }}</h5>

                <p class="text-muted mb-1">
                    Generated on {{ stock.transformation_date | format_date }}
                </p>

            </div>

            <div class="flex-shrink-0">

                {% if current_user.has_permission('Add glycerol stocks') %}
                    <a class="text-primary ml-2 mr-2"
                       data-bs-toggle="modal"
                       data-bs-target="#modal-edit-glycerol-stock-{{ stock.id }}">
                        <i class="fa-solid fa-pen"></i>
                    </a>
                {% endif %}

            </div>

        </div>

        <div class="d-flex align-items-stretch">

            <div class="flex-fill pr-2 border-end">
                <p class="mb-0 text-center">Storage place</p>
                <p class="text-info fw-bold text-center">{{ stock.storage_place }}</p>
            </div>

            <div class="flex-fill pl-2 pr-2 border-end">
                <p class="mb-0 text-center">Plasmid</p>
                <p class="fw-bold text-center">{{ stock.plasmid.label }}</p>
            </div>

            <div class="flex-fill pl-2 pr-2 border-end">
                <p class="mb-0 text-center">Strain</p>
                <p class="fw-bold text-center">{{ stock.strain }}</p>
            </div>

            <div class="flex-fill pl-2">
                <p class="mb-0 text-center">Disposed</p>
                <p class="fw-bold text-center">
                    {% if stock.disposal_date %}
                        {{ stock.disposal_date | format_date }}
                    {% else %}
                        -
                    {% endif %}
                </p>
            </div>

        </div>

    </div>

    {{ bacteria_add_form(form(None, obj=stock), "plasmids.bacteria.edit", "PUT", stock.id, stock.plasmid_id) }}

{% endmacro %}


{% macro bacteria_pane(status, pane_id, plasmid, form) %}
    <div class="tab-pane container {{ status }}" id="{{ pane_id }}">

        <div class="d-flex justify-content-between align-items-center mb-3">
            <h2 class="flex-grow-1 mb-0">Bacterial stocks</h2>
            <div class="flex-shrink-0">
                {% if current_user.has_permission('Add glycerol stocks') %}
                    <button
                        type="button"
                        class="btn btn-success btn-sm"
                        data-bs-toggle="modal"
                        data-bs-target="#modal-edit-glycerol-stock--1">
                        <i class="fa-solid fa-plus"></i>
                    </button>
                {% endif %}
            </div>
        </div>


        {% for stock in plasmid.glycerol_stocks %}
            {{ pane_details(stock, form) }}
        {% else %}
            <div class="fw-bold text-center mb-3">No bacterial stocks for this
                plasmid!</div>
        {% endfor %}

        {{ bacteria_add_form(form(), "plasmids.bacteria.add", "POST", -1, plasmid.id) }}

    </div>
{% endmacro %}