<?php

/**
 * Elementor Addons Init
 * @package pubzi
 * @since 1.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit(); // exit if access directly
}

if ( ! class_exists( 'Pubzi_Elementor_Widget_Init' ) ) {

	class Pubzi_Elementor_Widget_Init {
	   /**
		* $instance
		* @since 1.0.0
		*/
		private static $instance;

	   /**
		* construct()
		* @since 1.0.0
		*/
		public function __construct() {
			add_action( 'elementor/elements/categories_registered', array( $this, '_widget_categories' ) );
			//elementor widget registered
			add_action( 'elementor/widgets/widgets_registered', array( $this, '_widget_registered' ) );
			// elementor editor css
			add_action( 'elementor/editor/after_enqueue_scripts', array( $this, 'load_assets_for_elementor' ) );
			// for icomoon icon
			add_action( 'init', [ $this, 'i18n' ] );
			// for icomoon icon
			add_action( 'plugins_loaded', [ $this, 'init' ] );
		
		}

		public function i18n() {
			load_plugin_textdomain( 'pubzi-core' );
		}

		/**
	     * getInstance()
	     * @since 1.0.0
	     */
		public static function getInstance() {
			if ( null == self::$instance ) {
				self::$instance = new self();
			}

			return self::$instance;
		}

		/**
		 * _widget_categories()
		 * @since 1.0.0
		 */
		public function _widget_categories( $elements_manager ) {
			$elements_manager->add_category(
				'pubzi_widgets',
				[
					'title' => esc_html__( 'Pubzi Widgets', 'pubzi-core' ),
					'icon'  => 'fas fa-plug',
				]
			);
		}

		/**
		 * _widget_registered()
		 * @since 1.0.0
		 */
		public function _widget_registered() {
			if ( ! class_exists( 'Elementor\Widget_Base' ) ) {
				return;
			}
			$elementor_widgets = array(
				
				'banner',
				'banner-2',				
				'about-with-games',
				'heading-text',
				'game-feature-box',
				'game-logo-slider',
				'team-grid',
				'theme-button',
				'testimonials',
				'blog-post',
				'brand-slider',
				'image-styles',
				'counter-text',
				'video-box',
				'game-grid',
				'match-list',
				'newsletter-cta',
				'banner-slider',
				'next-matches',
				'new-blog-post',
				'line-slide',
				'club-players',
				'champions',
				'feature-card',
				'card-slider',
				'match-socials-icons',
				'team-card-vs',
				'md-sidebar',
				'sd-tab',
				'theme-accordion',
				'price-list',
				'price-btn',
				'game-sidebar',
				'day-time',
				'game-card',
				'gallery-box',
				'contact-form',
				'banner-3',
				'big-matches',
				'download-cta',
				'banner-slider-2',
				'banner-4',
				'banner-5',
				'contact-form-images',

			);

			$elementor_widgets = apply_filters( 'pubzi_elementor_widget', $elementor_widgets );
			ksort( $elementor_widgets );
			if ( is_array( $elementor_widgets ) && ! empty( $elementor_widgets ) ) {
				foreach ( $elementor_widgets as $widget ) {
					if ( file_exists( PUBZI_CORE_ELEMENTOR . '/addons/elementor-' . $widget . '-widget.php' ) ) {
						require_once PUBZI_CORE_ELEMENTOR . '/addons/elementor-' . $widget . '-widget.php';
					}
				}
			}
		}	

		/**
		 * load custom assets for elementor
		 * @since 1.0.0
		*/
		public function load_assets_for_elementor() {
			wp_enqueue_style( 'pubzi-core-elementor-style', PUBZI_CORE_ADMIN_ASSETS . '/css/elementor-editor.css' );
		}

		/**
		 * load custom icons for elementor
		 * @since 1.0.0
		*/

		public function init() {
			add_action( 'elementor/widgets/register', [ $this, 'init_widgets' ] );
		}

		public function init_widgets() {
			require_once plugin_dir_path( __FILE__ ) . '../customicon/icon.php';
		}
	}

	if ( class_exists( 'Pubzi_Elementor_Widget_Init' ) ) {
		Pubzi_Elementor_Widget_Init::getInstance();
	}
}//end if
