{% extends 'layout.html' %}
{% block content %}
<h2>Compose</h2>
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="ui {{ category }} message">
  {{ message }}
</div>
{% endfor %}
{% endif %}
{% endwith %}
<div class="ui form">
  <form method="POST" action="{{ url_for('query', env=current_env) }}">
    {{ form.csrf_token }}
    <div class="field {% if form.query.errors %} error {% endif %}">
      {{ form.query(autofocus="autofocus", rows=5, placeholder="Enter your query: [\"=\", \"certname\", \"hostname\"]. You may omit the opening and closing bracket.") }}
    </div>
    <div class="inline fields">
      {% for subfield in form.endpoints %}
      <div class="field">
        <div class="ui radio checkbox">
          {{ subfield }}
          {{ subfield.label }}
        </div>
      </div>
      {% endfor %}
    </div>
    <div class="inline fields">
      <div class="field">
        {{ form.rawjson(active=True) }} Raw JSON
      </div>
    </div>
    <input type=submit class="ui submit button" value='Submit'>
    <input type=reset class="ui red submit button" value='Cancel'>
  </form>
</div>

{% if result %}
<div class="row">
  <div class="span12">
    <h2>Result</h2>
      {% if form.rawjson.data %}
      <pre><code>{{ result|jsonprint }}</code></pre>
      {% else %}
      {% autoescape false %}
      {{ result|prettyprint}}
      {% endautoescape %}
      {% endif %}
  </div>
</div>
{% endif %}
{% endblock content %}
