<?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\model;
\defined('_JEXEC') or die;

use com_eorisis_pixels\framework\lib\core\app\config as app_config;
use com_eorisis_pixels\framework\lib\core\cms\language as cms_language;
use com_eorisis_pixels\framework\lib\core\cms\head as cms_head;
use com_eorisis_pixels\framework\lib\core\model\params;
use com_eorisis_pixels\framework\lib\core\view\link;

class document
{
	const FONTS_URI = 'https://fonts.googleapis.com/css?family=Open+Sans:300,400,500|Roboto+Condensed:300,400,700|Ubuntu+Mono:400';

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

	public function __construct() {}

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

	public static function link_to_site(string $relative_uri, string $content = '') : string
	{
		return link::a('https://eorisis.com/'.$relative_uri, [
			'content' => $content,
			'target' => '_blank',
			'title' => cms_language::text('EO_OPEN_IN_NEW_WINDOW')
		]);
	}

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

	public static function set_component_layout() // void
	{
		static $done = null;
		if ($done)
		{
			return;
		}

		app_config::init();
		cms_language::load(app_config::COMPONENT_ELEMENT);

		cms_head::add_css_uri([
			'name' => 'eorisis-backend-fonts',
			'uri' => self::FONTS_URI
		]);

		// Layout Colors
		$css = self::get_component_layout_colors_css();
		cms_head::add_css_inline($css);
		$media_uri = app_config::media_uri_relative(true).'/assets/css';

		cms_head::add_css_uri([
			'name' => 'eorisis-backend-component',
			'uri' => $media_uri.'/backend-component.css',
			'version' => true
		]);

		if (\version_compare(JVERSION, 5, '>='))
		{
			cms_head::add_css_uri([
				'name' => 'eorisis-backend-component-dark',
				'uri' => $media_uri.'/backend-component-dark.css',
				'version' => true
			]);
		}

		$done = true;
	}

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

	private static function get_component_layout_colors_css() : string
	{
		// >= J4
		if (\version_compare(JVERSION, 4, '>='))
		{
			// Sidebar
			if (!params::ui('sidebar_menus', 0))
			{
				return '.sidebar-wrapper{display:none}';
			}

			return '';
		}

		if (params::ui('layout_colors', 'eorisis') == 'default')
		{
			return '';
		}

		$css  = '.admin .header{background-color:#474747}';
		$css .= '.admin nav.navbar.navbar-inverse.navbar-fixed-top .navbar-inner,.admin #status.navbar.status-top{background-color:#1d2023}';

		// TODO: To be removed - not using sidebar anymore in J3
		// Sidebar - Joomla 3 Only
		if (params::ui('sidebar_menus', 0))
		{
			$css .= '.admin #sidebar .sidebar-nav ul li.active a{background-color:#6c757d}';
			$css .= '.admin #sidebar .sidebar-nav ul li a:hover{background-color:#999}';
			$css .= '.admin .j-toggle-sidebar-button {color:#6c757d}';
		}

		return $css;
	}
}
