<?php $this->extend('block_unsearchable'); ?>

<?php $this->block('content'); ?>

<form action="<?php echo $this->action; ?>" id="<?php echo $this->formId; ?>" class="form-inline" method="post">
<div class="formbody w-100 form-row p-3 bg-light border rounded">
<input type="hidden" name="FORM_SUBMIT" value="<?php echo $this->formId; ?>">
<input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}">

<?php if($this->hasSorting): ?>
<div class="sorting input-group col">
<div class="input-group-prepend"><label class="mr-2 p-0"><?php echo $this->sortingLabel; ?></label></div>
  <select name="sorting" id="ctrl_sorting_<?php echo $this->id; ?>" class="custom-select" onchange="document.getElementById('<?php echo $this->formId; ?>').submit();">
    <?php foreach( $this->sortingOptions as $option ): ?>
      <option value="<?php echo $option['value']; ?>"<?php if($option['default']) echo ' selected="selected"'; ?>><?php echo $option['label']; ?></option>
    <?php endforeach; ?>
  </select>
</div>
<?php endif; ?>

<?php if ($this->hasLimit): ?>
<div class="limit input-group col-auto">
  <div class="input-group-prepend"><label class="mr-2 p-0"><?php echo $this->limitLabel; ?></label></div>
  <select name="limit" id="ctrl_limit_<?php echo $this->id; ?>" class="custom-select" onchange="document.getElementById('<?php echo $this->formId; ?>').submit();">
    <?php foreach( $this->limitOptions as $option ): ?>
      <option value="<?php echo $option['value']; ?>"<?php if($option['default']) echo ' selected="selected"'; ?>><?php echo $option['label']; ?></option>
    <?php endforeach; ?>
  </select>
</div>
<?php endif; ?>

<?php if ($this->hasFilters): ?>
<div class="filters input-group">
  <?php foreach( $this->filterOptions as $field => $data ): ?>
    <div class="input-group-prepend"><label for="ctrl_filter_<?php echo $field; ?>_<?php echo $this->id; ?>"><?php echo $data['label']; ?></label></div>
    <select name="filter[<?php echo $field; ?>]" id="ctrl_filter_<?php echo $field; ?>_<?php echo $this->id; ?>" class="select" onchange="document.getElementById('<?php echo $this->formId; ?>').submit();">
      <option value=""><?php echo $data['blankOptionLabel'] ? $data['blankOptionLabel'] : '-'; ?></option>
      <?php foreach( $data['options'] as $option ): ?>
        <option value="<?php echo $option['value']; ?>"<?php if($option['default']) echo ' selected="selected"'; ?>><?php echo $option['label']; ?></option>
      <?php endforeach; ?>
    </select>
  <?php endforeach; ?>
</div>
<?php endif; ?>
<noscript>
<div class="submit_container"><input type="submit" class="submit btn btn-secondary" value="<?php echo $this->slabel; ?>"></div>
</noscript>
<div class="input-group-append"><a href="<?php echo $this->actionClear; ?>" class="btn btn-secondary clear_filters"><?php echo $this->clearLabel; ?></a> </div>
</div>
</form>

<?php if ($this->hasSearch): ?>
<div class="search mt-1 ml-n1 mr-1 bg-light border rounded">
  <form action="<?php echo $this->action; ?>" method="get">
    <div class="search input-group text-right w-100 p-0">
    <input type="hidden" name="isorc" value="<?php echo \Input::get('isorc'); ?>">
    <div class="input-group-prepend pt-1 px-2 bg-light border rounded"><label for="ctrl_keywords_<?php echo $this->id; ?>"><?php echo $this->keywordsLabel; ?></label></div>
    <input type="text" name="keywords" id="ctrl_keywords_<?php echo $this->id; ?>" class="text form-control" value="<?php echo $this->keywords; ?>" placeholder="<?php echo $this->defaultSearchText; ?>">
    <div class="input-group-append"><input type="submit" class="submit btn btn-success" value="<?php echo $this->searchLabel; ?>"></div>
    <div class="input-group-append"><a href="<?php echo $this->actionClear; ?>" class="btn btn-secondary clear_filters"><?php echo $this->clearLabel; ?></a> </div>
  </div>
  </form>
</div>
<?php endif; ?>

<?php if ($this->hasAutocomplete):
$GLOBALS['TL_CSS'][] = \Haste\Util\Debug::uncompressedFile('system/modules/isotope/assets/plugins/awesomplete/awesomplete.min.css');
?>
<script src="<?php echo \Haste\Util\Debug::uncompressedFile('system/modules/isotope/assets/plugins/awesomplete/awesomplete.min.js'); ?>"></script>
<script>
    Isotope.initAwesomplete(<?= $this->id ?>, document.getElementById('ctrl_keywords_<?php echo $this->id; ?>'));
</script>
<?php endif; ?>

<div class="clear">&nbsp;</div>

<?php $this->endblock(); ?>
