<?php
/**
 * Handles form data and saving for the SpectatorViews Appearance section.
 *
 * @package Ilabs\Firevert\Modules\SpectatorViews\Services\Form
 */

declare( strict_types=1 );

namespace Ilabs\Firevert\Modules\SpectatorViews\Services\Form;

use Ilabs\Firevert\Core\Settings\Form\DefaultSettingsProviderInterface;

/**
 * Class AppearanceFormHandler
 *
 * Processes widget appearance settings (colors, text, shadow).
 */
class AppearanceFormHandler extends AbstractFormHandler implements DefaultSettingsProviderInterface {

	/**
	 * Current section slug.
	 *
	 * @var string
	 */
	protected string $section_slug = 'appearance';

	/**
	 * Fields and their expected types.
	 *
	 * @var array<string, string>
	 */
	protected array $fields = array(
		'firevert_spectator_views_background'    => 'text',
		'firevert_spectator_views_accent_color'  => 'text',
		'firevert_spectator_views_primary_text'  => 'text',
		'firevert_spectator_views_add_border'    => 'bool',
		'firevert_spectator_views_border_color'  => 'text',
		'firevert_spectator_views_border_radius' => 'int',
		'firevert_spectator_views_add_shadow'    => 'bool',
	);

	/**
	 * Returns data to render in the appearance view.
	 *
	 * @return array<string, mixed> Array of field values and post object.
	 */
	public function get_data(): array {
		return array_merge(
			array( 'post' => $this->post ),
			$this->get_all_field_data()
		);
	}

	/**
	 * Returns default settings data.
	 *
	 * @return array<string, mixed>
	 */
	public function get_default_settings(): array {
		return array(
			'firevert_spectator_views_background'    => '#FFFFFF',
			'firevert_spectator_views_accent_color'  => '#F2003A',
			'firevert_spectator_views_primary_text'  => '#000000',
			'firevert_spectator_views_add_border'    => true,
			'firevert_spectator_views_border_color'  => '#00000038',
			'firevert_spectator_views_border_radius' => 20,
			'firevert_spectator_views_add_shadow'    => true,
		);
	}
}
