<?php
/**
 * Volade Branding — Badge et crédit admin
 *
 * @package Volade\SDK
 * @license GPL-2.0-or-later
 */

trait Volade_Branding {

	public function init_branding() {
		add_filter( 'admin_footer_text', array( $this, 'modify_admin_footer' ) );
	}

	public function render_branding_badge() {
		$screen = get_current_screen();
		if ( ! $screen || strpos( $screen->id, 'volade' ) === false ) {
			return;
		}

		$user      = $this->get_current_user();
		$is_logged = ! is_null( $user );
		?>
		<div class="volade-branding-badge">
			<div class="volade-badge-inner">
				<span class="volade-badge-logo">V</span>
				<span class="volade-badge-text">Volade</span>
				<?php if ( $is_logged && isset( $user['pseudo'] ) ) : ?>
					<span class="volade-badge-user"><?php echo esc_html( $user['pseudo'] ); ?></span>
					<span class="volade-badge-level">Lv.<?php echo (int) $user['level']; ?></span>
					<span class="volade-badge-xp"><?php echo (int) $user['xp']; ?> XP</span>
				<?php endif; ?>
			</div>
		</div>
		<?php
	}

	public function modify_admin_footer( $text ) {
		if ( ! $this->is_user_logged_in() || get_option( 'volade_show_admin_footer', '0' ) !== '1' ) {
			return $text;
		}
		$text .= ' &bull; <span class="volade-footer-credit">⚡ <a href="' . esc_url( admin_url( 'admin.php?page=volade' ) ) . '">Volade</a></span>';
		return $text;
	}
}
