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

namespace Awesomemotive\Rewardswp\Settings\Options\RewardsWidget;

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

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

/**
 * Class LauncherDisplayOption.
 */
class LauncherDisplayOption 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 'launcher_display';
	}

	/**
	 * 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 'icon_with_text';
	}

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

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

	/**
	 * Get the available options for the option.
	 *
	 * @since 1.0.0
	 *
	 * @return array
	 */
	public function get_options(): array {
		return [
			[
				'value' => 'icon_with_text',
				'label' => esc_html__( 'Icon with text', 'rewardswp' ),
			],
			[
				'value' => 'text_only',
				'label' => esc_html__( 'Text only', 'rewardswp' ),
			],
			[
				'value' => 'icon_only',
				'label' => esc_html__( 'Icon only', 'rewardswp' ),
			],
		];
	}

	/**
	 * Sanitize field.
	 *
	 * @since 1.0.0
	 *
	 * @param mixed $value The value to be sanitized.
	 *
	 * @return string
	 */
	public function sanitize( $value ): string {
		$options = $this->get_options();

		$values = array_map(
			function ( $item ) {
				return $item['value'];
			},
			$options
		);

		return in_array( $value, $values, true )
			? sanitize_text_field( $value )
			: $this->get_default_value();
	}
}
