<?php

namespace SugarCalendarBookings\Support\Data;

/**
 * DateTime class.
 *
 * @since 1.0.0
 */
class DateTime {

	/**
	 * Get common date formats.
	 *
	 * @since 1.0.0
	 *
	 * @return array
	 */
	public static function get_date_formats() {

		/**
		 * Filters the default date formats.
		 *
		 * @since 1.0.0
		 *
		 * @param string[] $default_date_formats Array of default date formats.
		 */
		$date_formats = apply_filters( // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
			'sugar_calendar_bookings_date_formats',
			[
				'F j, Y',
				'Y-m-d',
				'm/d/Y',
				'd/m/Y',
				'jS F, Y',
			]
		);

		return array_unique( $date_formats );
	}

	/**
	 * Get available time formats.
	 *
	 * @since 1.0.0
	 *
	 * @return array
	 */
	public static function get_time_formats() {

		/**
		 * Filters the default time formats.
		 *
		 * @since 1.0.0
		 *
		 * @param string[] $default_time_formats Array of default time formats.
		 */
		$time_formats = apply_filters( // phpcs:ignore WPForms.PHP.ValidateHooks.InvalidHookName
			'sugar_calendar_bookings_time_formats',
			[
				esc_html__( 'g:i a', 'sugar-calendar-bookings-scheduling-appointments-lite' ),
				'g:i A',
				'H:i',
			]
		);

		return array_unique( $time_formats );
	}

	/**
	 * Get localized week days.
	 *
	 * @since 1.0.0
	 *
	 * @return array
	 */
	public static function get_week_days() {

		global $wp_locale;

		return [
			1 => $wp_locale->get_weekday( 1 ),
			2 => $wp_locale->get_weekday( 2 ),
			3 => $wp_locale->get_weekday( 3 ),
			4 => $wp_locale->get_weekday( 4 ),
			5 => $wp_locale->get_weekday( 5 ),
			6 => $wp_locale->get_weekday( 6 ),
			7 => $wp_locale->get_weekday( 0 ),
		];
	}

	/**
	 * Get localized month names.
	 *
	 * @since 1.0.0
	 *
	 * @return array
	 */
	public static function get_months() {

		global $wp_locale;

		$keys   = range( 1, 12 );
		$values = array_map( fn( $key ) => $wp_locale->get_month( $key ), $keys );

		return array_combine( $keys, $values );
	}
}
