<?php
/**
 * Social icons for header.
 *
 * @internal Experimental — letter placeholders, not production Icon set.
 *           Not wired in production layouts. Enable via
 *           `kutby_header_experimental_social_icons` filter only.
 *
 * @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 SocialIcons
 *
 * @internal Incomplete presentation — do not expose in Admin.
 */
final class SocialIcons implements HeaderComponentInterface {

	/**
	 * Network key => Arabic label.
	 *
	 * @var array<string, string>
	 */
	private const NETWORKS = array(
		'facebook'  => 'فيسبوك',
		'twitter'   => 'إكس',
		'telegram'  => 'تيليجرام',
		'whatsapp'  => 'واتساب',
		'youtube'   => 'يوتيوب',
		'instagram' => 'إنستغرام',
	);

	/**
	 * {@inheritdoc}
	 */
	public static function render( HeaderContext $ctx, array $args = array() ): void {
		/**
		 * Allow experimental header social icons (default off).
		 *
		 * @since 2.6.1
		 *
		 * @param bool $enabled Whether to render.
		 */
		if ( ! apply_filters( 'kutby_header_experimental_social_icons', false ) ) {
			return;
		}

		if ( ! $ctx->bool( 'show_social' ) ) {
			return;
		}

		$social = $ctx->social();
		$links  = array();
		foreach ( self::NETWORKS as $key => $label ) {
			$url = isset( $social[ $key ] ) ? (string) $social[ $key ] : '';
			if ( '' !== $url ) {
				$links[ $key ] = array(
					'url'   => $url,
					'label' => $label,
				);
			}
		}

		if ( empty( $links ) ) {
			return;
		}
		?>
		<ul class="kutby-header-social" aria-label="وسائل التواصل">
			<?php foreach ( $links as $key => $item ) : ?>
				<li class="kutby-header-social__item kutby-header-social__item--<?php echo esc_attr( $key ); ?>">
					<a
						href="<?php echo esc_url( $item['url'] ); ?>"
						target="_blank"
						rel="noopener noreferrer"
						aria-label="<?php echo esc_attr( $item['label'] ); ?>"
					>
						<span aria-hidden="true"><?php echo esc_html( strtoupper( substr( $key, 0, 1 ) ) ); ?></span>
					</a>
				</li>
			<?php endforeach; ?>
		</ul>
		<?php
	}
}
