<?php
/**
 * Dokan Kits
 *
 * @package           Dokan_Kits
 * @author            WPIntegrity
 * @copyright         2025 WPIntegrity
 * @license           GPL-2.0-or-later
 *
 * @wordpress-plugin
 * Plugin Name:     Dokan Kits
 * Plugin URI:      https://wordpress.org/plugins/dokan-kits
 * Description:     The Helper Toolkits plugin for Dokan is a feature-packed add-on designed to streamline and enhance the functionality of your Dokan-powered multi-vendor marketplace.
 * Version:         3.1.5
 * Author:          WPIntegrity
 * Author URI:      https://wpintegrity.com/
 * Text Domain:     dokan-kits
 *
 *
 * Requires at least: 6.4.2
 * Tested up to: 7.0
 * Requires PHP: 7.4
 * WC requires at least: 7.9
 * WC tested up to: 9.8.3
 * Dokan requires at least: 3.9.7
 * Dokan tested up to: 4.0.1
 *
 * License: GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 */

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

// Define plugin constants.
define( 'DOKAN_KITS_VERSION', '3.1.5' );
define( 'DOKAN_KITS_FILE', __FILE__ );
define( 'DOKAN_KITS_BASENAME', plugin_basename( __FILE__ ) );
define( 'DOKAN_KITS_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'DOKAN_KITS_PLUGIN_URL', plugins_url( '', __FILE__ ) );
define( 'DOKAN_KITS_BUILD_URL', DOKAN_KITS_PLUGIN_URL . '/build' );
define( 'DOKAN_KITS_TEMPLATE_PATH', DOKAN_KITS_PLUGIN_PATH . 'templates/' );

// Composer autoloader.
if ( ! file_exists( __DIR__ . '/vendor/autoload.php' ) ||
	! file_exists( __DIR__ . '/freemius/start.php' ) ||
	! file_exists( __DIR__ . '/class-dokan-kits.php' ) ) {
	return;
}

require_once __DIR__ . '/vendor/autoload.php';

if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) || ! is_plugin_active( 'dokan-lite/dokan.php' ) ) {
	add_action( 'admin_notices', array( DokanKits\Admin\Notices\Dependencies::class, 'missing_dependencies_notice' ) );
	return;
}

/**
 * Declare the $dokan_kits_container as global to access from inside functions.
 */
global $dokan_kits_container;

/**
 * Initialize the container.
 */
$dokan_kits_container = new DokanKits\Core\DI\Container();
$dokan_kits_container->addServiceProvider( new DokanKits\Core\DI\Providers\ServiceProvider() );

/**
 * Get the global container instance.
 *
 * @since 3.0.0
 *
 * @return DokanKits\Core\DI\Container The global container instance or null if not initialized.
 */
function dokan_kits_get_container(): DokanKits\Core\DI\Container {
	global $dokan_kits_container;

	return $dokan_kits_container;
}

/**
 * Initialize the main plugin
 *
 * @return Dokan_Kits
 */
function dokan_kits(): Dokan_Kits {
	return Dokan_Kits::instance();
}

if ( ! function_exists( 'dokan_kits_fs' ) ) {
	/**
	 * Initialize Freemius SDK integration.
	 *
	 * This function initializes the Freemius SDK for the plugin, setting up licensing,
	 * analytics, and other Freemius features. It uses dynamic initialization to configure
	 * the plugin of Dokan Kits.
	 *
	 * @since 1.0.0
	 *
	 * @return Freemius Freemius SDK instance for managing plugin licensing and features.
	 * @throws Freemius_Exception When Freemius initialization fails.
	 *
	 * @global Freemius $dokan_kits_fs Freemius SDK instance for the plugin.
	 */
	function dokan_kits_fs() {
		global $dokan_kits_fs;

		if ( ! isset( $dokan_kits_fs ) ) {

			// Allow Freemius to be used in multisite.
			if ( ! defined( 'WP_FS__PRODUCT_19532_MULTISITE' ) ) {
				define( 'WP_FS__PRODUCT_19532_MULTISITE', true );
			}

			// Include Freemius SDK.
			require_once __DIR__ . '/freemius/start.php';

			$dokan_kits_fs = fs_dynamic_init(
				array(
					'id'             => '19532',
					'slug'           => 'dokan-kits',
					'type'           => 'plugin',
					'public_key'     => 'pk_3c4040e07fd028fc71a8cc0ad2197',
					'is_premium'     => false,
					'has_addons'     => true,
					'has_paid_plans' => false,
					'menu'           => array(
						'slug'       => 'dokan-kits',
						'first-path' => 'admin.php?page=dokan-kits',
						'contact'    => false,
						'support'    => false,
					),
				)
			);
		}

		return $dokan_kits_fs;
	}

	// Init Freemius.
	dokan_kits_fs();

	// Signal that SDK was initiated.
	do_action( 'dokan_kits_fs_loaded' );
}

// Take off the plugin.
dokan_kits()->init();
