<?php
/**
 * WebEngine CMS
 * https://webenginecms.org/
 *
 * @version 1.2.6
 * @author Gabo Development <https://gabodevelop.com/>
 * @copyright (c) 2026 Gabriel Development, All Rights Reserved
 */

/**
 * Nexora VE S6 - User Control Panel (rediseño)
 * Panel de usuario: tarjetas glass con icono + título, estilo coherente con Info/Downloads.
 */

try {
if (!isLoggedIn()) redirect(1, 'login');

$cfg = loadConfig('usercp');
if (!is_array($cfg)) throw new Exception('Could not load usercp, please contact support.');

$usercpTitle = lang('module_titles_txt_3', true) ?: 'User CP';
$activeItems = array();
foreach ($cfg as $element) {
	if (!is_array($element)) continue;
	if (!$element['active']) continue;
	if (isset($element['visibility']) && $element['visibility'] === 'guest' && isLoggedIn()) continue;
	if (isset($element['visibility']) && $element['visibility'] === 'user' && !isLoggedIn()) continue;
	$activeItems[] = $element;
}
?>
<div class="nexora-usercp">
	<header class="nexora-usercp-header">
		<h1 class="nexora-usercp-title"><?php echo htmlspecialchars($usercpTitle); ?></h1>
		<p class="nexora-usercp-subtitle"><?php echo htmlspecialchars(config('website_title')); ?> — <?php echo htmlspecialchars(lang('module_titles_txt_3', true) ?: 'Account'); ?></p>
	</header>

	<div class="nexora-usercp-grid">
		<?php foreach ($activeItems as $i => $element) {
			$link = ($element['type'] == 'internal') ? __BASE_URL__ . $element['link'] : $element['link'];
			$title = check_value(lang($element['phrase'], true)) ? lang($element['phrase']) : 'ERROR';
			$icon = function_exists('nexoraUsercpIcon') ? nexoraUsercpIcon($element) : (check_value($element['icon']) ? __PATH_TEMPLATE_IMG__ . 'icons/' . $element['icon'] : __PATH_TEMPLATE_IMG__ . 'icons/usercp_default.png');
			$newtab = !empty($element['newtab']);
		?>
		<a href="<?php echo htmlspecialchars($link); ?>" class="nexora-usercp-item"<?php echo $newtab ? ' target="_blank" rel="noopener"' : ''; ?>>
			<span class="nexora-usercp-item-icon">
				<img src="<?php echo htmlspecialchars($icon); ?>" alt="" width="56" height="56" loading="lazy" />
			</span>
			<span class="nexora-usercp-item-title"><?php echo htmlspecialchars($title); ?></span>
		</a>
		<?php } ?>
	</div>
</div>
<?php
} catch (Exception $e) {
	message('error', $e->getMessage());
}
