<?php

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

/**
 * Widgetkit Pro Class
 *
 * Register new elementor widget.
 *
 * @since 1.0.0
 */
class Widgetkit_Pro_Elements {

	public function __construct() {
		$this->add_actions();
	}

	private function add_actions() {
		require_once  WKP_PATH . '/inc/helper-functions.php';
		add_action( 'elementor/widgets/widgets_registered', [ $this, 'on_widgets_registered' ] );
	}

	public function on_widgets_registered() {
		$this->includes();
		$this->widgetkit_pro_register_widget();
	}

	private function includes() {
        $element_files = glob(WKP_PATH . '/widgets/elements/*.php');
        foreach ($element_files as $file) {
            require $file;
        }
	}

	private function widgetkit_pro_register_widget() {

		$wk_enable_status = is_plugin_active('widgetkit-for-elementor/widgetkit-for-elementor.php');

		$wkpro_default_keys = [
			'wkpro-post-tab',
			'wkpro-post-carousel',
			'wkpro-post-list',
			'wkpro-grid-slider',
			'wkpro-headline-slider',
			'wkpro-smart-toggle',
			'wkpro-event-list',
		];
		$widgetkit_woo_keys = [
	        'wke-woo-product',
	        'wke-woo-product-carousel',
	        'wke-woo-categories',
	        'wke-woo-recent-product',
		];
		
		$widgetkit_woo_single_keys = [
	        'wke-woo-single-product-title',
	        'wke-woo-single-product-price',
	        'wke-woo-single-product-short-description',
	        'wke-woo-single-product-categories',
	        'wke-woo-single-product-cart-button',
	        'wke-woo-single-product-thumbnail',
	        'wke-woo-single-product-additional-information',
	        'wke-woo-single-product-review',
	        'wke-woo-single-product-related-product',
	        'wke-woo-single-product-upsell-product',
	        'wke-woo-single-product-rating',
	        'wke-woo-single-product-cross-sell-product',
	        'wke-woo-single-product-sku',
	        'wke-woo-single-product-stock-status',
	    ];

	    $widgetkit_ld_keys = [
	        'wke-ld-course-list',
	        'wke-ld-course-tab',
	        'wke-ld-course-banner',
	        'wke-ld-course-certificate',
	        'wke-ld-course-enrollment',
	        'wke-ld-course-meta-info',
	        'wke-ld-course-progress',
	        'wke-ld-course-resource',
	        'wke-ld-course-tab-content',
	        'wke-ld-course-related-course',
	        'wke-ld-course-curriculum',
	        'wke-ld-course-instructor',
	        'wke-ld-course-payments-button',
	        'wke-ld-course-content',
	    ];

	    $widgetkit_lp_keys = [
	        'wke-lp-course-list',
	        'wke-lp-course-tab',
	        'wke-lp-course-category',
	    ];
	    
	    $widgetkit_sensei_keys = [
	        'wke-sensei-course-list',
	        'wke-sensei-course-tab',
	        'wke-sensei-course-category',
		];
	    $widgetkit_lifter_keys = [
	        'wke-lifter-course-list',
		];
	    $widgetkit_tutor_keys = [
	        'wke-tutor-course-list',
	        'wke-tutor-course-grid',
		];
		
		$widgetkit_pro_default_settings = array_fill_keys( $wkpro_default_keys, true );
		$widgetkit_pro_default_woo_settings = array_fill_keys( $widgetkit_woo_keys, true ); 
		$widgetkit_pro_default_woo_single_settings = array_fill_keys( $widgetkit_woo_single_keys, true ); 
		$widgetkit_pro_default_ld_settings = array_fill_keys( $widgetkit_ld_keys, true ); 
		$widgetkit_pro_default_lp_settings = array_fill_keys( $widgetkit_lp_keys, true ); 
		$widgetkit_pro_default_sensei_settings = array_fill_keys( $widgetkit_sensei_keys, true ); 
		$widgetkit_pro_default_lifter_settings = array_fill_keys( $widgetkit_lifter_keys, true ); 
		$widgetkit_pro_default_tutor_settings = array_fill_keys( $widgetkit_tutor_keys, true ); 

		$check_component_active = get_option( 'widgetkit_pro_save_settings', $widgetkit_pro_default_settings );

		$wkpro_get_keys = get_option( 'widgetkit_save_settings', $widgetkit_pro_default_settings );
		$wkpro_get_woo_keys = get_option( 'widgetkit_save_woo_settings', $widgetkit_pro_default_woo_settings );
		$wkpro_get_woo_single_keys = get_option( 'widgetkit_save_woo_single_settings', $widgetkit_pro_default_woo_single_settings );
		$wkpro_get_ld_keys = get_option( 'widgetkit_save_ld_settings', $widgetkit_pro_default_ld_settings );
		$wkpro_get_lp_keys = get_option( 'widgetkit_save_lp_settings', $widgetkit_pro_default_lp_settings );
		$wkpro_get_sensei_keys = get_option( 'widgetkit_save_sensei_settings', $widgetkit_pro_default_sensei_settings );
		$wkpro_get_lifter_keys = get_option( 'widgetkit_save_lifter_settings', $widgetkit_pro_default_lifter_settings );
		$wkpro_get_tutor_keys = get_option( 'widgetkit_save_tutor_settings', $widgetkit_pro_default_tutor_settings );
		
		if($wkpro_get_keys && $wk_enable_status):
			if(widgetkit_pro_array_get($wkpro_get_keys, 'wkpro-post-tab')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Post_Tab() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_keys, 'wkpro-post-carousel')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Post_Carousel() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_keys, 'wkpro-post-list')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Smart_List() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_keys, 'wkpro-grid-slider')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Grid_Slider() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_keys, 'wkpro-headline-slider')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Headline_Slider() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_keys, 'wkpro-smart-toggle')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Smart_Toggle() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_keys, 'wkpro-event-list')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Event_List());
			endif;
		endif;
		/**
		 * WooCommerce
		 */
		if($wkpro_get_woo_keys && $wk_enable_status):
			if(widgetkit_pro_array_get($wkpro_get_woo_keys, 'wke-woo-product')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Products() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_woo_keys, 'wke-woo-product-carousel')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Product_Carousel() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_woo_keys, 'wke-woo-categories')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Categories() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_woo_keys, 'wke-woo-recent-product')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Recent_Product() );
			endif;
		endif;
		/**
		 * WooCommerce Single
		 */
		if($wkpro_get_woo_single_keys && $wk_enable_status):
			/**
			 * thumbnail
			 */
			if(widgetkit_pro_array_get($wkpro_get_woo_single_keys, 'wke-woo-single-product-thumbnail')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Single_Product_Thumbnail() );
			endif;
			/**
			 * title
			 */
			if(widgetkit_pro_array_get($wkpro_get_woo_single_keys, 'wke-woo-single-product-title')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Single_Product_Title() );
			endif;
			/**
			 * price
			 */
			if(widgetkit_pro_array_get($wkpro_get_woo_single_keys, 'wke-woo-single-product-price')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Single_Product_Price() );
			endif;
			/**
			 * short description
			 */
			if(widgetkit_pro_array_get($wkpro_get_woo_single_keys, 'wke-woo-single-product-short-description')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Single_Product_Short_Description() );
			endif;
			/**
			 * stock status
			 */
			if(widgetkit_pro_array_get($wkpro_get_woo_single_keys, 'wke-woo-single-product-stock-status')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Single_Product_Stock_Status() );
			endif;
			/**
			 * rating
			 */
			if(widgetkit_pro_array_get($wkpro_get_woo_single_keys, 'wke-woo-single-product-rating')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Single_Product_Rating() );
			endif;
			/**
			 * cart button
			 */
			if(widgetkit_pro_array_get($wkpro_get_woo_single_keys, 'wke-woo-single-product-cart-button')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Single_Cart_Button() );
			endif;
			/**
			 * sku
			 */
			if(widgetkit_pro_array_get($wkpro_get_woo_single_keys, 'wke-woo-single-product-sku')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Single_Product_Sku() );
			endif;
			/**
			 * category
			 */
			if(widgetkit_pro_array_get($wkpro_get_woo_single_keys, 'wke-woo-single-product-categories')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Single_Product_Categories() );
			endif;
			/**
			 * additional information
			 */
			if(widgetkit_pro_array_get($wkpro_get_woo_single_keys, 'wke-woo-single-product-additional-information')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Single_Product_Additional_Information() );
			endif;
			/**
			 * comment
			 */
			if(widgetkit_pro_array_get($wkpro_get_woo_single_keys, 'wke-woo-single-product-review')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Single_Product_Review() );
			endif;
			/**
			 * related product
			 */
			if(widgetkit_pro_array_get($wkpro_get_woo_single_keys, 'wke-woo-single-product-related-product')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Woo_Single_Product_Related_Product() );
			endif;
		endif;
		/**
		 * LearnDash
		 */
		if($wkpro_get_ld_keys && $wk_enable_status):
			if(widgetkit_pro_array_get($wkpro_get_ld_keys, 'wke-ld-course-list')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LearnDash_Course_List());
			endif;
			if(widgetkit_pro_array_get($wkpro_get_ld_keys, 'wke-ld-course-tab')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LearnDash_Course_Tab() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_ld_keys, 'wke-ld-course-banner')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LearnDash_Course_Banner() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_ld_keys, 'wke-ld-course-certificate')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LearnDash_Course_Certificate() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_ld_keys, 'wke-ld-course-enrollment')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LearnDash_Course_Enrollment() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_ld_keys, 'wke-ld-course-meta-info')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LearnDash_Course_Meta_Info() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_ld_keys, 'wke-ld-course-progress')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LearnDash_Course_Progress() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_ld_keys, 'wke-ld-course-resource')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LearnDash_Course_Resource() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_ld_keys, 'wke-ld-course-tab-content')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LearnDash_Course_Tab_Content() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_ld_keys, 'wke-ld-course-related-course')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LearnDash_Related_Course() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_ld_keys, 'wke-ld-course-curriculum')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LearnDash_Course_Curriculum() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_ld_keys, 'wke-ld-course-instructor')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LearnDash_Course_Instructor() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_ld_keys, 'wke-ld-course-payments-button')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LearnDash_Course_Payments_Button() );
			endif;
			if(widgetkit_pro_array_get($wkpro_get_ld_keys, 'wke-ld-course-content')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LearnDash_Course_Content() );
			endif;
		endif;
		/**
		 * LearnPress
		 */
		if($wkpro_get_lp_keys && $wk_enable_status):
			if(widgetkit_pro_array_get($wkpro_get_lp_keys, 'wke-lp-course-list')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LP_Course_List());
			endif;
			if(widgetkit_pro_array_get($wkpro_get_lp_keys, 'wke-lp-course-tab')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LP_Course_Tab());
			endif;
			if(widgetkit_pro_array_get($wkpro_get_lp_keys, 'wke-lp-course-category')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_LP_Course_Category());
			endif;
		endif;
		/**
		 * Sensei
		 */
		if($wkpro_get_sensei_keys && $wk_enable_status):
			if(widgetkit_pro_array_get($wkpro_get_sensei_keys, 'wke-sensei-course-list')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Sensei_Course_List());
			endif;
			if(widgetkit_pro_array_get($wkpro_get_sensei_keys, 'wke-sensei-course-tab')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Sensei_Course_Tab());
			endif;
			if(widgetkit_pro_array_get($wkpro_get_sensei_keys, 'wke-sensei-course-category')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Sensei_Course_Category());
			endif;
		endif;
		/**
		 * lifter
		 */
		if($wkpro_get_lifter_keys && $wk_enable_status):
			if(widgetkit_pro_array_get($wkpro_get_lifter_keys, 'wke-lifter-course-list')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Lifter_Course_List());
			endif;
		endif;
		/**
		 * tutor
		 */
		if($wkpro_get_tutor_keys && $wk_enable_status):
			if(widgetkit_pro_array_get($wkpro_get_tutor_keys, 'wke-tutor-course-list')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Tutor_Course_List());
			endif;
			if(widgetkit_pro_array_get($wkpro_get_tutor_keys, 'wke-tutor-course-grid')):
				\Elementor\Plugin::instance()->widgets_manager->register_widget_type( new Widgetkit_Pro_Tutor_Course_Grid());
			endif;
		endif;
	
	}
}

new Widgetkit_Pro_Elements();
