{{ header }}
<ul class="breadcrumb">
  {% for breadcrumb in breadcrumbs %}
  <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
  {% endfor %}
</ul>
{% if j3.settings.get('pageTitlePosition') == 'top' %}
  <h1 class="title page-title"><span>{{ heading_title }}</span></h1>
{% endif %}
{{ j3.loadController('journal3/layout', 'top') }}
<div id="product-search" class="container">
  <div class="row">{{ column_left }}
    {% if column_left and column_right %}
    {% set class = 'col-sm-6' %}
    {% elseif column_left or column_right %}
    {% set class = 'col-sm-9' %}
    {% else %}
    {% set class = 'col-sm-12' %}
    {% endif %}
    <div id="content" class="{{ class }}">
      {% if j3.settings.get('pageTitlePosition') == 'default' %}
        <h1 class="title page-title">{{ heading_title }}</h1>
      {% endif %}
      {{ content_top }}
      <h2 class="title search-criteria-title">{{ entry_search }}</h2>

      <div class="search-form">
        <div class="inputs">
          <input type="text" name="search" value="{{ search }}" placeholder="{{ text_keyword }}" id="input-search" class="form-control" />

          <select name="category_id" class="form-control">
            <option value="0">{{ text_category }}</option>
            {% for category_1 in categories %}
              {% if category_1.category_id == category_id %}
                <option value="{{ category_1.category_id }}" selected="selected">{{ category_1.name }}</option>
              {% else %}
                <option value="{{ category_1.category_id }}">{{ category_1.name }}</option>
              {% endif %}
              {% for category_2 in category_1.children %}
                {% if category_2.category_id == category_id %}
                  <option value="{{ category_2.category_id }}" selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_2.name }}</option>
                {% else %}
                  <option value="{{ category_2.category_id }}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_2.name }}</option>
                {% endif %}
                {% for category_3 in category_2.children %}
                  {% if category_3.category_id == category_id %}
                    <option value="{{ category_3.category_id }}" selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_3.name }}</option>
                  {% else %}
                    <option value="{{ category_3.category_id }}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_3.name }}</option>
                  {% endif %}
                {% endfor %}
              {% endfor %}
            {% endfor %}
          </select>
        </div>

        <div class="checkbox">
          <label class="checkbox-inline">
            {% if sub_category %}
            <input type="checkbox" name="sub_category" value="1" checked="checked" />
            {% else %}
            <input type="checkbox" name="sub_category" value="1" />
            {% endif %}
            {{ text_sub_category }}</label>
        </div>

        <div class="checkbox">
          <label class="checkbox-inline">
            {% if description %}
              <input type="checkbox" name="description" value="1" id="description" checked="checked" />
            {% else %}
              <input type="checkbox" name="description" value="1" id="description" />
            {% endif %}
            {{ entry_description }}</label>
        </div>

      </div>

      <div class="buttons clearfix">
          <div class="pull-right"><button id="button-search" class="btn btn-primary"><span>{{ button_search }}</span></button></div>
      </div>
      <h2 class="title search-products-title">{{ text_search }}</h2>
      <div class="main-products-wrapper">
      {% if products %}
          {% if j3.settings.get('sortBarStatus') %}
              <div class="products-filter">
                  <div class="grid-list">
                    <button id="btn-grid-view" class="view-btn {% if j3.settings.get('globalProductView') == 'grid' %}active{% endif %}" data-toggle="tooltip" title="{{ button_grid }}" data-view="grid"></button>
                    <button id="btn-list-view" class="view-btn {% if j3.settings.get('globalProductView') == 'list' %}active{% endif %}" data-toggle="tooltip" title="{{ button_list }}" data-view="list"></button>
                    <a href="{{ compare }}" id="compare-total" class="compare-btn">{{ text_compare }}</a>
                  </div>
                  <div class="select-group">
                      <div class="input-group input-group-sm sort-by">
                          <label class="input-group-addon" for="input-sort">{{ text_sort }}</label>
                          <select id="input-sort" class="form-control" onchange="location = this.value;">
                              {% for sorts in sorts %}
                                  {% if sorts.value == '%s-%s'|format(sort, order) %}
                                      <option value="{{ sorts.href }}" selected="selected">{{ sorts.text }}</option>
                                  {% else %}
                                      <option value="{{ sorts.href }}">{{ sorts.text }}</option>
                                  {% endif %}
                              {% endfor %}
                          </select>
                      </div>
                      <div class="input-group input-group-sm per-page">
                          <label class="input-group-addon" for="input-limit">{{ text_limit }}</label>
                          <select id="input-limit" class="form-control" onchange="location = this.value;">
                              {% for limits in limits %}
                                  {% if limits.value == limit %}
                                      <option value="{{ limits.href }}" selected="selected">{{ limits.text }}</option>
                                  {% else %}
                                      <option value="{{ limits.href }}">{{ limits.text }}</option>
                                  {% endif %}
                              {% endfor %}
                          </select>
                      </div>
                  </div>
              </div>
          {% endif %}
        <div class="main-products product-{{ j3.settings.get('globalProductView') }}">
          {% set display = j3.settings.get('globalProductView') %}
          {% include "journal3/template/journal3/product_card.twig" %}
        </div>
        <div class="row pagination-results">
          <div class="col-sm-6 text-left">{{ pagination }}</div>
          <div class="col-sm-6 text-right">{{ results }}</div>
        </div>
      {% else %}
        <p>{{ text_empty }}</p>
        <div class="buttons">
          <div class="pull-right"><a href="{{ continue }}" class="btn btn-primary">{{ button_continue }}</a></div>
        </div>
      {% endif %}
      </div>
      {{ content_bottom }}</div>
    {{ column_right }}</div>
</div>
<script type="text/javascript"><!--
$('#button-search').bind('click', function() {
	url = 'index.php?route=product/search';

	var search = $('#content input[name=\'search\']').prop('value');

	if (search) {
		url += '&search=' + encodeURIComponent(search);
	}

	var category_id = $('#content select[name=\'category_id\']').prop('value');

	if (category_id > 0) {
		url += '&category_id=' + encodeURIComponent(category_id);
	}

	var sub_category = $('#content input[name=\'sub_category\']:checked').prop('value');

	if (sub_category) {
		url += '&sub_category=true';
	}

	var filter_description = $('#content input[name=\'description\']:checked').prop('value');

	if (filter_description) {
		url += '&description=true';
	}

	location = url;
});

$('#content input[name=\'search\']').bind('keydown', function(e) {
	if (e.keyCode == 13) {
		$('#button-search').trigger('click');
	}
});

$('select[name=\'category_id\']').on('change', function() {
	if (this.value == '0') {
		$('input[name=\'sub_category\']').prop('disabled', true);
	} else {
		$('input[name=\'sub_category\']').prop('disabled', false);
	}
});

$('select[name=\'category_id\']').trigger('change');
--></script>
{{ footer }}
