<?php
/**
 * Header CTA button.
 *
 * @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 CTAButton
 */
final class CTAButton implements HeaderComponentInterface {

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

		$text = $ctx->string( 'cta_text' );
		$url  = $ctx->string( 'cta_url' );
		if ( '' === $text || '' === $url ) {
			return;
		}

		$class = isset( $args['class'] ) ? (string) $args['class'] : 'kutby-btn kutby-btn--primary kutby-header-cta';
		?>
		<a class="<?php echo esc_attr( $class ); ?>" href="<?php echo esc_url( $url ); ?>">
			<?php echo esc_html( $text ); ?>
		</a>
		<?php
	}
}
