<?php
/**
 * Mobile nav toggle 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;
use Kutby\Icons\Icon;

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

/**
 * Class MobileToggle
 */
final class MobileToggle implements HeaderComponentInterface {

	/**
	 * {@inheritdoc}
	 */
	public static function render( HeaderContext $ctx, array $args = array() ): void {
		unset( $ctx );
		$controls = isset( $args['controls'] ) ? (string) $args['controls'] : 'kutby-primary-nav';
		$class    = isset( $args['class'] ) ? (string) $args['class'] : 'kutby-nav-toggle kutby-hide-desktop';
		?>
		<button
			type="button"
			class="<?php echo esc_attr( $class ); ?>"
			data-kutby-nav-toggle
			aria-controls="<?php echo esc_attr( $controls ); ?>"
			aria-expanded="false"
		>
			<span class="kutby-sr-only">القائمة</span>
			<?php
			$icon = Icon::render( 'menu', 'kutby-nav-toggle__icon', 'md' );
			if ( '' !== $icon ) {
				echo $icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- SVG via Icon.
			} else {
				echo '<span aria-hidden="true">☰</span>';
			}
			?>
		</button>
		<?php
	}
}
