<?php
/**
 * Theme toggle shell.
 *
 * @internal Experimental — not wired in production layouts. Enable via
 *           `kutby_header_experimental_theme_toggle` 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 ThemeToggle
 *
 * @internal Incomplete dark-mode behavior — do not expose in Admin.
 */
final class ThemeToggle implements HeaderComponentInterface {

	/**
	 * {@inheritdoc}
	 */
	public static function render( HeaderContext $ctx, array $args = array() ): void {
		$force = ! empty( $args['force'] );

		/**
		 * Allow experimental theme toggle rendering (default off).
		 *
		 * @since 2.6.1
		 *
		 * @param bool $enabled Whether to render.
		 */
		if ( ! $force && ! apply_filters( 'kutby_header_experimental_theme_toggle', false ) ) {
			return;
		}

		if ( ! $force && ! $ctx->bool( 'show_theme_toggle' ) ) {
			return;
		}

		$class = isset( $args['class'] ) ? (string) $args['class'] : 'kutby-theme-toggle';
		?>
		<button
			type="button"
			class="<?php echo esc_attr( $class ); ?>"
			data-kutby-theme-toggle
			aria-pressed="false"
			aria-label="تبديل المظهر"
		>
			<span class="kutby-theme-toggle__sun" aria-hidden="true">
				<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg>
			</span>
			<span class="kutby-theme-toggle__moon" aria-hidden="true">
				<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/></svg>
			</span>
		</button>
		<?php
	}
}
