<?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 define, class_exists, version_compare, key;
use EorisisHTMLHelper, JLoader;
use com_eorisis_pixels\framework\lib\core\cms\document as cms_document;
use com_eorisis_pixels\framework\lib\core\cms\language as cms_language;

if (!class_exists('EorisisHTMLHelper', false))
{
	if (version_compare(JVERSION, '3.8', '>='))
	{
		JLoader::registerAlias('EorisisHTMLHelper', '\\Joomla\\CMS\\HTML\\HTMLHelper');
	}
	else
	{
		JLoader::registerAlias('EorisisHTMLHelper', 'JHtml'); 
	}
}

if (version_compare(JVERSION, 4, '>='))
{
	define('EORISIS_TAB_PARAM', 'uitab');
}
else
{
	define('EORISIS_TAB_PARAM', 'bootstrap');
}

class tab
{
	public function __construct() {}

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

	public function start(array $fieldsets = [])
	{
		$options = [
			'active' => $this->active_name($fieldsets),
			'recall' => true
		];
		return cms_document::html(EORISIS_TAB_PARAM.'.startTabSet', 'myTab', $options);
	}

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

	public function add(string $name, $key)
	{
		$label = $key ? cms_language::text($key) : $key;
		return EorisisHTMLHelper::_(EORISIS_TAB_PARAM.'.addTab', 'myTab', $name, $label);
	}

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

	public function set_end()
	{
		return cms_document::html_display(EORISIS_TAB_PARAM.'.endTabSet');
	}

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

	public function end()
	{
		return cms_document::html_display(EORISIS_TAB_PARAM.'.endTab');
	}

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

	private function active_name(array $fieldsets)
	{
		// Fetch a key from an array
		return $fieldsets ? key($fieldsets) : 'general';
	}
}
