<?php
/**
 * WeMeet Elementor Integrator
 * Integrates WeMeet widgets with Elementor.
 *
 * @package WeMeet
 */

namespace SOVLIX\WEMEET\Elementor;

use Elementor\Elements_Manager;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'Wemeet_Elementor_Integrator' ) ) {
	/**
	 * Class Wemeet_Elementor_Integrator
	 * Integrates WeMeet widgets with Elementor.
	 */
	class Wemeet_Elementor_Integrator {
		/**
		 * Class constructor.
		 *
		 * Hooks into the 'plugins_loaded' action to initiate the plugin.
		 */
		public function __construct() {
			add_action( 'elementor/elements/categories_registered', array( $this, 'add_elementor_widget_categories' ), 10 );
			add_action( 'elementor/widgets/register', array( $this, 'register_oembed_widget' ) );
		}

		/**
		 * Add custom category for WeMeet widgets.
		 *
		 * @param \Elementor\Elements_Manager $elements_manager Elementor elements manager.
		 * @return void
		 */
		public function add_elementor_widget_categories( $elements_manager ) {
			$elements_manager->add_category(
				'wemeet-category',
				array(
					'title' => __( 'WeMeet Widgets', 'wemeet' ),
					'icon'  => 'fa fa-plug',
				)
			);
		}

		/**
		 * Register oEmbed Widget.
		 *
		 * Include widget file and register widget class.
		 *
		 * @since 1.0.0
		 * @param \Elementor\Widgets_Manager $widgets_manager Elementor widgets manager.
		 * @return void
		 */
		public function register_oembed_widget( $widgets_manager ) {
			$widgets_manager->register( new Widgets\Wemeet_Webex_Elementor() );
		}
	}
}
