<?php
  // Grab list object from search results (if applicable):
  $list = $this->results->getListObject();

  // Set up page title:
  $this->headTitle(isset($list) ? $list->title : $this->translate('Favorites'));

  // Set up breadcrumbs:
  $currPage = isset($list) ? 'List' : 'Favorites';
  $this->layout()->breadcrumbs = '<li><a href="' .  $this->url('myresearch-home') . '">' . $this->transEsc('Your Account') . '</a></li> <li class="active">' . $this->transEsc($currPage) . '</li>';

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

  // 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");
  }

  $recordTotal = $this->results->getResultTotal();

  // Convenience variable:
  $account = $this->auth()->getManager();
  $user = $this->auth()->isLoggedIn();
?>

<?=$this->flashmessages()?>

<div class="<?=$this->layoutClass('mainbody')?>">
  <h2><?=$list ? $this->escapeHtml($list->title) : $this->transEsc("Your Favorites")?></h2>
  <nav class="search-header hidden-print">
    <div class="search-stats">
      <?php if ($recordTotal > 0): ?>
        <?
          $transParams = [
            '%%start%%' => $this->localizedNumber($this->results->getStartRecord()),
            '%%end%%'   => $this->localizedNumber($this->results->getEndRecord()),
            '%%total%%' => $this->localizedNumber($recordTotal)
          ];
        ?>
        <?=$this->translate('showing_items_of_html', $transParams); ?>
      <?php endif; ?>
    </div>
      <div class="sortierung">
        <div class="search-controls">
          <?php if (isset($list)): ?>
            <?php if ($list->editAllowed($account->isLoggedIn())): ?>
              <a href="<?=$this->url('editList', ['id' => $list->id]) ?>" class="btn btn-link"><i class="fa fa-edit" aria-hidden="true"></i> <?=$this->transEsc("edit_list")?></a>
              <div class="btn-group">
                <a class="btn btn-link dropdown-toggle" data-toggle="dropdown" href="<?=$this->url('myresearch-deletelist') ?>?listID=<?=urlencode($list->id)?>">
                  <i class="fa fa-trash-o" aria-hidden="true"></i> <?=$this->transEsc("delete_list")?>
                </a>
                <ul class="dropdown-menu">
                  <li><a href="<?=$this->url('myresearch-deletelist') ?>?listID=<?=urlencode($list->id)?>&amp;confirm=1"><?=$this->transEsc('confirm_dialog_yes') ?></a></li>
                  <li><a href="#"><?=$this->transEsc('confirm_dialog_no')?></a></li>
                </ul>
              </div>
            <?php endif; ?>
          <?php endif; ?>
          <?php if ($recordTotal > 0): ?>
            <?=$this->render('search/controls/limit.phtml')?>
            <?=$this->render('search/controls/sort.phtml')?>
          <?php endif; ?>
        </div>
      </div>
  </nav>
  <?php if ($list && !empty($list->description)): ?>
    <p><?=$this->escapeHtml($list->description)?></p>
  <?php endif; ?>
  <?php if ($recordTotal > 0): ?>
    <div id="ergebnisfunktion" class="ergebnisfunktion">
        <span><?=$this->transEsc("Result Selection")?></span>
    </div>
    <div id="suchauswahl" class="show-content suchauswahl">
    <form class="form-inline" method="post" name="bulkActionForm" action="<?=$this->url('cart-myresearchbulk')?>" data-lightbox data-lightbox-onsubmit="bulkFormHandler">
      <?=$this->context($this)->renderInContext('myresearch/bulk-action-buttons.phtml', ['idPrefix' => '', 'list' => isset($list) ? $list : null, 'account' => $this->account])?>
<!--    </form>   -->
<!--    </div>    -->
      <div class="myresultlist">
          <?php foreach ($this->results->getResults() as $i=>$current): ?>
              <?=$this->record($current)->getListEntry($list, $user)?>
          <?php endforeach; ?>
      </div>
</form> 
</div> 
    <?=$this->paginationControl($this->results->getPaginator(), 'Sliding', 'search/pagination.phtml', ['results' => $this->results])?>
  <?php else: ?>
    <p><?=$this->transEsc('You do not have any saved resources')?></p>
  <?php endif; ?>
</div>

<div class="<?=$this->layoutClass('sidebar')?>">
  <?=$this->context($this)->renderInContext("myresearch/menu.phtml", ['active' => isset($list) ? 'list' . $list['id'] : 'favorites'])?>
  <?php foreach ($this->results->getRecommendations('side') as $current): ?>
    <?=$this->recommend($current)?>
  <?php endforeach; ?>
</div>
