<?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\toolbar as cms_toolbar;
use com_eorisis_pixels\framework\lib\core\cms\application;
use com_eorisis_pixels\framework\lib\core\cms\menu;
use com_eorisis_pixels\framework\lib\core\model\language as language_model;
use com_eorisis_pixels\framework\lib\core\model\toolbar as toolbar_model;
use com_eorisis_pixels\framework\lib\core\model\notices;
use com_eorisis_pixels\framework\lib\core\model\area;

if (version_compare(JVERSION, '3.8', '>='))
{
	JLoader::registerAlias('EorisisHtmlView', '\\Joomla\\CMS\\MVC\\View\\HtmlView');
}
else
{
	JLoader::registerAlias('EorisisHtmlView', 'JViewLegacy');
}

// Updates
class Eorisis_pixelsViewUpdates extends EorisisHtmlView
{
	protected $form;
	protected $item;
	protected $view_name;
	protected $canDo;
	protected $notifications = '';

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

	public function display($tpl = null)
	{
		// Display the view
		// @param   string  $tpl  The name of the template file to parse;
		//							automatically searches through the template paths

		$this->form = $this->get('Form');
		$this->item = $this->get('Item');
		$this->view_name = area::edit_view();
		$this->canDo = application::content_actions($this->view_name, (int)$this->form->getValue('id'));

		if (!$this->canDo->get('core.edit.'.$this->view_name))
		{
			return;
		}

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

		// Load Language Files
		language_model::jload('main');
		language_model::jload('toolbar');
		language_model::jload('help');
		language_model::jload('updates');

		// --------------------------------------------------
		// Checks

		application::error_check($this->get('Errors'));

		if (!notices::system_plugin_issue())
		{
			notices::check_eorisis_setup();
			notices::check_update_auth();
			notices::check_curl();
		}

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

		// Notifications
		$notifications = new \com_eorisis_pixels\framework\lib\core\controller\notifications;
		$this->notifications = $notifications->handler();

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

		// Display
		menu::hide_main();
		$this->addToolbar();
		parent::display($tpl);
	}

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

	protected function addToolbar()
	{
		$toolbar = new toolbar_model;
		$toolbar->remove_options_button();
		$toolbar->add_title(['EO_UPDATES']);
		$toolbar->add_save_buttons($this->view_name, ['apply','save']);
		cms_toolbar::add_close_button($this->view_name);

		if (version_compare(JVERSION, 4, '<'))
		{
			$toolbar->add_changelog_button($this->view_name);
			$toolbar->add_documentation_button($this->view_name);
		}
	}
}
