{% import "macros/form_utils.html" as utils %}

{% macro filters_form(case_id, db, inheritance_models, consequences, impact_severities, filters, sv_types=None, gene_lists=None, queries=None) %}
<form method="get" action="{{ url_for('variants.variants', case_id=case_id) }}">
  <div class="form-group">
    <div class="row">
      {% if db.filters.can_filter_frequency %}
        <div class="col-xs-3">
          <label class="control-label">Frequency</label>
          <input type="text" class="form-control" name="frequency" type="number" placeholder="0.0004" step="0.0001" value="{{ filters.frequency if filters.frequency }}">
        </div>
      {% endif %}
      {% if db.filters.can_filter_cadd %}
        <div class="col-xs-3">
          <label class="control-label">CADD</label>
          <input type="text" class="form-control" name="cadd" type="number" placeholder="23.4" step="0.1" value="{{ filters.cadd if filters.cadd }}">
        </div>
      {% endif %}
      {% if db.filters.can_filter_sv_len and db.variant_type == 'sv' %}
        <div class="col-xs-3">
          <label class="control-label">SV Len</label>
          <input type="text" class="form-control" name="sv_len" type="number" placeholder="500" step="0.1" value="{{ filters.sv_len if filters.sv_len }}">
        </div>
      {% endif %}
      {% if db.filters.can_filter_range %}
          <div class="col-xs-3">
            <label class="control-label">Range</label>
            <input type="text" class="form-control" name="range" pattern="\S+:\d+-\d+" placeholder="1:5000-5500" value="{{ filters.query_dict.range[0] if filters.range }}">
          </div>
        {% endif %}
    </div>
  </div>

  <div class="form-group">
    <div class="row">
        {% if db.filters.can_filter_gene %}
          <div class="col-md-6">
            <label class="control-label">Genes</label>
            <input type="text" class="form-control" name="gene_symbol" placeholder="ADK,LPP" value="{{ filters.gene_symbols|join(',') if filters.gene_symbols }}">
          </div>
        {% endif %}
        {% if db.filters.can_query_gemini %}
          <div class="col-md-6">
            <label class="control-label">Gemini Query</label>
            <input type="text" class="form-control" name="gemini_query" placeholder="SELECT * variants" value="{{ filters.gemini_query if filters.gemini_query }}">
          </div>
        {% endif %}
    </div>
  </div>

  <div class="form-group">
    <div class="row">
      {% if db.filters.can_filter_inheritance %}
        <div class="col-md-3">
          <label class="control-label">Inheritance models</label>
          {{ utils.select_input('inheritance_models', inheritance_models, filters.selected_models, multiple=True) }}
        </div>
      {% endif %}
      {% if db.filters.can_filter_consequence %}
        <div class="col-md-3">
          <label class="control-label">Consequences</label>
          {{ utils.select_input('consequences', consequences, filters.selected_consequences, multiple=True) }}
        </div>
      {% endif %}
      {% if db.filters.can_filter_impact_severity %}
        <div class="col-md-3">
          <label class="control-label">Impact Severity</label>
          {{ utils.select_input('impact_severities', impact_severities, filters.impact_severities, multiple=True) }}
        </div>
      {% endif %}
      {% if db.filters.can_filter_sv and db.variant_type == 'sv'%}
      <div class="col-md-3">
        <label class="control-label">SV Types</label>
        {{ utils.select_input('sv_types', (sv_types or []), filters.selected_sv_types, multiple=True) }}
      </div>
      {% endif %}
      {% if config['STORE_ENABLED'] %}
        <div class="col-md-3">
          <label class="control-label">Gene lists</label>
          {{ utils.select_input('gene_lists', gene_lists, filters.gene_lists, multiple=True) }}
        </div>
        {% if queries %}
          <div class="col-md-3">
            <label class="control-label">GEMINI queries</label>
            {{ utils.select_input('preset_gemini_query', queries, filters.gemini_query) }}
          </div>
        {% endif %}
      {% endif %}
    </div>
  </div>

  <div class="form-group">
    <div class="row">
      <div class="col-md-3">
        <button class="btn btn-default form-control" type="submit">Filter</button>
      </div>

      <div class="col-md-3">
        <a class="btn btn-default form-control" href="{{ url_for('variants.variants', case_id=case_id) }}">Reset</a>
      </div>
    </div>
  </div>
</form>
{% endmacro %}
