<?php
/*
 * Software Name: Eorisis Pixels
 * Software URI: https://eorisis.com/shop/software/joomla/pixels
 * 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;

use com_eorisis_pixels\framework\lib\core\cms\language as cms_language;
use com_eorisis_pixels\framework\lib\core\model\form as form_model;
use com_eorisis_pixels\framework\lib\core\view\help;

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

class JFormFieldCat extends EorisisFormField
{
	protected $type = 'cat';
	protected $form;

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

	protected function getLabel() : string
	{
		return parent::getLabel().help::icon($this->element);
	}

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

	protected function getInput() : string
	{
		form_model::set($this->form);
		$default = 2;
		$options = [
			1 => 'EO_SHOW_COLUMN_AND_UNDER_TITLE',
			2 => 'EO_SHOW_COLUMN',
			3 => 'EO_SHOW_UNDER_TITLE',
			0 => 'EO_OFF'
		];

		$is_pro = defined('EORISIS_PIXELS_PRO');
		$args = [];
		$html = '';

		if (!$is_pro)
		{
			$html .= '<div class="flex-row">';

			$args['selected'] = $default;
			$args['disabled'] = true;
			$args['title'] = cms_language::text('EO_UPGRADE_TO_PRO_TO_USE_FEATURE');
		}

		$html .= form_model::select((string)$this->element['name'], $options, $default, $args);

		if (!$is_pro)
		{
			$html .=	'<div class="field-notice">'.cms_language::text('EO_UPGRADE_TO_PRO').'</div>';
			$html .= '</div>';
		}

		return $html;
	}
}
