<?php
/*
 * Software Name: Eorisis Setup
 * Software URI: https://eorisis.com/shop/software/joomla/setup
 * Author: Eorisis
 * Author URI: https://eorisis.com
 * Copyright: Copyright (C) 2011-2025 EORISIS. All Rights Reserved.
 * License: GNU General Public License version 2; See https://eorisis.com/gpl
 * Terms of Service: https://eorisis.com/tos
 */
defined('_JEXEC') or die;

if (!class_exists('eorisis_setup\framework\lib\eorisis', false))
{
	// Executing the autoloader
	$namespace_path = JPATH_PLUGINS.'/installer/eorisis_setup/framework/lib';
	require_once $namespace_path.'/eorisis.php';
	$eorisis = new \eorisis_setup\framework\lib\eorisis($namespace_path);
	$eorisis->register();
}

use eorisis_setup\framework\lib\core\cms\language as cms_language;
use eorisis_setup\framework\lib\core\model\form as form_model;
use eorisis_setup\framework\lib\core\model\convert;
use eorisis_setup\framework\lib\core\model\params;

if (!class_exists('EorisisFormField', false))
{
	if (version_compare(JVERSION, '3.8', '>='))
	{
		JLoader::registerAlias('EorisisFormField', '\\Joomla\\CMS\\Form\\FormField');
	}
	else
	{
		JLoader::registerAlias('EorisisFormField', 'JFormField');
	}
}

class JFormFieldEospacer extends EorisisFormField
{
	protected $type = 'eospacer';
	protected $form;

	// --------------------------------------------------

	protected function getTitle() : string
	{
		return $this->getLabel();
	}

	// --------------------------------------------------

	protected function getLabel() : string
	{
		form_model::set($this->form);
		$class = !empty($this->class) ? ' class="'.$this->class.'"' : '';

		$html  = '<span class="spacer no-animation">';
		$html .=	'<span class="before"></span>';
		$html .=	'<span'.$class.'>';

		if (params::field_value('hr', $this->element) == 'true')
		{
			$html .= '<hr'.$class.'>';
		}
		else
		{
			$text = params::field_value('label', $this->element);

			if (!$text)
			{
				$text = params::field_value('name', $this->element);
			}

			if ($this->translateLabel)
			{
				$text = cms_language::text($text);
			}

			if (!empty($this->description) and version_compare(JVERSION, 4, '<'))
			{
				$class = 'hasPopover';
			}
			else
			{
				$class = '';
			}

			$required = $this->required == true ? ' required' : '';

			$html .= '<label ';
			$html .=	'id="'.$this->id.'-lbl" ';
			$html .=	'class="'.$class.$required.'"';

			if (!empty($this->description))
			{
				// If a description is specified, use it to build a tooltip

				if ($this->translateDescription)
				{
					$description = cms_language::text($this->description);
				}
				else
				{
					$description = $this->description;
				}

				$html .= ' title="'.convert::htmlspecialchars(trim($text, ':')).'"';
				$html .= ' data-content="'.convert::htmlspecialchars($description).'"';

				if (cms_language::is_rtl())
				{
					$html .= ' data-placement="left"';
				}
			}
			
			$html .=	'>';
			$html .=	$text;
			$html .= '</label>';
		}

		$html .=	'</span>';
		$html .=	'<span class="after"></span>';
		$html .= '</span>';
		return $html;
	}

	// --------------------------------------------------

	protected function getInput() : string
	{
		return '';
	}

	// --------------------------------------------------

	public function renderField($options = [])
	{
		if (empty($options['class']))
		{
			$options['class'] = 'field-spacer';
		}
		else
		{
			$options['class'] = $options['class'].' field-spacer';
		}

		return parent::renderField($options);
	}
}
