<?php
/**
 * Read more link.
 *
 * @package Kutby
 * @since   2.8.0
 */

declare(strict_types=1);

namespace Kutby\Hero\Components;

use Kutby\Hero\Contracts\HeroComponentInterface;
use Kutby\Hero\Support\HeroContext;
use WP_Post;

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

/**
 * Class ReadMoreButton
 */
final class ReadMoreButton implements HeroComponentInterface {

	/**
	 * {@inheritdoc}
	 */
	public static function render( HeroContext $ctx, array $args = array() ): void {
		unset( $ctx );
		$post = $args['post'] ?? null;
		if ( ! $post instanceof WP_Post ) {
			return;
		}

		$class = isset( $args['class'] ) ? (string) $args['class'] : 'kutby-btn kutby-hero-readmore';
		$label = isset( $args['label'] ) ? (string) $args['label'] : 'اقرأ المزيد';
		?>
		<a class="<?php echo esc_attr( $class ); ?>" href="<?php echo esc_url( get_permalink( $post ) ); ?>">
			<?php echo esc_html( $label ); ?>
		</a>
		<?php
	}
}
