<?php
/**
 * Announcement bar 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 AnnouncementBar
 */
final class AnnouncementBar implements HeaderComponentInterface {

	/**
	 * {@inheritdoc}
	 */
	public static function render( HeaderContext $ctx, array $args = array() ): void {
		if ( ! $ctx->bool( 'announcement_enabled' ) ) {
			return;
		}

		$text = $ctx->string( 'announcement_text' );
		if ( '' === $text ) {
			return;
		}

		$link = $ctx->string( 'announcement_link' );
		?>
		<div class="kutby-announcement" role="region" aria-label="إعلان">
			<div class="kutby-container kutby-announcement__inner">
				<?php if ( '' !== $link ) : ?>
					<a class="kutby-announcement__link" href="<?php echo esc_url( $link ); ?>">
						<?php echo esc_html( $text ); ?>
					</a>
				<?php else : ?>
					<p class="kutby-announcement__text"><?php echo esc_html( $text ); ?></p>
				<?php endif; ?>
			</div>
		</div>
		<?php
	}
}
