<?php
/**
 * Schema-driven options page (Arabic labels from Field Registry).
 *
 * @package Kutby
 * @since   2.0.0
 */

declare(strict_types=1);

namespace Kutby\Pages;

use Kutby\ThemeOptions\FieldRegistry;

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

/**
 * Class SchemaDrivenPage
 */
final class SchemaDrivenPage extends AbstractPage {

	/**
	 * @param string $panel_id Panel ID.
	 * @param string $title    Arabic title.
	 */
	public function __construct(
		private readonly string $panel_id,
		private readonly string $title
	) {}

	/** {@inheritdoc} */
	public function id(): string {
		return $this->panel_id;
	}

	/** {@inheritdoc} */
	public function title(): string {
		return $this->title;
	}

	/** {@inheritdoc} */
	public function fields( array $options ): array {
		$values = is_array( $options[ $this->panel_id ] ?? null ) ? $options[ $this->panel_id ] : array();
		return FieldRegistry::fields_for( $this->panel_id, $values );
	}
}
