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

namespace Awesomemotive\Rewardswp\Settings\Options\Points;

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

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

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

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

	/**
	 * Get the default value for the setting.
	 *
	 * @since 1.1.0
	 *
	 * @return string
	 */
	public function get_default_value(): string {
		return '+1 year'; // Points expire in 1 year by default.
	}

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

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

	/**
	 * Get the available options for the option.
	 *
	 * Must return an array with the value using the amount of time to add to the DateTime::modify method.
	 *
	 * @since 1.1.0
	 *
	 * @return array
	 */
	public function get_options(): array {
		return [
			'never'     => esc_html__( 'Never expire', 'rewardswp' ),
			'+30 days'  => esc_html__( '30 days', 'rewardswp' ),
			'+3 months' => esc_html__( '3 months', 'rewardswp' ),
			'+6 months' => esc_html__( '6 months', 'rewardswp' ),
			'+1 year'   => esc_html__( '1 year', 'rewardswp' ),
			'+2 years'  => esc_html__( '2 years', 'rewardswp' ),
		];
	}

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

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

	/**
	 * Get the description for the setting.
	 *
	 * @since 1.1.0
	 *
	 * @return string
	 */
	public function get_description(): string {
		return esc_html__( 'Select when points should expire after being earned. Points will automatically expire and become unavailable for redemption after this period.', 'rewardswp' );
	}
}
