<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
if ( ! class_exists( 'Draly_Dropshipping_Starter_Pluggable' ) ) {
	class Draly_Dropshipping_Starter_Pluggable {
		/**
		 * Variable to hold the initialization state.
		 *
		 * @var  boolean
		 */
		protected static $initialized = false;

		/**
		 * Initialize pluggable functions.
		 *
		 * @return  void
		 */
		public static function initialize() {
			// Do nothing if pluggable functions already initialized.
			if ( self::$initialized ) {
				return;
			}
			add_action( 'after_setup_theme', array( __CLASS__, 'draly_dropshipping_starter_after_setup_theme' ) );
			add_action( 'widgets_init', array( __CLASS__, 'draly_dropshipping_starter_register_sidebar_widgets' ) );
			Draly_Dropshipping_Starter_Render::initialize();
			if ( is_admin() ) {
				Draly_Dropshipping_Starter_Pluggable_One_Click_Demo_Import::initialize();
				Draly_Dropshipping_Starter_Plugins_Load::initialize();
				Draly_Dropshipping_Starter_Meta_Box::initialize();
			}
			if ( class_exists( 'WooCommerce' ) ) {
				Draly_Dropshipping_Starter_Pluggable_WooCommerce::initialize();
			}
			if( did_action( 'elementor/loaded' )){
				Draly_Dropshipping_Starter_Pluggable_Elementor::initialize();
			}
			if ( class_exists( 'YITH_WCQV_Frontend' ) ) {
				Draly_Dropshipping_Starter_Pluggable_Yith_Woocommerce_Quick_View::initialize();
			}
			if ( class_exists( 'YITH_WCWL' ) ) {
				Draly_Dropshipping_Starter_Pluggable_Yith_Woocommerce_Wishlist::initialize();
			}
			if ( class_exists( 'WOO_PRODUCT_COMPARE_ACTIVE' ) ) {
				Draly_Dropshipping_Starter_Pluggable_Compe_Woo_Compare_Products::initialize();
			}
			if ( class_exists( 'ReduxFramework' ) ) {
				Draly_Dropshipping_Starter_Theme_Option::initialize();
			}
			self::$initialized = true;
		}

		/**
		 * Setup theme.
		 *
		 * @return  void
		 */
		public static function draly_dropshipping_starter_after_setup_theme() {
			load_theme_textdomain( 'draly-dropshipping-starter', DRALY_DROPSHIPPING_STARTER_THEME_DIR . '/languages' );

			add_theme_support( 'wp-block-styles' );
			add_theme_support( 'responsive-embeds' );
			add_theme_support( 'align-wide' );
			add_theme_support( 'automatic-feed-links' );
			add_theme_support( 'title-tag' );
			add_theme_support( 'post-thumbnails' );
			add_theme_support( 'custom-background' );
			add_theme_support( 'customize-selective-refresh-widgets' );

			// WooCommerce
			add_theme_support( 'woocommerce' );
			add_theme_support( 'wc-product-gallery-slider' );

			// HTML5 support
			add_theme_support( 'html5', array(
				'search-form',
				'comment-form',
				'comment-list',
				'gallery',
				'caption',
			) );

			// Post formats support
			add_theme_support( 'post-formats', array(
				'image',
				'video',
				'quote',
				'link',
				'gallery',
				'audio',
			) );

			register_nav_menus( array(
				'primary'       => esc_html__( 'Primary Menu', 'draly-dropshipping-starter' ),
				'vertical_menu' => esc_html__( 'Vertical Menu', 'draly-dropshipping-starter' ),
			) );
		}

		public static function draly_dropshipping_starter_register_sidebar_widgets() {
			$common_args = array(
				'before_widget' => '<div id="%1$s" class="widget %2$s">',
				'after_widget'  => '</div>',
				'before_title'  => '<h2 class="widgettitle">',
				'after_title'   => '</h2>',
			);
			$sidebars    = array(
				array(
					'name'        => esc_html__( 'Widget Blog', 'draly-dropshipping-starter' ),
					'id'          => 'widget-area',
					'description' => esc_html__( 'Add widgets here to appear in your blog sidebar.', 'draly-dropshipping-starter' ),
				),
				array(
					'name'           => esc_html__( 'Widget Shop', 'draly-dropshipping-starter' ),
					'id'             => 'widget-shop',
					'description'    => esc_html__( 'Add widgets here to appear in your shop sidebar.', 'draly-dropshipping-starter' ),
					'before_sidebar' => '<div class="filter-heading"><h2>' . esc_html__( 'Filter', 'draly-dropshipping-starter' ) . '</h2><div data-draly="draly-dropdown"><a href="#"><svg width="30" height="30" viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M7 7L23 23M7 23L23 7" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg></a></div></div>',
				),
				array(
					'name'        => esc_html__( 'Widget Product', 'draly-dropshipping-starter' ),
					'id'          => 'widget-product',
					'description' => esc_html__( 'Add widgets here to appear in your single product sidebar.', 'draly-dropshipping-starter' ),
				)
			);

			foreach ( $sidebars as $sidebar ) {
				register_sidebar( array_merge( $common_args, $sidebar ) );
			}
		}

	}
}
