<?php
/*
 * Software Name: Eorisis Setup
 * Software URI: https://eorisis.com/shop/software/joomla/setup
 * 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 eorisis_setup\framework\lib\core\cms;
\defined('_JEXEC') or die;

use eorisis_setup\framework\lib\core\cms\application;
use eorisis_setup\framework\lib\core\model\database;

class component
{
	public function __construct() {}

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

	public static function get_params(string $element) : array
	{
		$dbo = application::dbo();
		$query = $dbo->getQuery(true);
		$query->select($dbo->quoteName('params'));
		$query->from($dbo->quoteName('#__extensions'));
		$query->where([
			$dbo->quoteName('type').'='.$dbo->quote('component'),
			$dbo->quoteName('element').'='.$dbo->quote($element)
		]);
		$dbo->setQuery($query);
		$result = database::get_array($dbo);
		if ($result['error'])
		{
			application::add_backend_message($result['error']);
			return [];
		}

		if (!isset($result['record']['params']))
		{
			return [];
		}

		return (array)\json_decode((string)$result['record']['params'], true);
	}
}
