<?php
/**
 * Account link.
 *
 * @internal Experimental — not wired in production layouts. Enable via
 *           `kutby_header_experimental_account_link` filter only.
 *
 * @package Kutby
 * @since   2.6.0
 */

declare(strict_types=1);

namespace Kutby\Header\Components;

use Kutby\Header\Contracts\HeaderComponentInterface;
use Kutby\Header\Support\HeaderContext;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class AccountLink
 *
 * @internal Stub destination (wp-admin profile) — do not expose in Admin.
 */
final class AccountLink implements HeaderComponentInterface {

	/**
	 * {@inheritdoc}
	 */
	public static function render( HeaderContext $ctx, array $args = array() ): void {
		/**
		 * Allow experimental account link rendering (default off).
		 *
		 * @since 2.6.1
		 *
		 * @param bool $enabled Whether to render.
		 */
		if ( ! apply_filters( 'kutby_header_experimental_account_link', false ) ) {
			return;
		}

		if ( ! $ctx->bool( 'show_account' ) ) {
			return;
		}

		if ( is_user_logged_in() ) {
			$url   = admin_url( 'profile.php' );
			$label = 'حسابي';
		} else {
			$url   = wp_login_url();
			$label = 'تسجيل الدخول';
		}
		?>
		<a class="kutby-header-account" href="<?php echo esc_url( $url ); ?>">
			<?php echo esc_html( $label ); ?>
		</a>
		<?php
	}
}
