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

namespace Kufer\KuferTools\Mitarbeiter\Anmeldung\DetailsDialog;

class DetailsDialogPresenter extends \Kufer\KuferTools\Basis\Presenter\Presenter
{
  public function present()
  {
    $result = '';
    $detailsDialogView = $this->getView();
    $result .= $detailsDialogView->getHeader();
    $result .= $this->getContent();
    $result .= $detailsDialogView->getFooter();

    return $result;
  }

  protected function getContent()
  {
    return $this->getAnderenContentAlsBody($this->useCaseResponse->freiWaehlbareFelder);
  }

  protected function getAnderenContentAlsBody($datamodulArray)
  {
    $result = '';
    $view = $this->getView();
    if (!$this->isDatamodulAryEmpty($datamodulArray)) {
      foreach ($datamodulArray as $key => $datamodul) {
        $result .= $this->getAnderenContent($datamodul, $key);
      }
    } else {
      $result .= $view->getNoData();
    }

    return $result;
  }

  protected function getViewModel()
  {
    return new DetailsDialogViewModel();
  }

  
  protected function getAnderenContent($datamodul, $key)
  {
    static $htmlFreiWaehlbaresEingabefeld = null;
    if (is_null($htmlFreiWaehlbaresEingabefeld)) {
      $htmlFreiWaehlbaresEingabefeld = new \HtmlFreiWaehlbaresEingabefeldResponsive();
    }
    $viewModel = new FreiWaehlbareFelderViewModel();
    if (trim($datamodul->bezeichnung) != '') {
      $nr = $datamodul->id;
      $name = 'beleghistorie' . $nr;
      $viewModel->label = $htmlFreiWaehlbaresEingabefeld->getBezeichnungLabel($datamodul, $name);
      $viewModel->feld = $htmlFreiWaehlbaresEingabefeld->getInputFeld($datamodul, $name, $name, $name, $this->useCaseResponse->readonly, null, true);
    }
    $viewModel->index = $key;
    $notenView = new FreiWaehlbareFelderView($viewModel);

    return $notenView->show();
  }

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