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

declare( strict_types=1 );

namespace Ilabs\Firevert\Modules\PromoTimeWidget\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_promo_time_widget_text'               => 'html',
		'firevert_promo_time_widget_background'         => 'text',
		'firevert_promo_time_widget_accent_color'       => 'text',
		'firevert_promo_time_widget_primary_text'       => 'text',
		'firevert_promo_time_widget_counter_background' => 'text',
		'firevert_promo_time_widget_counter_text'       => 'text',
		'firevert_promo_time_widget_add_shadow'         => 'bool',
		'firevert_promo_time_widget_border_radius'      => 'int',
	);

	/**
	 * Returns translatable fields used in this form.
	 *
	 * @return array<string>
	 */
	public function get_translatable_fields(): array {
		return array(
			'firevert_promo_time_widget_text',
		);
	}

	/**
	 * 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_promo_time_widget_text'          => '<p style="text-align: left;">Only now <strong>000$</strong> cheaper with the code <strong>TESTCODE</strong></p>',
			'firevert_promo_time_widget_background'    => '#047EF8',
			'firevert_promo_time_widget_accent_color'  => '#FFD500',
			'firevert_promo_time_widget_primary_text'  => '#FFFFFF',
			'firevert_promo_time_widget_counter_background' => '#FFD500',
			'firevert_promo_time_widget_counter_text'  => '#000000',
			'firevert_promo_time_widget_add_shadow'    => true,
			'firevert_promo_time_widget_border_radius' => 20,
		);
	}
}
