<?php
/**
 * BrandForegroundColorOption.php.
 *
 * @package RewardsWP
 */

namespace Awesomemotive\Rewardswp\Settings\Options\RewardsWidget;

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

use Awesomemotive\Rewardswp\Abstracts\AbstractOption;
use Awesomemotive\Rewardswp\Interfaces\OptionInterface;

/**
 * Class BrandForegroundColorOption.
 */
class BrandForegroundColorOption extends AbstractOption implements OptionInterface {
	/**
	 * Get the setting key used in the option array.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_name(): string {
		return 'brand_foreground_color';
	}

	/**
	 * Get the setting group.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_group(): string {
		return 'rewards_widget';
	}

	/**
	 * Get the default value for the setting.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_default_value(): string {
		return '#ffffff'; // Default to white.
	}

	/**
	 * Get the label for the setting.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_label(): string {
		return esc_html__( 'Brand Foreground Color', 'rewardswp' );
	}

	/**
	 * Get the type of the setting (text, textarea, select, etc).
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	public function get_type(): string {
		return 'color';
	}

	/**
	 * Get the value with default fallback.
	 *
	 * @since 1.1.0
	 *
	 * @return mixed
	 */
	public function get_value() {
		$value = parent::get_value();

		return ! empty( $value ) ? $value : $this->get_default_value();
	}

	/**
	 * Sanitize the color value.
	 *
	 * @since 1.0.0
	 *
	 * @param mixed $value The value to be sanitized.
	 *
	 * @return string
	 */
	public function sanitize( $value ): string {
		if ( strpos( $value, '#' ) === 0 ) {
			return sanitize_hex_color( $value ) ?: $this->get_default_value();
		}
		return $this->get_default_value();
	}
}
