<?php
/**
 * Dynamic Tag: Site Current Date Time
 *
 * @package captain-widgets-kit
 * @since   1.1.0
 */

use Elementor\Core\DynamicTags\Tag;
use Elementor\Modules\DynamicTags\Module;
if ( ! defined( 'ABSPATH' ) ) {
	exit; }
/**
 * Class Captwiki_Tag_Site_Current_Date_Time
 * Outputs the current site date and time with format options.
 */
class Captwiki_Tag_Site_Current_Date_Time extends Tag {
	/**
	 * Get tag name.
	 *
	 * @return string
	 */
	public function get_name(): string {
		return 'captwiki-tag-current-date-time'; }
	/**
	 * Get tag title.
	 *
	 * @return string
	 */
	public function get_title(): string {
		return esc_html__( 'Current Date Time', 'captain-widgets-kit' ); }
	/**
	 * Get tag group.
	 *
	 * @return array
	 */
	public function get_group(): array {
		return array( 'captwiki-site' ); }
	/**
	 * Get tag categories.
	 *
	 * @return array
	 */
	public function get_categories(): array {
		return array( Module::TEXT_CATEGORY ); }
	/**
	 * Check whether settings are required.
	 *
	 * @return bool
	 */
	public function is_settings_required() {
		return true; }
	/**
	 * Register tag controls.
	 *
	 * @return void
	 */
	protected function register_controls(): void {
		$this->add_control(
			'captwiki_format',
			array(
				'label'   => esc_html__( 'Format', 'captain-widgets-kit' ),
				'type'    => \Elementor\Controls_Manager::SELECT,
				'default' => 'default',
				'options' => array(
					'default'      => esc_html__( 'Default', 'captain-widgets-kit' ),
					'F j, Y'       => date_i18n( 'F j, Y' ),
					'Y-m-d'        => date_i18n( 'Y-m-d' ),
					'm/d/Y'        => date_i18n( 'm/d/Y' ),
					'd-m-Y'        => date_i18n( 'd-m-Y' ),
					'g:i a'        => date_i18n( 'g:i a' ),
					'H:i'          => date_i18n( 'H:i' ),
					'F j, Y g:i a' => date_i18n( 'F j, Y g:i a' ),
					'Y-m-d H:i'    => date_i18n( 'Y-m-d H:i' ),
					'custom'       => esc_html__( 'Custom', 'captain-widgets-kit' ),
				),
			)
		);
		$this->add_control(
			'captwiki_custom_format',
			array(
				'label'     => esc_html__( 'Custom Format', 'captain-widgets-kit' ),
				'type'      => \Elementor\Controls_Manager::TEXT,
				'default'   => 'F j, Y g:i a',
				'condition' => array( 'captwiki_format' => 'custom' ),
			)
		);
	}
	/**
	 * Render tag output.
	 *
	 * @return void
	 */
	public function render(): void {
		$settings = $this->get_settings();
		if ( 'default' === $settings['captwiki_format'] ) {
			$format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
		} elseif ( 'custom' === $settings['captwiki_format'] ) {
			$format = $settings['captwiki_custom_format'];
		} else {
			$format = $settings['captwiki_format'];
		}
		echo wp_kses_post( date_i18n( $format ) );
	}
}
