{% extends 'timeseer.html' %}

{% from 'macros.html' import bootstrap_icon, menu %}
{% from 'resources.html' import resource_breadcrumb %}

{% macro series_set_menu(active) %}
{{
    menu(
        (bootstrap_icon('arrow-left', 'h5 fw-bolder m-0', 24), url_for('series_sets.show_series_sets', sourcename=source_name)),
        [
            ('Time series', url_for('series_sets.manage_series_set', seriessetname=series_set.name, sourcename=source_name)),
            ('Metadata', url_for('series_sets.manage_series_set_metadata', seriessetname=series_set.name, sourcename=source_name)),
        ],
        active,
    )
}}
{% endmacro %}

{% block breadcrumb %}
{{
    resource_breadcrumb([
        ("Series sets", url_for('series_sets.show_series_sets', sourcename=source_name)),
        series_set.name,
    ])
}}
{% endblock %}

{% block main %}
<div class="ts-section pb-3 mb-3">
    <div class="row align-items-center gx-2">
        <div class="col-sm">
            <h2 class="h4">{% block series_set_title %}Time series{% endblock %}</h2>
            <p class="h6 text-break">{{ series_set.name }}</p>
        </div>
        {% if series_set.origin.value == 'ui' %}
        <div class="col-sm-auto">
            <div class="btn-toolbar" role="toolbar">
                {% block custom_actions %}
                {% endblock %}
                <div class="dropdown">
                    <button class="btn btn-secondary dropdown-toggle" type="button" id="editDropdown" data-bs-toggle="dropdown">
                        Edit
                    </button>
                    <ul class="dropdown-menu" aria-labelledby="editDropdown">
                        <li>
                            <a class="dropdown-item" href="{{ url_for('.rename_series_set', seriessetname=series_set.name, sourcename=source_name) }}">
                             Rename
                            </a>
                        </li>
                        {% if is_in_use %}
                        <li data-bs-toggle="tooltip" data-bs-placement="left" title="Series set is in use">
                            <a class="dropdown-item disabled" tabindex="-1" aria-disabled="true">Remove</a>
                        </li>
                        {% else %}
                        <li>
                            <a class="dropdown-item"
                               href="{{ url_for('.remove_series_set', seriessetname=series_set.name, sourcename=source_name) }}">
                                Remove
                            </a>
                        </li>
                        {% endif %}
                    </ul>
                </div>
            </div>
        </div>
        {% endif %}
    </div>
</div>

{% if series_set.short_help_text != "" and series_set.origin.value == 'ui' %}
<div class="pt-3 my-3">
    {% if series_set.short_help_text != "" %}
    <p>
        {{ series_set.short_help_text }}
        <a data-bs-toggle="offcanvas"
           href="#series-set-help-text"
           aria-controls="series-set-help-text"
           aria-expanded="false">
            {{ bootstrap_icon('question-circle') }}
        </a>
    </p>
    {% else %}
        {% if series_set.origin.value == 'ui' %}
        <p>
            No description provided
            <a href="{{ url_for('.edit_kpi_set_help_text', seriessetid=series_set.db_id, sourcename=source_name) }}">
                (add)
            </a>.
        </p>
        {% endif %}
    {% endif %}

    <div class="offcanvas offcanvas-end" tabindex="-1" id="series-set-help-text">
        <div class="offcanvas-header">
            <h3 class="offcanvas-title h5">{{ series_set.name }}</h3>
            <button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
        </div>
        <div class="offcanvas-body">
            <p>{{ series_set.short_help_text }}</p>
            <div>{{ series_set.html_help_text|safe }}</div>
            {% if series_set.origin.value == 'ui' %}
            <p class="mt-3">
                <a class="btn btn-primary" href="{{ url_for('.edit_kpi_set_help_text', seriessetid=series_set.db_id, sourcename=source_name) }}">
                    Edit description
                </a>
            </p>
            {% endif %}
        </div>
    </div>
</div>
{% endif %}

{% block series_set_content %}
{% endblock %}
{% endblock %}
