<?php
  /**
   * @package     Formea.Plugin
   * @subpackage  element
   *
   * @copyright   Copyright (C) 2010-2023 Feseur Sdn Bhd. All rights reserved.
   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   */
// no direct access
  defined('_JEXEC') or die();

  use Joomla\CMS\Dispatcher\DispatcherInterface;
  use Joomla\CMS\Editor\Editor;
  use Joomla\CMS\Extension\PluginInterface;
  use Joomla\CMS\Factory;
  use Joomla\CMS\HTML\HTMLHelper;
  use Joomla\CMS\Layout\LayoutHelper;
  use Joomla\CMS\Plugin\PluginHelper;
  use Joomla\Component\Formea\Site\Helper\FormeaGeneralHelper;
  use Joomla\Component\Formea\Site\Libraries\FormeaElementAttribute;
  use Joomla\Component\Formea\Site\Libraries\FormeaEltype;

  class FormeaEditor extends FormeaEltype
  {
    public function __construct($config = [])
    {
      parent::__construct($config);
      $this->element_css_class[] = 'editor';
    }


    public function getInput($class = [], $inputAttributes = [], $langTagUnderscore = '', $preview = false, $labelSetting = null)
    {
      $html = '';
      if ($preview)
      {
        return '<textarea placeholder="Joomla! Editor" class="form-control"></textarea>';
      }
      else
      {
        $app        = Factory::getApplication();
        $jconfig    = $app->getConfig();
        $editorName = $this->params->get('formea_editor', $jconfig->get('editor'));

        $editor = Editor::getInstance($editorName);
        $value  = '';
        $width  = $this->params->get('editor_width', '100%');
        $height = $this->params->get('editor_height', '230px');
        if (isset($inputAttributes['value']))
        {
          $value = $inputAttributes['value'];
        }
        $html = $editor->display($this->formatElementName(), htmlspecialchars($value, ENT_COMPAT, 'UTF-8'), $width, $height, '20', '20', false, $this->formatElementId(), 'formeaEditor',);
      }

      return $html;
    }

  }
