<?php
/**
 * Perfil de guild — Nexora V6 Custom
 */
if (!defined('access') || !access) {
	die();
}

$pageTitle = (function_exists('lang') && lang('profiles_txt_1', true)) ? lang('profiles_txt_1', true) : 'Guild Profile';

echo '<div class="nexora-profile-page nexora-profile-guild">';
echo '<header class="nexora-profile-page-header"><h1 class="nexora-profile-page-title">'.htmlspecialchars($pageTitle).'</h1><span class="nexora-profile-page-line"></span></header>';

loadModuleConfigs('profiles');
if (!mconfig('active')) {
	message('error', lang('error_47', true));
	echo '</div>';
	return;
}
if (!isset($_GET['req'])) {
	message('error', lang('error_25', true));
	echo '</div>';
	return;
}

try {
	$weProfiles = new weProfiles();
	$weProfiles->setType("guild");
	$weProfiles->setRequest($_GET['req']);
	$guildData = $weProfiles->data();

	$guildMembers = explode(",", $guildData[5]);
	$displayData = array(
		'gname'   => $guildData[1],
		'glogo'   => returnGuildLogo($guildData[2], 150),
		'gmaster' => $guildData[4],
		'gscore'  => $guildData[3],
		'gmembers'=> count($guildMembers),
	);
	?>
		<div class="nexora-guild-card">
			<div class="nexora-guild-hero">
				<div class="nexora-guild-logo-wrap"><?php echo $displayData['glogo']; ?></div>
				<h2 class="nexora-guild-name"><?php echo htmlspecialchars($displayData['gname']); ?></h2>
			</div>

			<div class="nexora-guild-stats">
				<div class="nexora-guild-stat">
					<span class="nexora-guild-stat-label"><?php echo htmlspecialchars(lang('profiles_txt_3', true)); ?></span>
					<span class="nexora-guild-stat-value"><?php echo playerProfile($displayData['gmaster']); ?></span>
				</div>
				<div class="nexora-guild-stat">
					<span class="nexora-guild-stat-label"><?php echo htmlspecialchars(lang('profiles_txt_4', true)); ?></span>
					<span class="nexora-guild-stat-value"><?php echo number_format($displayData['gscore']); ?></span>
				</div>
				<div class="nexora-guild-stat">
					<span class="nexora-guild-stat-label"><?php echo htmlspecialchars(lang('profiles_txt_5', true)); ?></span>
					<span class="nexora-guild-stat-value"><?php echo number_format($displayData['gmembers']); ?></span>
				</div>
			</div>

			<section class="nexora-guild-members-section">
				<h3 class="nexora-guild-members-title"><?php echo htmlspecialchars(lang('profiles_txt_6', true)); ?></h3>
				<div class="nexora-guild-members-grid">
					<?php
					if (is_array($guildMembers)) {
						foreach ($guildMembers as $idx => $memberName) {
							echo '<div class="nexora-guild-member-item" style="animation-delay: ' . ($idx * 0.05) . 's">' . playerProfile($memberName) . '</div>';
						}
					}
					?>
				</div>
			</section>
		</div>
	<?php
} catch (Exception $e) {
	message('error', $e->getMessage());
}
echo '</div>';
