<?
  $this->headTitle($this->translate('Browse the Catalog'));
  $this->layout()->breadcrumbs = '<a href="' . $this->url('browse-home') . '">' . $this->transEsc('Browse') . '</a>';

  $BROWSE_BASE = $this->url('browse-' . strtolower($this->currentAction));
  $SEARCH_BASE = $this->url($this->currentAction == 'Tag' ? 'tag-home' : 'search-results');
?>

<? if (!isset($this->currentAction)): ?>
  <h2><?=$this->transEsc('Choose a Category to Begin Browsing') ?>:</h2>
<? endif; ?>

<div class="row">
  <div class="browse list-group col-sm-3<? if (!empty($this->categoryList)): ?> hidden-xs<? endif ?>" id="list1">
    <? foreach ($this->browseOptions as $item=>$currentOption): ?>
      <a href="<?=$this->url('browse-' . strtolower($currentOption['action'])); ?>" class="list-group-item<? if($currentOption['action'] == $this->currentAction): ?> active<? endif; ?>">
        <?=$this->transEsc($currentOption['description']) ?>
        <span class="pull-right flip"><i class="fa fa-angle-right"></i></span>
      </a>
    <? endforeach; ?>
  </div>

  <? if (!empty($this->categoryList)): ?>
    <div class="browse list-group col-sm-3<? if (!empty($this->secondaryList) || !empty($this->resultList)): ?> hidden-xs<? endif ?>" id="list2">
      <? foreach($this->categoryList as $findby=>$category): ?>
        <a href="<?=$BROWSE_BASE ?>?findby=<?=urlencode($findby) ?>&amp;query_field=<?=$this->browse()->getSolrField($findby, $this->currentAction) ?>" class="list-group-item clearfix<? if ($this->findby == $findby): ?> active<? endif; ?>">
          <? if(is_string($category)): ?>
            <?=$this->transEsc($category)?>
            <span class="pull-right flip"><i class="fa fa-angle-right"></i></span>
          <? else: ?>
            <?=$this->transEsc($category['text'])?>
            <span class="badge"><?=number_format($category['count'])?></span>
          <? endif; ?>
        </a>
      <? endforeach; ?>
    </div>
  <? endif; ?>

  <? if (!empty($this->secondaryList)): ?>
    <div class="browse list-group col-sm-3<? if (!empty($this->resultList)): ?> hidden-xs<? endif ?>" id="list3">
    <? foreach($this->secondaryList as $secondary): ?>
      <? $url = $BROWSE_BASE . '?findby=' . urlencode($this->findby)
          . '&category=' . urlencode($this->category)
          . '&query=' . urlencode($secondary['value']);
        if ($this->facetPrefix) {
          $url .= '&facet_prefix=' . urlencode($secondary['displayText']);
        }
        if ($this->secondaryParams) {
          foreach($this->secondaryParams as $var=>$val) {
            $url .= '&' . $var .'=' . urlencode($val);
          }
        }
        $viewRecord = !empty($this->categoryList) && $this->currentAction != 'Tag' && $this->findby != 'alphabetical';
      ?>
      <a href="<?=$url ?>" class="list-group-item clearfix<? if ($this->query == $secondary['value'].'' || $this->query == $secondary['value'].'*'): ?> active<? endif; ?>">
        <?=$this->escapeHtml($secondary['displayText']) ?>
        <? if ($this->findby != 'alphabetical' && isset($secondary['count'])): ?>
          <span class="badge"><?=number_format($secondary['count']) ?></span>
        <? else: ?>
          <span class="pull-right flip"><i class="fa fa-angle-right"></i></span>
        <? endif; ?>
      </a>
      <? if($viewRecord): ?>
        <a class="list-group-item view-record" href="<?=$SEARCH_BASE ?>?lookfor=<? if ($this->filter): ?>&amp;filter[]=<?=urlencode($this->filter) ?>%3A<?=str_replace('+AND+','&amp;filter[]=', urlencode($secondary['value'])) ?><? endif; ?>&amp;filter[]=<?=$this->browse()->getSolrField($this->currentAction) ?>%3A[* TO *]<? if($this->dewey_flag):?>&amp;sort=dewey-sort<?endif;?>"><?=$this->transEsc('View Records') ?></a>
      <? endif; ?>
    <? endforeach; ?>
    </div>
  <? endif; ?>

  <? if (!empty($this->resultList)): ?>
    <div class="browse list-group col-sm-3" id="list4">
    <? foreach($this->resultList as $result): ?>
      <a class="list-group-item clearfix" href="<?=$SEARCH_BASE ?>?<?=$this->paramTitle ?><?=urlencode($result['value']) ?><? if ($this->searchParams): foreach($this->searchParams as $var=>$val): ?>&amp;<?=$var ?>=<?=urlencode($val) ?><? endforeach;endif; ?>">
        <?=$this->escapeHtml($result['displayText'])?>
        <span class="badge"><?=number_format($result['count']) ?></span>
      </a>
    <? endforeach; ?>
    </div>
  <? elseif (isset($this->query)): ?>
    <ul class="browse list-group col-sm-3" id="list4">
      <li class="list-group-item"><?=$this->transEsc('nohit_heading') ?></li>
    </ul>
  <? endif; ?>
</div>