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

namespace Kufer\Web\KuferTools\Basis\Uebersicht;

abstract class UebersichtPresenter extends \Kufer\Web\KuferTools\Basis\Presenter\MitRahmenPresenter
{
  protected function getPanelTitle($datamodul)
  {
    return '';
  }

  protected function getPanelTitleHinweis()
  {
    return '';
  }

  protected function getPanelBody($datamodul)
  {
    return '';
  }

  protected function getMaxPanelSpalten()
  { 
    return 2;
  }

  protected function getPanelCheckBoxValue($datamodul)
  {
    return '';
  }

  protected function getPanelTitleLink($datamodul)
  {
    return '';
  }

  
  protected function getPanelBootStrapColor($datamodul)
  {
    return 'default';
  }

  protected function getViewModel()
  {
    $viewModel = $this->getUebersichtViewModel();
    $viewModel->blaettern = $this->getBlaettern();
    $viewModel->buttons = $this->getButtonHtml();
    $viewModel->ueberschrift = $this->useCaseResponse->ueberschrift;
    $viewModel->freitext = $this->useCaseResponse->freitext;
    $viewModel->display_buttons_top = $this->useCaseResponse->display_buttons_top;
    $viewModel->display_buttons_bottom = $this->useCaseResponse->display_buttons_bottom;
    $viewModel->maxPanelSpalten = $this->getMaxPanelSpalten();
    $viewModel->panels = $this->getPanels();

    return $viewModel;
  }

  protected function getSeitenTitel(): string
  {
    return $this->useCaseResponse->ueberschrift ?? '';
  }

  protected function getBlaettern()
  {
    return \Kufer\Web\KuferTools\Basis\Blaettern\BlaetternLeiste::getBlaetternLeiste($this->getBlaetternAction(), $this->useCaseResponse->toolId, $this->useCaseResponse->blaettern);
  }

  protected function getPanels()
  {
    $datamodule = $this->useCaseResponse->datamodule;
    $panels = array();
    foreach ($datamodule as $datamodul) {
      $panels[] = $this->datamodulToPanel($datamodul);
    }

    return $panels;
  }

  abstract protected function getBlaetternAction();

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

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

  protected function getJsFilesSrcAryWeitere(): array
  {
    return array(
      $this->getJsFileFromSys('filter.js'),
      $this->getJsFileFromSys('uebersicht.js')
    );
  }

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

    return $buttonleiste->getHtmlButtonleiste($this->useCaseResponse->buttons);
  }

  protected function datamodulToPanel($datamodul)
  {
    $panel = new \Kufer\Web\KuferTools\Basis\Panel\Panel();
    $panel->title = $this->getPanelTitle($datamodul);
    $panel->titleHinweis = $this->getPanelTitleHinweis();
    $panel->body = $this->getPanelBody($datamodul);
    $panel->buttons = $this->getPanelButtons($datamodul);
    $panel->spaltenMax = $this->getMaxPanelSpalten();

    $panel->showCheckbox = $this->useCaseResponse->showCheckbox;
    $panel->checkBoxValue = $this->getPanelCheckBoxValue($datamodul);

    $panel->verlinkeTitle = $this->useCaseResponse->verlinkePanelTitle;
    $panel->titleLink = $this->getPanelTitleLink($datamodul);
    $panel->titleLinkSymbol = $this->getPanelLinkSymbol();
    $panel->titleLinkText = $this->getPanelLinkText();
    $panel->bootstrapColor = $this->getPanelBootStrapColor($datamodul);

    return $panel;
  }

  protected function getPanelButtons($datamodul)
  {
    if (is_array($this->useCaseResponse->panelButtonCallBacks) && count($this->useCaseResponse->panelButtonCallBacks) > 0) {
      $buttonViewModel = new \Kufer\Web\KuferTools\Basis\Button\ButtonAllgViewModel();

      $buttons = array();
      foreach ($this->useCaseResponse->panelButtonCallBacks as $buttonFeedBack) {
        $btn = $buttonFeedBack($datamodul);
        if ($btn) { 
          $buttons[] = $btn;
        }
      }

      $buttonViewModel->buttons = $buttons;
      $buttonView = new \Kufer\Web\KuferTools\Basis\Button\ButtonAllgView($buttonViewModel);

      return $buttonView->show();
    } else {
      return '';
    }
  }

  
  protected function getPanelLinkSymbol()
  {
    return 'fa fa-search-plus';
  }

  
  protected function getPanelLinkText()
  {
    $panelLinkHinweis = $this->getPanelTitleHinweis();
    if (trim($panelLinkHinweis) != '') {
      return $panelLinkHinweis;
    }

    return 'Zu den Details';
  }
}