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

namespace Kufer\KuferTools\Basis\Uebersicht;

abstract class UebersichtMitWssPresenter extends UebersichtPresenter
{
  protected function getContent()
  {
    if ($this->uebersichtAlsTabelle() && count($this->useCaseResponse->datamodule) > 0) {
      
      array_unshift($this->useCaseResponse->datamodule, $this->getDatamodulFuerUeberschriftszeile());
    }

    return $this->getAnderenContentAlsBody($this->useCaseResponse->datamodule);
  }

  protected function uebersichtAlsTabelle()
  {
    return isset($this->useCaseResponse->uebersichtAlsTabelle) && $this->useCaseResponse->uebersichtAlsTabelle;
  }

  protected function getDatamodulFuerUeberschriftszeile()
  {
    return new \Datamodul();
  }

  protected function getAnderenContent($datamodul, $key)
  {
    if ($this->uebersichtAlsTabelle()) {
      return $this->contentAlsTabelle($datamodul, $key);
    } else {
      return $this->contentAlsPanels($datamodul, $key);
    }
  }

  protected function contentAlsPanels($datamodul, $key)
  {
    $panelViewModel = $this->getPanelViewModel($datamodul);

    $panelViewModel->index = $key;
    $panelViewModel->columns = $this->useCaseResponse->columns;
    $panelViewModel->datamodul = $datamodul;

    $panelViewModel->panel = $this->datamodulToPanel($datamodul);
    $bodyView = $this->getPanelView($panelViewModel);

    return $bodyView->show();
  }

  protected function contentAlsTabelle($datamodul, $key)
  {
    $panelViewModel = $this->getTableViewModel($datamodul);

    $panelViewModel->index = $key;
    $panelViewModel->columns = $this->useCaseResponse->columns;
    $panelViewModel->datamodul = $datamodul;

    $panelViewModel->panel = $this->datamodulToPanel($datamodul);
    $bodyView = $this->getTableView($panelViewModel);

    return $bodyView->show();
  }

  protected function getPanels()
  {
    return array();
  }

  protected function getPanelViewModel($datamodul)
  {
    return new UebersichtPanelMitWssViewModel();
  }

  protected function getPanelView($viewModel)
  {
    return new UebersichtPanelMitWssView($viewModel);
  }

  protected function getTableViewModel($datamodul)
  {
    return new UebersichtTabelleMitWssViewModel();
  }

  protected function getTableView($viewModel)
  {
    return new UebersichtTabelleMitWssView($viewModel);
  }

  protected function getViewModel()
  {
    $viewModel = parent::getViewModel();
    $viewModel->toolId = $this->useCaseResponse->toolId;
    $viewModel->showBackButton = $this->showBackButton();
    $viewModel->fehlermeldung = $this->getFehlermeldung();
    $viewModel->erfolgsmeldung = $this->getErfolgsmeldungen();
    $viewModel->uebersichtAlsTabelle = $this->uebersichtAlsTabelle();

    return $viewModel;
  }

  protected function showBackButton()
  {
    return false;
  }

  protected function getFehlermeldung()
  {
    return '';
  }

  protected function getErfolgsmeldungen()
  {
    return '';
  }

  protected function getUebersichtViewModel()
  {
    return new UebersichtViewModel();
  }

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