<?php
  // Set up page title:
  $lookfor = $this->results->getUrlQuery()->isQuerySuppressed() ? '' : $this->params->getDisplayQuery();
  if (isset($this->overrideTitle)) {
      $this->headTitle($this->overrideTitle);
  } else {
      $this->headTitle($this->translate('Search Results') . (empty($lookfor) ? '' : " - {$lookfor}"));
  }


  // Set up search box:
  $this->layout()->searchbox = $this->context($this)->renderInContext(
      'search/searchbox.phtml',
      [
        'lookfor' => $lookfor,
        'searchIndex' => $this->params->getSearchHandler(),
        'searchType' => $this->params->getSearchType(),
        'searchId' => $this->results->getSearchId(),
        'searchClassId' => $this->params->getSearchClassId(),
        'checkboxFilters' => $this->params->getCheckboxFacets(),
        'filterList' => $this->params->getFilterList(true),
        'hasDefaultsApplied' => $this->params->hasDefaultsApplied(),
        'selectedShards' => $this->params->getSelectedShards(),
        'ignoreHiddenFiltersInRequest' => isset($this->ignoreHiddenFiltersInRequest) ? $this->ignoreHiddenFiltersInRequest : false,
        'ignoreHiddenFilterMemory' => isset($this->ignoreHiddenFilterMemory) ? $this->ignoreHiddenFilterMemory : false,
      ]
  );

    // Set up breadcrumbs:
    if (isset($this->overrideTitle)) {
        $this->layout()->breadcrumbs .= '<li class="active">' . $this->escapeHtml($this->overrideTitle) . '</li>';
    } else {
        $this->layout()->breadcrumbs .= '<li class="active">' . $this->transEsc('Search') . ': ' . $this->escapeHtml($lookfor) . '</li>';
    }


// Enable cart if appropriate:
  $this->showBulkOptions = $this->params->getOptions()->supportsCart() && $this->showBulkOptions;
  // Checkboxes if appropriate:
  $this->showCartControls = $this->params->getOptions()->supportsCart() && $this->cart()->isActive()
    && ($this->showBulkOptions || !$this->cart()->isActiveInSearch());
  // Enable bulk options if appropriate:
  $this->showCheckboxes = $this->showCartControls || $this->showBulkOptions;

  // Load Javascript only if list view parameter is NOT full:
  if ($this->params->getOptions()->getListViewOption() != "full") {
    $this->headScript()->appendFile("record.js");
    $this->headScript()->appendFile("embedded_record.js");
  }

  // Load Javascript dependencies into header:
  $this->headScript()->appendFile("check_item_statuses.js");
  $this->headScript()->appendFile("check_save_statuses.js");
  $this->headScript()->appendFile("accordion.js");
?>

<div class="<?=$this->layoutClass('mainbody')?>">

  <div class="ergebnisse">
    <span id="ergebnisliste"><?=$this->transEsc("Resultlist")?></span>
  </div>

  <?php if (($recordTotal = $this->results->getResultTotal()) > 0): // only display these at very top if we have results ?>

      <nav class="search-header hidden-print">
          <div class="search-stats">
              <?php if ($recordTotal > 0): ?>
                  <?=$this->context()->renderInContext('search/controls/showing.phtml', ['lookfor' => $lookfor, 'recordTotal' => $recordTotal]) ?>
              <?php else: ?>
                  <h2><?=$this->transEsc('nohit_heading')?></h2>
              <?php endif; ?>
          </div>
      </nav>

        <div class="sortierung clear">
          <?php if ($recordTotal > 0): ?>
              <div class="search-controls clear">
                  <?=$this->render('search/controls/limit.phtml')?>
                  <?=$this->render('search/controls/sort.phtml')?>
                  <?=$this->render('search/controls/view.phtml')?>
              </div>
          <?php endif; ?>
        </div>

  <?php endif; ?>
  <?=$this->flashmessages()?>



  <?php /* End Listing Options */ ?>

  <?php if ($recordTotal < 1): ?>
    <p>
      <?php if (isset($this->overrideEmptyMessage)): ?>
        <?=$this->overrideEmptyMessage?>
      <?php else: ?>
        <?php $this->layout()->srmessage = $this->translate('nohit_lookfor_html', ['%%lookfor%%' => $this->escapeHtml($lookfor)]); ?>
        <?=$this->layout()->srmessage ?>
      <?php endif; ?>
    </p>
    <?php if (isset($this->parseError)): ?>
      <p class="alert alert-danger"><?=$this->transEsc('nohit_parse_error')?></p>
    <?php endif; ?>
    <?php foreach (($top = $this->results->getRecommendations('top')) as $current): ?>
      <?=$this->recommend($current)?>
    <?php endforeach; ?>
    <?php foreach ($this->results->getRecommendations('noresults') as $current): ?>
      <?php if (!in_array($current, $top)): ?>
        <?=$this->recommend($current)?>
      <?php endif; ?>
    <?php endforeach; ?>
  <?php else: ?>

      <div id="ergebnisfunktion" class="ergebnisfunktion">
        <span><?=$this->transEsc("Result Selection")?></span>
      </div>
      <div id="suchauswahl" class="show-content suchauswahl">
        <form id="search-cart-form" method="get" name="bulkActionForm" action="<?=$this->url('cart-searchresultsbulk')?>" data-lightbox data-lightbox-onsubmit="bulkFormHandler">
          <?=$this->context($this)->renderInContext('search/bulk-action-buttons.phtml', ['idPrefix' => ''])?>
        </form>
      </div>
        <?=$this->render('search/list-' . $this->params->getView() . '.phtml')?>
        <?=$this->paginationControl($this->results->getPaginator(), 'Sliding', 'search/pagination.phtml', ['results' => $this->results, 'options' => isset($this->paginationOptions) ? $this->paginationOptions : []])?>
      <div class="clear"></div>
      <div id="ergebnisfunktion2" class="ergebnisfunktion">
              <span><?=$this->transEsc("Result Selection")?></span>
            </div>
      <div id="suchauswahl2" class="show-content suchauswahl">
          <form id="search-cart-form" method="get" name="bulkActionForm" action="<?=$this->url('cart-searchresultsbulk')?>" data-lightbox data-lightbox-onsubmit="bulkFormHandler">
              <?=$this->context($this)->renderInContext('search/bulk-action-buttons.phtml', ['idPrefix' => 'bottom_'])?>
          </form>
      </div>

      <div class="searchtools hidden-print">
      <strong><?=$this->transEsc('Search Tools')?>:</strong>
      <a href="<?=$this->results->getUrlQuery()->setViewParam('rss')?>"><i class="fa fa-bell" aria-hidden="true"></i> <?=$this->transEsc('Get RSS Feed')?></a>
          |
      <a href="<?=$this->url('search-email')?>" class="mailSearch" data-lightbox id="mailSearch<?=$this->escapeHtmlAttr($this->results->getSearchId())?>">
        <i class="fa fa-envelope" aria-hidden="true"></i> <?=$this->transEsc('Email this Search')?>
      </a>
      <?php if ($this->accountCapabilities()->getSavedSearchSetting() === 'enabled'): ?>
          |
        <?php if (is_numeric($this->results->getSearchId())): ?>
          <?php if ($this->results->isSavedSearch()): ?>
            <a href="<?=$this->url('myresearch-savesearch')?>?delete=<?=urlencode($this->results->getSearchId())?>"><i class="fa fa-remove" aria-hidden="true"></i> <?=$this->transEsc('save_search_remove')?></a>
          <?php else: ?>
            <a href="<?=$this->url('myresearch-savesearch')?>?save=<?=urlencode($this->results->getSearchId())?>"><i class="fa fa-save" aria-hidden="true"></i> <?=$this->transEsc('save_search')?></a>
          <?php endif; ?>
        <?php endif; ?>
      <?php endif; ?>
    </div>
  <?php endif; ?>
</div>
<?php /* End Main Listing */ ?>

<?php /* Narrow Search Options */ ?>
<div class="<?=$this->layoutClass('sidebar')?>">
  <?php foreach ($this->results->getRecommendations('side') as $current): ?>
    <?=$this->recommend($current)?>
  <?php endforeach; ?>
</div>
<?php /* End Narrow Search Options */ ?>
