<?php
/**
 * Elementor integration.
 * Defines custom Elementor widgets for WAWP shortcodes.
 *
 * @package automation-web-platform
 */

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

/**
 * Register WAWP shortcodes as Elementor widgets if Elementor is active.
 */
add_action(
	'plugins_loaded',
	function () {
		if ( did_action( 'elementor/loaded' ) ) {
			$hook = has_action( 'elementor/widgets/register' ) ? 'elementor/widgets/register' : 'elementor/widgets/widgets_registered';

			add_action(
				$hook,
				function ( $widgets_manager ) {
					$dir = WAWP_PLUGIN_DIR . 'integrations/elementor/';
					require_once $dir . 'class-wawp-login-widget.php';
					require_once $dir . 'class-wawp-signup-widget.php';
					require_once $dir . 'class-wawp-fast-login-widget.php';

					if ( method_exists( $widgets_manager, 'register' ) ) {
						$widgets_manager->register( new WAWP_Login_Widget() );
						$widgets_manager->register( new WAWP_Signup_Widget() );
						$widgets_manager->register( new WAWP_Fast_Login_Widget() );
					} else {
						$widgets_manager->register_widget_type( new WAWP_Login_Widget() );
						$widgets_manager->register_widget_type( new WAWP_Signup_Widget() );
						$widgets_manager->register_widget_type( new WAWP_Fast_Login_Widget() );
					}
				}
			);
		}
	}
);
