<?php
/**
 * Primary navigation component.
 *
 * @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 Navigation
 */
final class Navigation implements HeaderComponentInterface {

	/**
	 * {@inheritdoc}
	 *
	 * @param array<string, mixed> $args {
	 *     @type string $id       Nav element id.
	 *     @type string $class    CSS classes.
	 *     @type int    $depth    Menu depth.
	 *     @type string $position Optional menu position modifier (right|center|left).
	 * }
	 */
	public static function render( HeaderContext $ctx, array $args = array() ): void {
		unset( $ctx );

		$id    = isset( $args['id'] ) ? (string) $args['id'] : 'kutby-primary-nav';
		$class = isset( $args['class'] ) ? (string) $args['class'] : 'kutby-nav';
		$depth = isset( $args['depth'] ) ? (int) $args['depth'] : 2;

		if ( isset( $args['position'] ) ) {
			$pos = sanitize_key( (string) $args['position'] );
			if ( in_array( $pos, array( 'right', 'center', 'left' ), true ) ) {
				$class .= ' kutby-nav--' . $pos;
			}
		}
		?>
		<nav
			id="<?php echo esc_attr( $id ); ?>"
			class="<?php echo esc_attr( $class ); ?>"
			data-kutby-nav
			aria-label="القائمة الرئيسية"
		>
			<?php
			wp_nav_menu(
				array(
					'theme_location' => 'primary',
					'container'      => false,
					'menu_class'     => 'kutby-menu',
					'fallback_cb'    => false,
					'depth'          => $depth,
				)
			);
			?>
		</nav>
		<?php
	}
}
