<?php
/**
 * Handles form data and saving for the SpectatorViews "Widget Settings" 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;
use Ilabs\Firevert\Modules\SpectatorViews\Services\Type\PositionType;

/**
 * Class SettingsFormHandler
 *
 * Handles sanitization and data access for SpectatorViews settings form.
 */
class SettingsFormHandler extends AbstractFormHandler implements DefaultSettingsProviderInterface {

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

	/**
	 * Fields and their expected types.
	 *
	 * @var array<string, string>
	 */
	protected array $fields = array(
		'firevert_spectator_views_visible_admin_only' => 'bool',
		'firevert_spectator_views_display_position'   => 'text',
	);

	/**
	 * Returns data to render in the settings 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_visible_admin_only' => true,
			'firevert_spectator_views_display_position'   => PositionType::BEFORE_ADD_TO_CART_BUTTON,
		);
	}
}
