<?php
/**
 * Plugin Name:       Dude Commerce
 * Plugin URI:        https://wpdude.com/dude-commerce/
 * Description:       Sell physical products from WordPress using Stripe Checkout.
 * Version:           1.0.13
 * Requires at least: 6.5
 * Requires PHP:      8.1
 * Author:            wpdude
 * Author URI:        https://wpdude.com
 * License:           GPL-2.0-or-later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       dude-commerce
 * Domain Path:       /languages
 *
 * @package WPDudeProducts
  */

declare(strict_types=1);

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

define( 'WPDUDE_DC_VERSION', '1.0.13' );
define( 'WPDUDE_DC_FILE', __FILE__ );
define( 'WPDUDE_DC_PATH', plugin_dir_path( __FILE__ ) );
define( 'WPDUDE_DC_URL', plugin_dir_url( __FILE__ ) );
define( 'WPDUDE_DC_BASENAME', plugin_basename( __FILE__ ) );

$wpdude_dc_autoload = WPDUDE_DC_PATH . 'vendor/autoload.php';

if ( ! file_exists( $wpdude_dc_autoload ) ) {
	add_action(
		'admin_notices',
		static function (): void {
			if ( ! current_user_can( 'activate_plugins' ) ) {
				return;
			}
			echo '<div class="notice notice-error"><p>';
			echo esc_html__( 'Dude Commerce: Composer autoload is missing. Run composer dump-autoload in the plugin directory.', 'dude-commerce' );
			echo '</p></div>';
		}
	);
	return;
}

require_once $wpdude_dc_autoload;

/**
 * Freemius SDK accessor (wpdude_dc_fs — Paywall uses wpdude_dp_fs).
 *
 * @return \Freemius|null
 */
if ( ! function_exists( 'wpdude_dc_fs' ) ) {
	/**
	 * @return \Freemius|null
	 */
	function wpdude_dc_fs() {
		return \WPDude\Products\Licensing\Freemius::instance()->fs();
	}
}

/**
 * Initialize Freemius licensing early.
 */
\WPDude\Products\Licensing\Freemius::instance()->init();

do_action( 'wpdude_dc_fs_loaded' );

/**
 * Freemius uninstall cleanup (runs after Freemius reports the uninstall event).
 *
 * Do not use uninstall.php or register_uninstall_hook() — that blocks Freemius feedback.
 */
function wpdude_dc_fs_uninstall_cleanup(): void {
	\WPDude\Products\Uninstall\Cleanup::run();
}

$wpdude_dc_fs = wpdude_dc_fs();
if ( $wpdude_dc_fs && method_exists( $wpdude_dc_fs, 'add_action' ) ) {
	$wpdude_dc_fs->add_action( 'after_uninstall', 'wpdude_dc_fs_uninstall_cleanup' );
}

register_activation_hook( __FILE__, array( \WPDude\Products\Plugin::class, 'activate' ) );
register_deactivation_hook( __FILE__, array( \WPDude\Products\Plugin::class, 'deactivate' ) );

add_action(
	'plugins_loaded',
	static function (): void {
		\WPDude\Products\Plugin::instance()->boot();
	},
	5
);
