{% extends 'timeseer.html' %}

{% from 'macros.html' import alerter, bootstrap_icon, info_popover, progress_bar, visualize_check_result, visualize_score, visualize_series_name %}
{% from 'prepare.html' import prepare_menu with context %}

{% block csp_style %}
'self' 'unsafe-inline'
{% endblock %}

{% block scripts %}
<script src="{{ url_for('static', filename='dist/charts.js') }}" nonce="{{ csp_nonce }}"></script>
{% endblock %}

{% block styles %}
<style nonce="{{ csp_nonce }}">
    .score-table {
        table-layout: fixed;
    }
    .score-table .score-grouping {
        width: 20%;
    }
    .score-table .score {
        width: 20%;
    }
    .score-table .checkbox {
        width: 5%;
    }
</style>
{% endblock %}

{% block main %}
<div class="ts-section py-3 my-3">
    <div class="row align-items-center">
        <div class="col">
            {% block tags_title %}

            {% endblock %}
            <p class="h6 text-break">{{ visualize_series_name(series.name) }} <small class="text-muted">{{ source_name }}</small></p>
        </div>
        <div class="col-lg-auto">
            <form action="{{ url_for('analyze.analyze_series') }}" method="POST" id="analyzeseries">
                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                <input type="hidden" name="seriesid" value="{{ series.series_id }}">
            </form>
            {% block tags_action %}

            {% endblock %}
            <button type="submit" class="btn btn-secondary" form="analyzeseries">Analyze</button>
        </div>
    </div>
</div>

<div class="pt-3 my-3">
    {{ alerter () }}

    {% if not is_analyzed and analysis_state is none %}
    <div class="alert alert-primary">
        <div class="row align-items-center gx-2">
            <div class="col-md">
                Results are only available when the time series has been analyzed.
            </div>
            <div class="col-md-auto">
                <form action="{{ url_for('analyze.analyze_series') }}" method="POST">
                    <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                    <input type="hidden" name="seriesid" value="{{ series.series_id }}">
                    <button type="submit" class="btn btn-primary btn-block">Analyze</button>
                </form>
            </div>
        </div>
    </div>
    {% elif not is_analyzed or analysis_state.failed > 0 %}
        {% call progress_bar(analysis_state, url_for('prepare.get_analysis_state', blockevaluationid=block_evaluation.db_id, seriesid = series.series_id), class_name='univariate-progress', empty_is_pending=True) %}
        Analysis
        {% endcall %}
    {% endif %}
    {% block tags_content %}
    {% endblock tags_content %}
</div>
{% endblock main %}

{% block scripts_bottom %}
<script src="{{ url_for('static', filename='dist/flows.js') }}" nonce="{{ csp_nonce }}"></script>
{% endblock %}
