<?php
/**
 * Module: JetEngine Listing Calendar.
 */
namespace Jet_Engine_Divi_Views\Components\Jet_Engine\Modules;

if ( ! defined( 'ABSPATH' ) ) {
	die( 'Direct access forbidden.' );
}

use ET\Builder\Framework\DependencyManagement\Interfaces\DependencyInterface;
use ET\Builder\Packages\ModuleLibrary\ModuleRegistration;
use Jet_Engine_Divi_Views\Module_Render;
use ET\Builder\FrontEnd\Module\Style;
use Jet_Engine_Divi_Views\Utils;

class Listing_Calendar implements DependencyInterface {

	/**
	 * Module's style components.
	 *
	 * This function is equivalent of JS function ModuleStyles located in
	 * module/styles.tsx.
	 *
	 * @since ??
	 *
	 * @param array $args {
	 *     An array of arguments.
	 *
	 *      @type string $id                Module ID. In VB, the ID of module is UUIDV4. In FE, the ID is order index.
	 *      @type string $name              Module name.
	 *      @type string $attrs             Module attributes.
	 *      @type string $parentAttrs       Parent attrs.
	 *      @type string $orderClass        Selector class name.
	 *      @type string $parentOrderClass  Parent selector class name.
	 *      @type string $wrapperOrderClass Wrapper selector class name.
	 *      @type string $settings          Custom settings.
	 *      @type string $state             Attributes state.
	 *      @type string $mode              Style mode.
	 *      @type ModuleElements $elements  ModuleElements instance.
	 * }
	 */
	public static function module_styles( $args ) {

		$elements                    = $args['elements'];
		$settings                    = $args['settings'] ?? [];
		$default_printed_style_attrs = $args['defaultPrintedStyleAttrs'] ?? [];
		$attrs                       = $args['attrs'] ?? [];
		$order_class                 = $args['orderClass'] ?? '';

		$selectors = [
			'caption'            => "{$order_class} .jet-calendar-caption",
			'caption_wrap'       => "{$order_class} .jet-calendar-caption__wrap",
			'caption_name'       => "{$order_class} .jet-calendar-caption__name",
			'nav_link'           => "{$order_class} .jet-calendar-nav__link",
			'nav_link_next'      => "{$order_class} .jet-calendar-nav__link.nav-link-next",
			'nav_link_hover'     => "{$order_class} .jet-calendar-nav__link:hover",
			'week_day'           => "{$order_class} .jet-calendar-header__week-day",
			'week_day_first'     => "{$order_class} .jet-calendar-header__week-day:first-child",
			'week_day_last'      => "{$order_class} .jet-calendar-header__week-day:last-child",
			'day'                => "{$order_class} .jet-calendar-week__day",
			'day_content'        => "{$order_class} .jet-calendar-week__day-content",
			'day_wrap'           => "{$order_class} .jet-calendar-week__day-wrap",
			'day_event_gap'      => "{$order_class} .jet-calendar-week__day-event + .jet-calendar-week__day-event",
			'day_date'           => "{$order_class} .jet-calendar-week__day-date",
			'day_date_events'    => "{$order_class} .has-events .jet-calendar-week__day-date",
			'day_header'         => "{$order_class} .jet-calendar-week__day-header",
			'current_day'        => "{$order_class} .jet-calendar-week__day.current-day",
			'current_day_date'   => "{$order_class} .jet-calendar-week__day.current-day .jet-calendar-week__day-date",
			'disabled_day'       => "{$order_class} .jet-calendar-week__day.day-pad",
			'disabled_day_date'  => "{$order_class} .jet-calendar-week__day.day-pad .jet-calendar-week__day-date",
			'mobile_trigger'     => "{$order_class} .jet-calendar-week__day-mobile-trigger",
			'mobile_trigger_active' => "{$order_class} .calendar-event-active .jet-calendar-week__day-mobile-trigger",
			'mobile_wrap'        => "{$order_class} .jet-calendar-week__day-mobile-wrap",
			'mobile_event'       => "{$order_class} .jet-calendar-week__day-mobile-event",
		];

		$caption_typography = Utils\extract_typography_attrs( $attrs['module']['decoration']['captionTypography'] ?? null );
		$caption_typography_styles = Utils\build_typography_styles( $selectors['caption_name'], $caption_typography );
		$caption_spacing = Utils\extract_spasing_attrs( $attrs['module']['decoration']['captionSpacing'] ?? null );
		$caption_spacing_styles = Utils\build_spacing_styles( $selectors['caption'], $caption_spacing );
		$caption_border = Utils\extract_border_attrs( $attrs['module']['decoration']['captionBorder'] ?? null );
		$caption_border_styles = Utils\build_border_styles( $selectors['caption'], $caption_border );
		$nav_border = Utils\extract_border_attrs( $attrs['module']['decoration']['navBorder'] ?? null );
		$nav_border_styles = Utils\build_border_styles( $selectors['nav_link'], $nav_border );
		$nav_next_border = Utils\extract_border_attrs( $attrs['module']['decoration']['navBorderNext'] ?? null );
		$nav_next_border_styles = Utils\build_border_styles( $selectors['nav_link_next'], $nav_next_border );
		$week_typography = Utils\extract_typography_attrs( $attrs['module']['decoration']['weekTypography'] ?? null );
		$week_typography_styles = Utils\build_typography_styles( $selectors['week_day'], $week_typography );
		$week_padding = Utils\extract_spasing_attrs( $attrs['module']['decoration']['weekPadding'] ?? null );
		$week_padding_styles = Utils\build_spacing_styles( $selectors['week_day'], $week_padding );
		$day_padding = Utils\extract_spasing_attrs( $attrs['module']['decoration']['dayPadding'] ?? null );
		$day_padding_styles = Utils\build_spacing_styles( $selectors['day_content'], $day_padding );
		$day_label_typography = Utils\extract_typography_attrs( $attrs['module']['decoration']['dayLabelTypography'] ?? null );
		$day_label_typography_styles = Utils\build_typography_styles( $selectors['day_date'], $day_label_typography );
		$day_label_border = Utils\extract_border_attrs( $attrs['module']['decoration']['dayLabelBorder'] ?? null );
		$day_label_border_styles = Utils\build_border_styles( $selectors['day_date'], $day_label_border );
		$day_label_spacing = Utils\extract_spasing_attrs( $attrs['module']['decoration']['dayLabelSpacing'] ?? null );
		$day_label_spacing_styles = Utils\build_spacing_styles( $selectors['day_date'], $day_label_spacing );
		$mobile_trigger_border = Utils\extract_border_attrs( $attrs['module']['decoration']['mobileTriggerBorder'] ?? null );
		$mobile_trigger_border_styles = Utils\build_border_styles( $selectors['mobile_trigger'], $mobile_trigger_border );
		$mobile_trigger_spacing = Utils\extract_spasing_attrs( $attrs['module']['decoration']['mobileTriggerSpacing'] ?? null );
		$mobile_trigger_spacing_styles = Utils\build_spacing_styles( $selectors['mobile_trigger'], $mobile_trigger_spacing );
		$mobile_event_spacing = Utils\extract_spasing_attrs( $attrs['module']['decoration']['mobileEventSpacing'] ?? null );
		$mobile_event_spacing_styles = Utils\build_spacing_styles( $selectors['mobile_event'], $mobile_event_spacing );

		Style::add(
			[
				'id'            => $args['id'],
				'name'          => $args['name'],
				'orderIndex'    => $args['orderIndex'],
				'storeInstance' => $args['storeInstance'],
				'styles'        => [
					$elements->style(
						[
							'attrName'   => 'module',
							'styleProps' => [
								'defaultPrintedStyleAttrs' => $default_printed_style_attrs['module']['decoration'] ?? [],
								'disabledOn'               => [
									'disabledModuleVisibility' => $settings['disabledModuleVisibility'] ?? null,
								],
								'advancedStyles'           => array_merge(
									$caption_typography_styles,
									$caption_spacing_styles,
									$caption_border_styles,
									$nav_border_styles,
									$nav_next_border_styles,
									$week_typography_styles,
									$week_padding_styles,
									$day_padding_styles,
									$day_label_typography_styles,
									$day_label_border_styles,
									$day_label_spacing_styles,
									$mobile_trigger_border_styles,
									$mobile_trigger_spacing_styles,
									$mobile_event_spacing_styles,
									[
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'background-color', 'selector' => $selectors['caption'], 'attr' => $attrs['module']['decoration']['captionBgColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'color', 'selector' => $selectors['caption_name'], 'attr' => $attrs['module']['decoration']['captionTextColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'gap', 'selector' => $selectors['caption_wrap'], 'attr' => $attrs['module']['decoration']['captionGap'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'width', 'selector' => $selectors['nav_link'], 'attr' => $attrs['module']['decoration']['navWidth'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'height', 'selector' => $selectors['nav_link'], 'attr' => $attrs['module']['decoration']['navHeight'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'font-size', 'selector' => $selectors['nav_link'], 'attr' => $attrs['module']['decoration']['navSize'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'color', 'selector' => $selectors['nav_link'], 'attr' => $attrs['module']['decoration']['navColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'background-color', 'selector' => $selectors['nav_link'], 'attr' => $attrs['module']['decoration']['navBackgroundColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'color', 'selector' => $selectors['nav_link_hover'], 'attr' => $attrs['module']['decoration']['navColorHover'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'background-color', 'selector' => $selectors['nav_link_hover'], 'attr' => $attrs['module']['decoration']['navBackgroundColorHover'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'border-color', 'selector' => $selectors['nav_link_hover'], 'attr' => $attrs['module']['decoration']['navBorderColorHover'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'background-color', 'selector' => $selectors['week_day'], 'attr' => $attrs['module']['decoration']['weekBgColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'color', 'selector' => $selectors['week_day'], 'attr' => $attrs['module']['decoration']['weekTextColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'border-width', 'selector' => $selectors['week_day'], 'attr' => $attrs['module']['decoration']['weekBorderWidth'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'border-color', 'selector' => $selectors['week_day'], 'attr' => $attrs['module']['decoration']['weekBorderColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'border-left-color', 'selector' => $selectors['week_day_first'], 'attr' => $attrs['module']['decoration']['weekBorderColorFirst'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'border-right-color', 'selector' => $selectors['week_day_last'], 'attr' => $attrs['module']['decoration']['weekBorderColorLast'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'background-color', 'selector' => $selectors['day'], 'attr' => $attrs['module']['decoration']['dayBgColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'min-height', 'selector' => $selectors['day_content'], 'attr' => $attrs['module']['decoration']['dayMinHeight'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'min-height', 'selector' => $selectors['day_wrap'], 'attr' => $attrs['module']['decoration']['dayMinHeight'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'margin-top', 'selector' => $selectors['day_event_gap'], 'attr' => $attrs['module']['decoration']['dayEventsGap'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'border-width', 'selector' => $selectors['day'], 'attr' => $attrs['module']['decoration']['dayBorderWidth'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'border-color', 'selector' => $selectors['day'], 'attr' => $attrs['module']['decoration']['dayBorderColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'color', 'selector' => $selectors['day_date'], 'attr' => $attrs['module']['decoration']['dayLabelColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'background-color', 'selector' => $selectors['day_date'], 'attr' => $attrs['module']['decoration']['dayLabelBgColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'color', 'selector' => $selectors['day_date_events'], 'attr' => $attrs['module']['decoration']['dayLabelColorHasEvents'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'background-color', 'selector' => $selectors['day_date_events'], 'attr' => $attrs['module']['decoration']['dayLabelBgColorHasEvents'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'justify-content', 'selector' => $selectors['day_header'], 'attr' => $attrs['module']['decoration']['dayLabelAlignment'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'justify-content', 'selector' => $selectors['day_date'], 'attr' => $attrs['module']['decoration']['dayLabelTextAlignment'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'width', 'selector' => $selectors['day_date'], 'attr' => $attrs['module']['decoration']['dayLabelWidth'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'height', 'selector' => $selectors['day_date'], 'attr' => $attrs['module']['decoration']['dayLabelHeight'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'background-color', 'selector' => $selectors['current_day'], 'attr' => $attrs['module']['decoration']['currentDayBgColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'color', 'selector' => $selectors['current_day_date'], 'attr' => $attrs['module']['decoration']['currentDayLabelColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'background-color', 'selector' => $selectors['current_day_date'], 'attr' => $attrs['module']['decoration']['currentDayLabelBgColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'border-color', 'selector' => $selectors['current_day_date'], 'attr' => $attrs['module']['decoration']['currentDayLabelBorderColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'opacity', 'selector' => $selectors['disabled_day'], 'attr' => $attrs['module']['decoration']['dayOpacity'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'background-color', 'selector' => $selectors['disabled_day'], 'attr' => $attrs['module']['decoration']['dayBgColorDisabled'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'border-color', 'selector' => $selectors['disabled_day'], 'attr' => $attrs['module']['decoration']['dayBorderColorDisabled'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'color', 'selector' => $selectors['disabled_day_date'], 'attr' => $attrs['module']['decoration']['dayLabelColorDisabled'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'background-color', 'selector' => $selectors['disabled_day_date'], 'attr' => $attrs['module']['decoration']['dayLabelBgColorDisabled'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'border-color', 'selector' => $selectors['disabled_day_date'], 'attr' => $attrs['module']['decoration']['dayLabelBorderColorDisabled'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'background-color', 'selector' => $selectors['mobile_trigger'], 'attr' => $attrs['module']['decoration']['mobileTriggerColor'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'background-color', 'selector' => $selectors['mobile_trigger_active'], 'attr' => $attrs['module']['decoration']['mobileTriggerColorActive'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'width', 'selector' => $selectors['mobile_trigger'], 'attr' => $attrs['module']['decoration']['mobileTriggerWidth'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'height', 'selector' => $selectors['mobile_trigger'], 'attr' => $attrs['module']['decoration']['mobileTriggerHeight'] ?? [] ] ],
										[ 'componentName' => 'divi/common', 'props' => [ 'property' => 'justify-content', 'selector' => $selectors['mobile_wrap'], 'attr' => $attrs['module']['decoration']['mobileTriggerAlignment'] ?? [] ] ],
									]
								),
							],
						]
					),
				],
			]
		);
	}

	/**
	 * Set script data of used module options.
	 *
	 * @since ??
	 *
	 * @param array $args {
	 *   Array of arguments.
	 *
	 *   @type string $id       Module id.
	 *   @type string $selector Module selector.
	 *   @type array  $attrs    Module attributes.
	 * }
	 */
	public static function module_script_data( $args ) {
	}

	/**
	 * Module classnames function for Dynamic module.
	 *
	 * This function is equivalent of JS function moduleClassnames located in
	 * src/components/dynamic-module/module-classnames.ts.
	 *
	 * @since ??
	 *
	 * @param array $args {
	 *     An array of arguments.
	 *
	 *     @type object $classnamesInstance Instance of ET\Builder\Packages\Module\Layout\Components\Classnames.
	 *     @type array  $attrs              Block attributes data that being rendered.
	 * }
	 */
	public static function module_classnames( $args ) {
	}

	/**
	 * Dynamic module render callback which outputs server side rendered HTML on the Front-End.
	 *
	 * @since ??
	 *
	 * @param array          $attrs    Block attributes that were saved by VB.
	 * @param string         $content  Block content.
	 * @param \WP_Block      $block    Parsed block object that being rendered.
	 * @param ModuleElements $elements ModuleElements instance.
	 *
	 * @return string HTML rendered of module.
	 */
		public static function render_callback( $attrs, $content, $block, $elements ) {

			$prepared_attrs = [];

			foreach ( $attrs as $key => $value ) {
				if ( isset( $value['innerContent']['desktop']['value'] ) ) {
					$prepared_attrs[ $key ] = $value['innerContent']['desktop']['value'];
				}
			}

			$normalize_toggle = function ( $value ) {
				if ( true === $value || 1 === $value || '1' === $value || 'true' === $value || 'yes' === $value || 'on' === $value ) {
					return true;
				}

				if ( false === $value || 0 === $value || '0' === $value || '' === $value || null === $value || 'false' === $value || 'no' === $value || 'off' === $value ) {
					return false;
				}

				return (bool) $value;
			};

			$prepared_attrs['group_by']                 = $prepared_attrs['group_by'] ?? 'post_date';
			$prepared_attrs['group_by_key']             = $prepared_attrs['group_by_key'] ?? '';
			$prepared_attrs['allow_multiday']           = isset( $prepared_attrs['allow_multiday'] ) ? $normalize_toggle( $prepared_attrs['allow_multiday'] ) : false;
			$prepared_attrs['end_date_key']             = $prepared_attrs['end_date_key'] ?? '';
			$prepared_attrs['use_custom_post_types']    = isset( $prepared_attrs['use_custom_post_types'] ) ? $normalize_toggle( $prepared_attrs['use_custom_post_types'] ) : false;
			$prepared_attrs['custom_post_types']        = $prepared_attrs['custom_post_types'] ?? [];
			$prepared_attrs['week_days_format']         = $prepared_attrs['week_days_format'] ?? 'short';
			$prepared_attrs['custom_start_from']        = isset( $prepared_attrs['custom_start_from'] ) ? $normalize_toggle( $prepared_attrs['custom_start_from'] ) : false;
			$prepared_attrs['start_from_month']         = $prepared_attrs['start_from_month'] ?? '';
			$prepared_attrs['start_from_year']          = $prepared_attrs['start_from_year'] ?? date( 'Y' );
			$prepared_attrs['show_posts_nearby_months'] = isset( $prepared_attrs['show_posts_nearby_months'] ) ? $normalize_toggle( $prepared_attrs['show_posts_nearby_months'] ) : true;
			$prepared_attrs['hide_past_events']         = isset( $prepared_attrs['hide_past_events'] ) ? $normalize_toggle( $prepared_attrs['hide_past_events'] ) : false;
			$prepared_attrs['allow_date_select']        = isset( $prepared_attrs['allow_date_select'] ) ? $normalize_toggle( $prepared_attrs['allow_date_select'] ) : false;
			$prepared_attrs['start_year_select']        = $prepared_attrs['start_year_select'] ?? '1970';
			$prepared_attrs['end_year_select']          = $prepared_attrs['end_year_select'] ?? '2038';
			$prepared_attrs['caption_layout']           = $prepared_attrs['caption_layout'] ?? 'layout-1';
			$prepared_attrs['custom_query']             = isset( $prepared_attrs['custom_query'] ) ? $normalize_toggle( $prepared_attrs['custom_query'] ) : false;
			$prepared_attrs['custom_query_id']          = $prepared_attrs['custom_query_id'] ?? '';
			$prepared_attrs['posts_query']              = $prepared_attrs['posts_query'] ?? [];
			$prepared_attrs['meta_query_relation']      = $prepared_attrs['meta_query_relation'] ?? 'AND';
			$prepared_attrs['tax_query_relation']       = $prepared_attrs['tax_query_relation'] ?? 'AND';
			$prepared_attrs['hide_widget_if']           = $prepared_attrs['hide_widget_if'] ?? '';
			$prepared_attrs['cache_enabled']            = isset( $prepared_attrs['cache_enabled'] ) ? $normalize_toggle( $prepared_attrs['cache_enabled'] ) : false;
			$prepared_attrs['max_cache']                = $prepared_attrs['max_cache'] ?? '12';
			$prepared_attrs['cache_timeout']            = $prepared_attrs['cache_timeout'] ?? '60';

			if ( empty( $prepared_attrs['lisitng_id'] ) ) {
				return 'Please select a base listing item';
		}

		$render = self::get_jet_engine_render_instance( $prepared_attrs );

		$divi_module_render = new Module_Render();

		return $divi_module_render->render_content(
			$render,
			$attrs,
			$block,
			$elements,
			self::class
		);
	}

	/**
	 * Get JetEngine render class instance
	 */
	public static function get_jet_engine_render_instance( $attributes ) {
		$render = jet_engine()->listings->get_render_instance( self::get_jet_engine_render_name(), $attributes );

		if ( $render ) {
			return $render;
		}

		$calendar_module = jet_engine()->modules->get_module( 'calendar' );

		if ( $calendar_module && method_exists( $calendar_module, 'register_render_class' ) ) {
			$calendar_module->register_render_class( jet_engine()->listings );
			$render = jet_engine()->listings->get_render_instance( self::get_jet_engine_render_name(), $attributes );
		}

		return $render;
	}

	/**
	 * Return name of JetEngine renderer for current module
	 */
	public static function get_jet_engine_render_name() {
		return 'listing-calendar';
	}

	/**
	 * Loads `DynamicField` and registers Front-End render callback and REST API Endpoints.
	 *
	 * @since ??
	 *
	 * @return void
	 */
	public function load() {

		$module_json_folder_path = JET_ENGINE_DIVI_VIEWS_MODULES_JSON_PATH . 'listing-calendar/';

		add_action(
			'init',
			function() use ( $module_json_folder_path ) {
				if ( ! jet_engine()->modules->is_module_active( 'calendar' ) ) {
					return;
				}

				ModuleRegistration::register_module(
					$module_json_folder_path,
					[
						'render_callback' => [ Listing_Calendar::class, 'render_callback' ],
					]
				);
			}
		);
	}
}
