<?php
/**
 * @copyright (c) Kufer Software GmbH, Oderstraße 7, D-84453 Mühldorf
 */

namespace Kufer\Web\KuferTools\Basis\Kursdetails\Detailsreiter\Dozenten;

use Kufer\Web\KuferTools\Basis\View\DetailsTabelleRowView;
use Kufer\Web\KuferTools\Basis\View\DetailsTabelleRowViewModel;

class DozentenPresenter extends \Kufer\Web\KuferTools\Basis\Presenter\Presenter
{
  public function present()
  {
    
    
    $dbwDozHon = new \DBWorkDozentenHonorar();
    $emptyDozHon = $dbwDozHon->getNewObject();
    $dozHonorare = \array_merge(array($emptyDozHon), $this->useCaseResponse->honorare);

    return $this->getAnderenContentAlsBody($dozHonorare);
  }

  protected function isDatamodulAryEmpty(array $datamodulArray): bool
  {
    return count($datamodulArray) <= 1;
  }

  protected function getAnderenContent($datamodul, $key): string
  {
    $showCheckbox = $this->useCaseResponse->markierenButtons;
    $isHeader = empty($datamodul->id);
    $viewDetailsModel = new DozentenRowViewModel();
    $viewDetailsModel->dozHonorar = $datamodul;
    $viewDetailsModel->showCheckbox = $showCheckbox;
    $viewDetailsModel->isHeader = $isHeader;
    $viewDetails = new DozentenRowView($viewDetailsModel);

    $viewModel = new DetailsTabelleRowViewModel(
      $this->useCaseResponse->toolSection,
      $this->useCaseResponse->toolSettings,
      $showCheckbox,
      $isHeader,
      trim($viewDetails->getHeader()),
      $this->useCaseResponse->columns,
      $datamodul->id,
      $datamodul
    );

    $viewModel->additionalContent = $viewDetails->getBody();
    $viewModel->checkboxInputAttr = trim($viewDetails->getFooter());

    $view = new DetailsTabelleRowView($viewModel);

    return $view->show();
  }

  protected function getView()
  {
    return new DozentenReiterView($this->getViewModel());
  }

  protected function getViewModel()
  {
    $viewModel = new DozentenReiterViewModel();
    $viewModel->toolSection = $this->useCaseResponse->toolSection;
    $viewModel->toolSettings = $this->useCaseResponse->toolSettings;
    $viewModel->kurs = $this->useCaseResponse->kurs;
    $viewModel->kurs->toolId = $this->useCaseResponse->toolId;
    $viewModel->kurs->reiterButtons = $this->getButtonHtml();
    $viewModel->kurs->markierenButtons = $this->useCaseResponse->markierenButtons;

    $viewModel->jsdeclarations = $this->getJsDeclarations();

    return $viewModel;
  }

  protected function getButtonHtml()
  {
    $buttonleiste = new \Kufer\Web\KuferTools\Basis\Button\Buttonleiste();

    return $buttonleiste->getHtmlButtonleiste($this->useCaseResponse->reiterButtons, 'dozenten_buttons');
  }

  
  protected function getJSDeclarations(): string
  {
    $result = 'registerNamespace("KuferTools.KursDetails.DozentDelete");' . "\n";
    
    
    $result .= \JsOperations::getDeclarationString('KuferTools.KursDetails.DozentDelete.Xsrf', $this->useCaseResponse->dozentDeleteXsrf);
    $result .= \JsOperations::getDeclarationBoolean('KuferTools.KursDetails.newDozentAllow', (bool)$this->useCaseResponse->newDozentAllow);
    $result .= \JsOperations::getDeclarationJson('KuferTools.KursDetails.DozKursIdZuDnrMapping', $this->useCaseResponse->dozKursIdZuDnrMapping);

    return $result;
  }
}