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

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

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

class MaterialPresenter extends \Kufer\Web\KuferTools\Basis\Presenter\Presenter
{
  public function present()
  {
    
    $dbwMaterial = new \DBWorkMaterial();
    $leereMaterial = $dbwMaterial->getNewObject();
    $material = \array_merge(array($leereMaterial), $this->useCaseResponse->materialien);

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

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

  protected function getAnderenContent($datamodul, $key): string
  {
    $isHeader = empty($datamodul->id);
    $showCheckbox = false;
    $viewDetailsModel = new MaterialRowViewModel();
    $viewDetailsModel->material = $datamodul;
    $viewDetailsModel->isHeader = $isHeader;
    $viewDetailsModel->showCheckbox = $showCheckbox;
    $viewDetails = new MaterialRowView($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 MaterialReiterView($this->getViewModel());
  }

  protected function getViewModel()
  {
    $viewModel = new MaterialReiterViewModel();
    $viewModel->toolSection = $this->useCaseResponse->toolSection;
    $viewModel->toolSettings = $this->useCaseResponse->toolSettings;
    $viewModel->kurs = $this->useCaseResponse->kurs;
    $viewModel->materialien = $this->useCaseResponse->materialien;

    return $viewModel;
  }
}