<?php
/**
 * Shared section heading.
 *
 * @package Kutby
 * @since   2.9.1
 */

declare(strict_types=1);

namespace Kutby\Homepage;

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

/**
 * Class SectionHeader
 */
final class SectionHeader {

	/**
	 * @param string               $title Title.
	 * @param string               $lead  Optional lead.
	 * @param string               $id    Optional heading id.
	 * @param array<string,string> $args  Optional link args: url, label.
	 * @return void
	 */
	public static function render( string $title, string $lead = '', string $id = '', array $args = array() ): void {
		$url   = isset( $args['url'] ) ? (string) $args['url'] : '';
		$label = isset( $args['label'] ) ? (string) $args['label'] : 'عرض الكل';
		?>
		<header class="kutby-home-section__header">
			<div class="kutby-home-section__heading">
				<h2 class="kutby-home-section__title"<?php echo $id ? ' id="' . esc_attr( $id ) . '"' : ''; ?>>
					<?php echo esc_html( $title ); ?>
				</h2>
				<?php if ( '' !== $url ) : ?>
					<a class="kutby-home-section__more" href="<?php echo esc_url( $url ); ?>">
						<?php echo esc_html( $label ); ?>
					</a>
				<?php endif; ?>
			</div>
			<?php if ( '' !== $lead ) : ?>
				<p class="kutby-home-section__lead"><?php echo esc_html( $lead ); ?></p>
			<?php endif; ?>
		</header>
		<?php
	}
}
