<?php


/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */


class CatalogBarWithJsDialog
{
  protected $currentIndex;
  protected $maxIndex;
  protected $selflink;
  protected $nextLinkContent;
  protected $previousLinkContent;
  protected $cssIdPrefix;

  
  public function __construct($currentIndex, $maxIndex, $selflink, $nextLinkContent = 'weiter', $previousLinkContent = 'zurueck', $cssIdPrefix = '')
  {
    $this->currentIndex = $currentIndex;
    $this->maxIndex = $maxIndex;
    $this->selflink = $selflink;
    $this->nextLinkContent = $nextLinkContent;
    $this->previousLinkContent = $previousLinkContent;
    $this->cssIdPrefix = $cssIdPrefix;
  }

  
  public function Render()
  {
    return $this->GetPreviousLink() . $this->GetNavigationDisplay() . $this->GetNextLink();
  }

  
  protected function GetPreviousLink()
  {
    $url = new URL($this->selflink);

    $url->removeSpecialParametersFromUrl();

    $url->SetParameterValue('currentIndex', $this->currentIndex);

    return $this->currentIndex == 0 ? '' : '<a class="blaettern ' . CleanOperations::cleanStringForHtml($this->cssIdPrefix) . 'CatalogBarPreviousLink" href="' . CleanOperations::cleanStringForHtml($url->getUrlRelative()) . '">' . $this->previousLinkContent . '</a> ';
  }

  
  protected function GetNextLink()
  {
    $url = new URL($this->selflink);

    $url->removeSpecialParametersFromUrl();

    $url->SetParameterValue('currentIndex', ($this->currentIndex + 2)); 

    return $this->currentIndex == $this->maxIndex ? '' : '<a class="blaettern ' . CleanOperations::cleanStringForHtml($this->cssIdPrefix) . 'CatalogBarNextLink" href="' . CleanOperations::cleanStringForHtml($url->getUrlRelative()) . '">' . $this->nextLinkContent . '</a> ';
  }

  
  protected function GetNavigationDisplay()
  {
    if ($this->currentIndex == $this->maxIndex && $this->maxIndex == 0) {
      return '';
    }

    return HTMLOperations::createButtonSpan(($this->currentIndex + 1) . ' / ' . ($this->maxIndex + 1), 'Seite wechseln', $this->cssIdPrefix . 'CatalogBarNavigationDisplay');
  }
}