{% from 'macros.html' import visualize_series, description_explanations %}

{% macro series_set_template_form(submit_text, template, sources, resource, cancel_url, reference_name=None, source_name=None) %}
<form method="POST">
    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
    {% if reference_name %}
    <input type="hidden" name="templatereferencename" value="{{ reference_name }}">
    {% endif %}
    {% if source_name %}
    <input type="hidden" name="sourcename" value="{{ source_name }}">
    {% endif %}

    <div
        class="series-set-template-form"
        data-template-name="{{ template.name }}"
        data-name-pattern="{{ template.name_pattern }}"
        data-source-name="{{ template.source_name }}"
        data-sources='{{ sources|tojson }}'
        data-grouping-pattern="{{ template.tag_grouping_pattern['series name'] }}"
        data-filter-field="{{ template.metadata_filters|first }}"
        data-filter-pattern="{{ template.metadata_filters.values()|first }}"
        data-template-description="{{ template.help_text }}"
        data-submit-button-text="{{ submit_text }}"
        data-has-errors="{{ (get_flashed_messages(category_filter=['error'])|count > 0)|tojson }}"
        data-cancel-url="{{ cancel_url }}"></div>

</form>
{% endmacro %}

{% macro series_sets_preview(series_sets) %}
<ul class="list-group list-group-flush">
    {% for pattern, series_set in series_sets|dictsort %}
    <li class="list-group-item px-0">
        <div class="row">
            <div class="col">
                <div class="input-group">
                    <input type="text" class="form-control bg-transparent" value="{{ series_set.name }}" readonly>
                    <span class="input-group-text">{{ pattern }}</span>
                </div>
            </div>
            <div class="col">
                <ul class="list-group">
                    {% for series in series_set.series|sort(attribute='name') %}
                    <li class="list-group-item py-2">
                        <a class="ts-table-link text-decoration-none text-dark" href="{{ url_for('prepare.tags', sourcename=series.source, seriesid=series.series_id) }}">
                            {{ visualize_series(series) }}
                        </a>
                    </li>
                {% endfor %}
                </ul>
            </div>
        </div>
    </li>
    {% endfor %}
</ul>
{% endmacro %}
