<?php

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

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

if ( ! class_exists( 'Geroz_Elementor_Widget_Init' ) ) {

	class Geroz_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( 'geroz-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(
				'geroz_widgets',
				[
					'title' => esc_html__( 'Geroz Widgets', 'geroz-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(
				
				'main-header',
				'footer-style-1',
				'footer-style-2',
				'footer-style4',
				'footer-style5',
				'footer-style6',
				'home1-hero',
				'home1-about',
				'home1-skills',
				'home1-services',
				'home1-projects',
				'home1-partner',
				'home1-counter',
				'home1-price',
				'home1-testimonials',
				'home1-contact',
				'home1-blog-post',
				'home2-hero',
				'home2-counter',
				'home2-text-slide',
				'home2-about',
				'home2-projects',
				'home2-awards',
				'home2-vision',
				'home2-services',
				'home2-clients-slide',
				'home2-video',
				'home2-price',
				'home2-blog-post',
				'home3-hero',
				'home3-progressbar',
				'home3-aboutme',
				'home3-project',
				'home3-provide',
				'home3-counter',
				'home3-awards',
				'home3-text-slide',
				'home3-testimonials',
				'home3-Price',
				'home3-blog-post',
				'home3-contact',
				'home3-hire',		
				'home4-hero',	
				'home4-aboutme',
				'home4-clients-slide',
				'home4-services',
				'home4-video',
				'home4-funfact',
				'home4-case',
				'home4-expert',
				'home4-team',
				'home4-testimonials',
				'home4-contact',
				'home4-blog-post',
				'home4-accordion',
				'home5-hero',
				'home5-aboutme',
				'home5-text-slide',
				'home5-project',
				'home5-content-write',
				'home5-services',
				'home5-clients-slide',
				'home5-testimonials',
				'home5-video',
				'home5-newsletter',
				'home6-hero',
				'home6-about',
				'home6-services',
				'home6-project',
				'home6-text-slide',
				'home6-skill',
				'home6-testimonials',			
				'home6-clients-slide',			
				'home6-contact',			
				'home6-blog-post',			
				'home6-faq',			
				'breadcrumb',			
				'services-filter',			
				'service-sidebar',			
				'projects',			
				'filter-blog-post',			
				'contact-form',	

			);

			$elementor_widgets = apply_filters( 'geroz_elementor_widget', $elementor_widgets );
			ksort( $elementor_widgets );
			if ( is_array( $elementor_widgets ) && ! empty( $elementor_widgets ) ) {
				foreach ( $elementor_widgets as $widget ) {
					if ( file_exists( GEROZ_CORE_ELEMENTOR . '/addons/elementor-' . $widget . '-widget.php' ) ) {
						require_once GEROZ_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( 'geroz-core-elementor-style', GEROZ_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( 'Geroz_Elementor_Widget_Init' ) ) {
		Geroz_Elementor_Widget_Init::getInstance();
	}
}//end if
