<?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
 */
namespace com_eorisis_pixels\framework\lib\core\cms;
\defined('_JEXEC') or die;

use com_eorisis_pixels\framework\lib\core\cms\document as cms_document;
use com_eorisis_pixels\framework\lib\core\cms\input as cms_input;
use com_eorisis_pixels\framework\lib\core\view\form as form_view;

class form
{
	public function __construct() {}

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

	public static function get(string $key, $item_form)
	{
		// $item_form: Do not restrict object for php < 7.2

		if (\version_compare(JVERSION, '3.2', '>='))
		{
			return (array)$item_form->getData()->get($key);
		}

		return (array)$item_form->getValue($key);
	}

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

	public static function token() : string
	{
		static $val = null;
		if ($val === null)
		{
			$val = (string)cms_document::html_display('form.token');
		}

		return $val;
	}

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

	public static function add_validator() // void
	{
		cms_document::html_display('behavior.formvalidator');
	}

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

	public static function add_tabstate() // void
	{
		// Joomla 3 Only
		cms_document::html_display('behavior.tabstate');
	}

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

	public static function return_cmd() : string
	{
		$value = cms_input::get_cmd('return');
		return form_view::hidden('return', ['value' => $value]);
	}

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

	public static function forced_language() : string
	{
		$value = cms_input::get('forcedLanguage', '', 'cmd');
		return form_view::hidden('forcedLanguage', ['value' => $value]);
	}
}
