{% from 'bootstrap/comps.buttons.html.j2' import btn_m %}

{% macro modal(title, size, content, action, btn=True) %}

    {% set modal_id=title.replace(' ', '') %}

    {% if btn %}
        {{ btn_m(title, modal_id) }}
    {% endif %}

    <div class="modal fade" tabindex="-1" role="dialog" id="{{ modal_id or 'newModal'}}">
        <div class="modal-dialog {{ ('modal-' ~ size) if size else '' }} modal-dialog-scrollable" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">{{ title or 'Modal' }}</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    {% if content is string %}
                        {{ content | safe }}
                    {% else %}
                        {{ content | render_form(action=url_for(action) or '',
                                                 button_map={'submit': 'primary btn-block'},
                                                 form_type='basic',
                                                 horizontal_columns=('lg', 4, 8)) }}
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
{% endmacro %}