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

namespace Kufer\KuferTools\Utils\WssField;

class WssFieldKurstagBemerkung extends 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;
  }

  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>';
  }
}