{% load util %}
{% load form_util %}
<div class="aw-error-msg">
  {{ form.non_field_errors }}
</div>
<button type="submit" class="btn btn-primary" title="Save">Save</button>
{% for bf in form.visible_fields %}
{%   if bf.name in primary_fields %}
<div class="mb-3 row">
    <label for="{{ bf.id_for_label }}" class="form-label col-sm-2 col-form-label">{{ bf.label }}</label>
    <div class="col-sm-10">
{%     if bf|form_field_is_dropdown %}
        {{ bf|get_form_field_select:existing|safe }}
{%     else %}
        {{ bf|get_form_field_input:existing|safe }}
{%     endif %}
    </div>
{%     if bf.help_text|exists %}
    <div class="help-block">
        <b>Info:</b> {{ bf.help_text|safe }}
    </div>
{%     endif %}
</div>
<div class="aw-error-msg">
    {{ bf.errors }}
</div>
{%   endif %}
{% endfor %}

<button type="button" class="btn btn-warning aw-btn-action aw-btn-expand" title="Show Settings" aw-expand="aw-spoiler-job-settings">
    {% include "../button/icon/expand.html" %}
</button>
<br>

<div hidden="hidden" id="aw-spoiler-job-settings">
{% for bf in form.visible_fields %}
{%   if bf.name not in primary_fields %}
    <div class="mb-3 row">
        <label for="{{ bf.id_for_label }}" class="form-label col-sm-2 col-form-label">{{ bf.label }}</label>
        <div class="col-sm-10">
{%     if bf|form_field_is_dropdown %}
            {{ bf|get_form_field_select:existing|safe }}
{%     else %}
            {{ bf|get_form_field_input:existing|safe }}
{%     endif %}
        </div>
{%     if bf.help_text|exists %}
        <div class="help-block">
            <b>Info:</b> {{ bf.help_text|safe }}
        </div>
{%     endif %}
    </div>
    <div class="aw-error-msg">
        {{ bf.errors }}
    </div>
{%   endif %}
{% endfor %}

    <div class="mb-3 row" >
        <label class="form-label col-sm-2 col-form-label">Execution Prompts</label>
        <div class="col-sm-10">
            <button type="button" class="btn btn-success aw-job-form-prompt-add" title="Add">Add Prompt</button>
        </div>
        <div class="help-block">
            <b>Info:</b> Define prompts for custom job executions.
        </div>
    </div>
    <div id="aw-job-form-prompts-config">
        <div class="mb-3 row">
            <label for="id_prompt_limit" class="form-label col-sm-2 col-form-label form-label-sub">Enforce Prompts</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_prompt_enforce" name="prompt_enforce">
                    <option value="True" {% if existing|check_job_prompt_flag:"enforce" %}selected{% endif %}>Yes</option>
                    <option value="False" {% if not existing|check_job_prompt_flag:"enforce" %}selected{% endif %}>No</option>
                </select>
            </div>
            <div class="help-block">
                <b>Info:</b> Disable quick execution and require the user to fill-out the given prompts.
            </div>
        </div>
        <div class="mb-3 row">
            <label for="id_prompt_limit" class="form-label col-sm-2 col-form-label form-label-sub">Prompt for Limit</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_prompt_limit" name="prompt_limit">
                    <option value="True" {% if existing|check_job_prompt_flag:"limit" %}selected{% endif %}>Yes</option>
                    <option value="False" {% if not existing|check_job_prompt_flag:"limit" %}selected{% endif %}>No</option>
                </select>
            </div>
        </div>
        <div class="mb-3 row">
            <label for="id_prompt_limit" class="form-label col-sm-2 col-form-label form-label-sub">Require a Limit</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_prompt_limit_req" name="prompt_limit_req">
                    <option value="True" {% if existing|check_job_prompt_flag:"limit_req" %}selected{% endif %}>Yes</option>
                    <option value="False" {% if not existing|check_job_prompt_flag:"limit_req" %}selected{% endif %}>No</option>
                </select>
            </div>
            <div class="help-block">
                <b>Info:</b> Require the user to provide a limit. Note: The group 'all' is valid and will not be filtered!
            </div>
        </div>
        <div class="mb-3 row">
            <label for="id_prompt_mode_check" class="form-label col-sm-2 col-form-label form-label-sub">Prompt for Check-Mode</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_prompt_mode_check" name="prompt_mode_check">
                    <option value="True" {% if existing|check_job_prompt_flag:"mode_check" %}selected{% endif %}>Yes</option>
                    <option value="False" {% if not existing|check_job_prompt_flag:"mode_check" %}selected{% endif %}>No</option>
                </select>
            </div>
        </div>
        <div class="mb-3 row">
            <label for="id_prompt_mode_diff" class="form-label col-sm-2 col-form-label form-label-sub">Prompt for Difference-Mode</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_prompt_mode_diff" name="prompt_mode_diff">
                    <option value="True" {% if existing|check_job_prompt_flag:"mode_diff" %}selected{% endif %}>Yes</option>
                    <option value="False" {% if not existing|check_job_prompt_flag:"mode_diff" %}selected{% endif %}>No</option>
                </select>
            </div>
        </div>
        <div class="mb-3 row">
            <label for="id_prompt_tags" class="form-label col-sm-2 col-form-label form-label-sub">Prompt for Tags</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_prompt_tags" name="prompt_tags">
                    <option value="True" {% if existing|check_job_prompt_flag:"tags" %}selected{% endif %}>Yes</option>
                    <option value="False" {% if not existing|check_job_prompt_flag:"tags" %}selected{% endif %}>No</option>
                </select>
            </div>
        </div>
        <div class="mb-3 row">
            <label for="id_prompt_skip_tags" class="form-label col-sm-2 col-form-label form-label-sub">Prompt for Skip-Tags</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_prompt_skip_tags" name="prompt_skip_tags">
                    <option value="True" {% if existing|check_job_prompt_flag:"skip_tags" %}selected{% endif %}>Yes</option>
                    <option value="False" {% if not existing|check_job_prompt_flag:"skip_tags" %}selected{% endif %}>No</option>
                </select>
            </div>
        </div>
        <div class="mb-3 row">
            <label for="id_prompt_verbosity" class="form-label col-sm-2 col-form-label form-label-sub">Prompt for Verbosity</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_prompt_verbosity" name="prompt_verbosity">
                    <option value="True" {% if existing|check_job_prompt_flag:"verbosity" %}selected{% endif %}>Yes</option>
                    <option value="False" {% if not existing|check_job_prompt_flag:"verbosity" %}selected{% endif %}>No</option>
                </select>
            </div>
        </div>
        <div class="mb-3 row">
            <label for="id_prompt_env_vars" class="form-label col-sm-2 col-form-label form-label-sub">Prompt for Environmental-Variables</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_prompt_env_vars" name="prompt_env_vars">
                    <option value="True" {% if existing|check_job_prompt_flag:"env_vars" %}selected{% endif %}>Yes</option>
                    <option value="False" {% if not existing|check_job_prompt_flag:"env_vars" %}selected{% endif %}>No</option>
                </select>
            </div>
        </div>
        <div class="mb-3 row">
            <label for="id_prompt_cmd_args" class="form-label col-sm-2 col-form-label form-label-sub">Prompt for CLI-Arguments</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_prompt_cmd_args" name="prompt_cmd_args">
                    <option value="True" {% if existing|check_job_prompt_flag:"cmd_args" %}selected{% endif %}>Yes</option>
                    <option value="False" {% if not existing|check_job_prompt_flag:"cmd_args" %}selected{% endif %}>No</option>
                </select>
            </div>
        </div>
        <div class="mb-3 row">
            <label for="id_prompt_credentials" class="form-label col-sm-2 col-form-label form-label-sub">Prompt for Credentials</label>
            <div class="col-sm-10">
                <select class="form-control" id="id_prompt_credentials" name="prompt_credentials">
                    <option value="True" {% if existing|check_job_prompt_flag:"credentials" %}selected{% endif %}>Yes</option>
                    <option value="False" {% if not existing|check_job_prompt_flag:"credentials" %}selected{% endif %}>No</option>
                </select>
            </div>
        </div>
        <br>
        <div id="aw-job-form-prompts"></div>
        <div class="col-sm-10">
            <button type="button" class="btn btn-success aw-job-form-prompt-add" title="Add">Add Prompt</button>
        </div>
    </div>
</div>
<br>
<button type="submit" class="btn btn-primary" title="Save">Save</button>

<script>
    const PROMPT_CNF = '{{ existing|get_value:"execution_prompts" }}';
</script>
