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

namespace Kufer\Web\KuferTools\Utils\WssField\Kurstag;

use Kufer\Web\Classes\HTML\TextToHtmlConverter;

class WssFieldKurstagBemerkung extends \Kufer\Web\KuferTools\Utils\WssField\WssField
{
  protected function getFieldBearbeitbar($datamodulWert, $isFormular, string $requestPrefix = '')
  {
    $feld = parent::getFieldBearbeitbar($datamodulWert, $isFormular, $requestPrefix);

    $objSettings = \ToolSettingsAPI::getToolSettings(\RequestOperations::getVarValue('tool_id'));

    $hinterlegungFaecher = $hinterlegungFelder = '';
    if ($objSettings->hl_faecher) {
      $hinterlegungFaecher = $this->getHinterlegungFaecher();
    }
    if ($objSettings->hl_info_felder) {
      $hinterlegungFelder = $this->getHinterlegungInfoFelder($objSettings->hl_faecher);
    }

    return $feld . $hinterlegungFaecher . $hinterlegungFelder;
  }

  protected function getFieldNichtBearbeitbar($datamodulWert, $isFormular, string $requestPrefix = '')
  {
    $converter = new TextToHtmlConverter($datamodulWert->getVarValueEx('bemerkungen', 'kurstag'));

    return \StringOperations::convertLinebreaks2HTML($converter->toHTML());
  }

  private function getHinterlegungFaecher()
  {
    $buttonStyle = 'position: absolute; right: 20px; top: -3px; font-size: 27px; color: #555;';
    $result = $this->getHinterlegungButton($buttonStyle, 'button_hl_faecher');
    $result .= $this->getFaecherDialog();

    return $result;
  }

  private function getHinterlegungInfoFelder($twoButtons)
  {
    if ($twoButtons) {
      $top = 35;
    } else {
      $top = 3;
    }
    $buttonStyle = 'position: absolute; right: 20px; top: ' . $top . 'px; font-size: 27px; color: #555;';
    $result = $this->getHinterlegungButton($buttonStyle, 'button_hl_info_felder');
    $result .= $this->getInfoFelderDialog();

    return $result;
  }

  private function getFaecherDialog()
  {
    return '<div id="dialog_hl_faecher">' . \HinterlegungAPI::getFaecherListe() . '</div>';
  }

  private function getInfoFelderDialog()
  {
    return '<div id="dialog_hl_info_felder">' . \HinterlegungAPI::getInfoFelderFuerKurstagListe() . '</div>';
  }

  private function getHinterlegungButton($pButtonStyle, $pButtonClass)
  {
    return '<span style=" ' . $pButtonStyle . ' cursor:pointer;">'
                   . '<i class="fa fa-hand-o-down ' . $pButtonClass . '" aria-hidden="true"></i>'
                 . '</span>';
  }
}