{% extends "base.html" %}
{% block title %}{{ instrument.name|default:"Instrument not found" }} - Batch run submission{% endblock %}
{% load static %}
{% block body %}
{% if error %}
<div class="text-center col-md-6 col-md-offset-3 alert alert-danger " id="error">
    {{ error }}
</div>
{% endif %}
<title>{{ instrument.name }} - Batch run submission</title>
<div class="row">
    <div class="col-md-12 text-center">
        <h2>{{ instrument.name }} - Batch run submission</h2>
    </div>
</div>
<form id="run_variables" method="POST" action="{% url 'runs:configure_batch_run' instrument=instrument.name %}" class="form-horizontal">
    {% csrf_token %}
    <input type="hidden" id="upcoming_runs" name="upcoming_runs" value="{{ upcoming_run_variables }}"/>
    <input type="hidden" id="is_editing" name="is_editing" value="{{ editing }}"/>
    <div class="row">
        <div class="col-md-9">
            {% include "snippets/variables/form_warnings.html" %}
            <br/>
            <div class="js-variable-by-run">
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label for="runs" class="col-form-label col-md-3">Run Numbers</label>
                            <div class="col-md-9">
                                <input type="text" id="runs" name="runs" value="{{ runs }}" class="form-control"/></div>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-10 col-md-offset-1">
                        <div class="alert alert-warning collapse" id="run_finish_warning">
                            <strong>Please Note:</strong> The <a href="#" class="js-show-default-variables">default
                            script values</a> will be used from run <span id="next_run"></span> onwards. You will be
                            able to change this by selecting the appropriate "edit variables" link from the
                            Instrument Summary page.
                        </div>
                    </div>
                </div>
            </div>

            <div class="js-variables-container">
                {% include "snippets/variables/form.html" with standard_variables=standard_variables advanced_variables=advanced_variables variable_help=variable_help instrument=instrument.name only %}
            </div>
        </div>
        <div class="col-md-3">
            <div class="card card-body">
                <div class="row">
                    <div class="col-md-12"><h4>Additional Actions</h4></div>
                </div>
                <div class="row">
                    <ul class="js-form-actions">
                        {% include "snippets/reset_buttons.html" %}
                    </ul>
                </div>
            </div>
            <div class="row">
                <div class="col-md-12 js-action-explaination"></div>
            </div>
        </div>
    </div>
    <div class="form-group variables-buttons">
        <div class="col-md-9 text-right">
            <a href="{% url 'runs:list' instrument.name %}" class="btn btn-danger" id="cancel">Cancel</a>
            <input type="submit" value="Submit Batch Run" class="btn btn-success" id="variableSubmit"/>
        </div>
    </div>
</form>
<div class="modal fade" id="default-variables-modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span
                        aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">Default Variables</h4>
            </div>
            <div class="modal-body">
                <h5>Standard Variables</h5>
                {% for name,variable in default_standard_variables.items %}
                    <div>
                        <strong>{{ name }}:</strong> {{ variable.value }}
                    </div>
                {% endfor %}
                <h5>Advanced Variables</h5>
                {% for name,variable in default_advanced_variables.items %}
                    <div>
                        <strong>{{ name }}:</strong> {{ variable.value }}
                    </div>
                {% endfor %}
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="conflicts-modal">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span
                        aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">Overwrite Existing Variables?</h4>
            </div>
            <div class="modal-body">
                <p>There are already saved values that fall within this run range chosen.</p>
                <p>These variables start at the following runs: <span class="js-conflicts-list"></span></p>
                <p>Do you want to overwrite these with the new values?</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
                <button type="button" class="btn btn-primary js-conflicts-confirm" id="replace_confirm">Yes, Replace</button>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block stylesheets %}
    <link rel="stylesheet" href="{% static "css/vendor/prettify.css" %}">
{% endblock %}
{% block scripts %}
    <script src='{% static "javascript/vendor/prettify.js" %}'></script>
    <script src='{% static "javascript/run_variables.js" %}'></script>
{% endblock %}
