<? $idAndClass = 'id="more-narrowGroupHidden-'.$this->escapeHtmlAttr($this->title).'" class="facet narrow-toggle"'; ?>
<? $moreClass = 'narrowGroupHidden-'.$this->escapeHtmlAttr($this->title).' hidden'; ?>
<? foreach ($this->cluster['list'] as $i => $thisFacet): ?>
  <?
    if(empty($thisFacet['displayText'])) {
      $thisFacet['displayText'] = "-";
    }
  ?>
  <? /* MORE link */ ?>
  <? if ($i == $this->facets_before_more): ?>
    <? if ($facetLightbox = $this->options->getFacetListAction()): ?>
      <? $moreUrl = $this->url($facetLightbox) . $results->getUrlQuery()->getParams() . '&amp;facet=' . $this->title . '&amp;facetop=' . $thisFacet['operator'] . '&amp;facetexclude=' . ($this->allowExclude ? 1 : 0); ?>
    <? else: ?>
      <? $moreUrl = '#'; ?>
    <? endif; ?>
    <? if (($this->showMoreInLightbox && $this->showMoreInLightbox !== 'more') && $facetLightbox): ?>
      <a <?=$idAndClass ?> data-lightbox href="<?=$moreUrl ?>" rel="nofollow"><?=$this->transEsc('more')?> ...</a>
      <? break; ?>
    <? endif; ?>
    <a <?=$idAndClass ?> href="<?=$moreUrl ?>" onclick="return moreFacets('narrowGroupHidden-<?=$this->escapeHtmlAttr($this->title) ?>')" rel="nofollow"><?=$this->transEsc('more')?> ...</a>
  <? endif; ?>

  <?
    $affectiveURL = $thisFacet['isApplied']
      ? $this->currentPath() . $results->getUrlQuery()->removeFacet($this->title, $thisFacet['value'], $thisFacet['operator'])
      : $this->currentPath() . $results->getUrlQuery()->addFacet($this->title, $thisFacet['value'], $thisFacet['operator']);
  ?>
  <? if (!$thisFacet['isApplied'] && $this->allowExclude): ?>
    <div class="facet excludable facet<?=$thisFacet['operator'] ?><? if ($thisFacet['isApplied']): ?>active<? endif; ?><? if ($i >= $this->facets_before_more): ?> <?=$moreClass ?><?endif ?>">
      <? $excludeURL = $thisFacet['isApplied']
        ? $this->currentPath() . $results->getUrlQuery()->removeFacet($this->title, $thisFacet['value'], $thisFacet['operator'])->addFacet($this->title, $thisFacet['value'], 'NOT')
        : $this->currentPath() . $results->getUrlQuery()->addFacet($this->title, $thisFacet['value'], 'NOT');
      ?>
      <a href="<?=$excludeURL ?>" title="<?=$this->transEsc('exclude_facet') ?>" class="exclude"><i class="fa fa-times" aria-hidden="true"></i></a>
  <? else: ?>
    <a href="<?=$affectiveURL ?>" class="facet facet<?=$thisFacet['operator'] ?><? if ($thisFacet['isApplied']): ?>active<? endif; ?><? if ($i >= $this->facets_before_more): ?> <?=$moreClass ?><?endif ?>">
  <? endif; ?>

  <? if ($thisFacet['isApplied']): ?>
    <span class="status"><i class="fa fa-check" aria-hidden="true"></i></span>
  <? else: ?>
    <span class="badge"><?=$this->localizedNumber($thisFacet['count'])?></span>
  <? endif; ?>

  <? if (!$thisFacet['isApplied'] && $this->allowExclude): ?>
    <a href="<?=$affectiveURL ?>" class="text">
  <? else: ?>
    <span class="text">
  <? endif; ?>

  <? if ($thisFacet['operator'] == 'OR'): ?>
    <i class="fa <?=$thisFacet['isApplied'] ? 'fa-check-square-o' : 'fa-square-o' ?>" aria-hidden="true"></i>
  <? endif; ?>

  <?=$this->transEsc($thisFacet['displayText'])?>

  <? if (!$thisFacet['isApplied'] && $this->allowExclude): ?>
      </a>
    </div>
  <? else: ?>
      </span>
    </a>
  <? endif; ?>
<? endforeach; ?>

<? /* LESS and SEE MORE links */ ?>
<? if ($i >= $this->facets_before_more): ?>
  <? if ($this->showMoreInLightbox === 'more' && $facetLightbox = $options->getFacetListAction()): ?>
    <? $moreUrl = $this->url($facetLightbox) . $results->getUrlQuery()->getParams().'&amp;facet='.$this->title.'&amp;facetop='.$thisFacet['operator'].'&amp;facetexclude='.($this->allowExclude ? 1 : 0); ?>
    <a class="facet narrow-toggle <?=$moreClass ?>" data-lightbox href="<?=$moreUrl ?>" rel="nofollow"><?=$this->transEsc('see all')?> ...</a>
  <? endif; ?>
  <a class="facet narrow-toggle <?=$moreClass ?>" href="#" onclick="return lessFacets('narrowGroupHidden-<?=$this->escapeHtmlAttr($this->title) ?>')"><?=$this->transEsc('less')?> ...</a>
<? endif; ?>
